Re: [PATCH] Allow git-diff exit with codes similar to diff(1)

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] Allow git-diff exit with codes similar to diff(1)

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:59

"Alex Riesen" [off-list ref] writes:
Challenging... Now, if someone just told me where to look for
differences in diff-tree case...
As the resident git-diff expert I might hack on this myself as
the --quiet options are useful, and --exit-code comes almost
free when you properly do --quiet that implies --quick.
quoted
A slight tangent, but what Linus recalled he thought he did but
he didn't is related to the parts you touched in diff-tree
above.  Because of the interaction with diffcore, these changes
should not be used for the purpose of -exit-code, but catching
the tree level change in the above places and leaving early
would be the right thing to do for comparing the whole tree for
the purpose of simplifying the parents.  Tomorrow will be my git
day so I might whip up a patch to speed that up.
Can it eventually be wired to "-s" (DIFF_FORMAT_NO_OUTPUT)?
I do not think so.  When we run diff internally to pick the set
of paths (i.e. run diffcore and check contents of diff_queue,
just like you did for diff-index/diff-files), we internally use
NO_OUTPUT.  See merge-recursive.c for an example.
quoted
quoted
      diffcore_std(&revs->diffopt);
+     ret = revs->diffopt.diff_exit_code && diff_queued_diff.nr ? 1: 0;
      diff_flush(&revs->diffopt);
      return ret;
 }
This side looks correct, as you are counting queued_diff.nr after
letting diffcore_std() to filter the results.
And it will continue to work if the diffing is left early because of
no output needed. Err, will it?
To implement --quick correctly, you need to know when it is safe
to leave early.  Presence of -S (pickaxe) would most likely mean
you shouldn't leave early.

[PATCH] Allow git-diff exit with codes similar to diff(1)

From: Alex Riesen <hidden>
Date: 2016-06-15 22:42:59

This introduces a new command-line option: --exit-code. The diff
programs will return 1 for differences, return 0 for equality, and
something else for errors.

Signed-off-by: Alex Riesen <redacted>
---
Updated the patch:

- added more tests: path limiter and -S
- moved exit code into diff_options and used diffcore_std* for its evaluation

On 3/14/07, Junio C Hamano [off-list ref] wrote:
quoted
Challenging... Now, if someone just told me where to look for
differences in diff-tree case...
As the resident git-diff expert I might hack on this myself as
the --quiet options are useful, and --exit-code comes almost
free when you properly do --quiet that implies --quick.
Thanks! That would _most_ welcome :)
quoted
Can it eventually be wired to "-s" (DIFF_FORMAT_NO_OUTPUT)?
I do not think so.  When we run diff internally to pick the set
of paths (i.e. run diffcore and check contents of diff_queue,
just like you did for diff-index/diff-files), we internally use
NO_OUTPUT.  See merge-recursive.c for an example.
Right, is not that simple as it looks...
quoted
quoted
quoted
      diffcore_std(&revs->diffopt);
+     ret = revs->diffopt.diff_exit_code && diff_queued_diff.nr ? 1: 0;
      diff_flush(&revs->diffopt);
      return ret;
 }
This side looks correct, as you are counting queued_diff.nr after
letting diffcore_std() to filter the results.
And it will continue to work if the diffing is left early because of
no output needed. Err, will it?
To implement --quick correctly, you need to know when it is safe
to leave early.  Presence of -S (pickaxe) would most likely mean
you shouldn't leave early.
Thanks, that got me thinking. Moved all exit code evaluation
into diffcore_std, added a field for the code to diff_options,
and use it if called with --exit-code.

 Documentation/diff-options.txt |    5 +++
 builtin-diff-files.c           |    4 ++-
 builtin-diff-index.c           |    4 ++-
 builtin-diff-tree.c            |    4 +-
 builtin-diff.c                 |   19 +++++++-----
 diff-lib.c                     |    5 ++-
 diff.c                         |    6 ++++
 diff.h                         |    5 ++-
 t/t4017-diff-retval.sh         |   64 ++++++++++++++++++++++++++++++++++++++++
 9 files changed, 102 insertions(+), 14 deletions(-)
 create mode 100755 t/t4017-diff-retval.sh
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help