From: "Alex Riesen" <raa.lkml@gmail.com>
To: "Junio C Hamano" <junkio@cox.net>
Cc: "Johannes Schindelin" <Johannes.Schindelin@gmx.de>, git@vger.kernel.org
Subject: [PATCH] Allow git-diff exit with codes similar to diff(1)
Date: Wed, 14 Mar 2007 15:01:18 +0100 [thread overview]
Message-ID: <81b0412b0703140701h60982fddw3ed8fa71288cb220@mail.gmail.com> (raw)
In-Reply-To: <7v6494dwms.fsf@assigned-by-dhcp.cox.net>
[-- Attachment #1: Type: text/plain, Size: 2386 bytes --]
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 <raa.lkml@gmail.com>
---
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 <junkio@cox.net> wrote:
> > 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 :)
> > 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...
> >> > 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
[-- Attachment #2: 0001-Allow-git-diff-exit-with-codes-similar-to-diff-1.patch --]
[-- Type: application/xxxxx, Size: 9788 bytes --]
next prev parent reply other threads:[~2007-03-14 14:01 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-14 0:17 [PATCH] Allow git-diff exit with codes similar to diff(1) Alex Riesen
2007-03-14 1:03 ` Johannes Schindelin
2007-03-14 1:20 ` Linus Torvalds
2007-03-14 1:23 ` Junio C Hamano
2007-03-14 1:13 ` Linus Torvalds
2007-03-14 1:18 ` Johannes Schindelin
2007-03-14 1:34 ` Linus Torvalds
2007-03-14 1:38 ` Johannes Schindelin
2007-03-14 8:37 ` Alex Riesen
2007-03-14 12:05 ` Johannes Schindelin
2007-03-14 12:26 ` Alex Riesen
2007-03-14 12:31 ` Johannes Schindelin
2007-03-15 12:49 ` Simon 'corecode' Schubert
2007-03-15 13:56 ` Alex Riesen
2007-03-14 1:31 ` Junio C Hamano
2007-03-14 8:19 ` Alex Riesen
2007-03-14 8:58 ` Junio C Hamano
2007-03-14 9:06 ` Junio C Hamano
2007-03-14 9:07 ` Alex Riesen
2007-03-14 9:36 ` Junio C Hamano
2007-03-14 9:46 ` Alex Riesen
2007-03-14 4:56 ` Junio C Hamano
2007-03-14 8:28 ` Alex Riesen
2007-03-14 9:04 ` Junio C Hamano
2007-03-14 14:01 ` Alex Riesen [this message]
2007-03-14 16:14 ` Junio C Hamano
2007-03-14 16:33 ` Alex Riesen
2007-03-14 16:37 ` Junio C Hamano
2007-03-14 17:12 ` Alex Riesen
2007-03-14 17:20 ` Junio C Hamano
2007-03-14 17:06 ` Junio C Hamano
2007-03-14 17:15 ` Alex Riesen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81b0412b0703140701h60982fddw3ed8fa71288cb220@mail.gmail.com \
--to=raa.lkml@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).