From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org, Adrian Bunk <bunk@stusta.de>
Subject: Re: [PATCH 1/3] diff --stat: allow custom diffstat output width.
Date: Thu, 28 Sep 2006 15:07:16 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.64.0609281458420.3952@g5.osdl.org> (raw)
In-Reply-To: <7vac4ju1f1.fsf@assigned-by-dhcp.cox.net>
On Thu, 28 Sep 2006, Junio C Hamano wrote:
> Linus Torvalds <torvalds@osdl.org> writes:
>
> > So how about just extending the existing "--stat" thing, and just making
> > it do something like
> >
> > git diff --stat=72,30
> >
> > instead (perhaps along with a config option to set the defaults to
> > something else if we want to).
> >
> > What do you think?
>
> I am all for it.
Here. Something like this.
You should probably check the "width" and "name_width" values for sanity.
The old code didn't, so I didn't do it, but this actually does check that
the number was a real number (and didn't have crap after it). And it's
easy to check the values, since all cases go through the same point.
I could have made it a more obvious "stupid" parser, I just think it's
better to do it this way.
Linus
----
diff --git a/diff.c b/diff.c
index 98c29bf..8546dde 100644
--- a/diff.c
+++ b/diff.c
@@ -1825,15 +1825,33 @@ int diff_opt_parse(struct diff_options *
else if (!strcmp(arg, "--patch-with-raw")) {
options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
}
- else if (!strcmp(arg, "--stat"))
- options->output_format |= DIFF_FORMAT_DIFFSTAT;
- else if (!strncmp(arg, "--stat-width=", 13)) {
- options->stat_width = strtoul(arg + 13, NULL, 10);
- options->output_format |= DIFF_FORMAT_DIFFSTAT;
- }
- else if (!strncmp(arg, "--stat-name-width=", 18)) {
- options->stat_name_width = strtoul(arg + 18, NULL, 10);
+ else if (!strncmp(arg, "--stat", 6)) {
+ char *end;
+ int width = options->stat_width;
+ int name_width = options->stat_name_width;
+ arg += 6;
+ end = arg;
+
+ switch (*arg) {
+ case '-':
+ if (!strncmp(arg, "-width=", 7))
+ width = strtoul(arg + 7, &end, 10);
+ else if (!strncmp(arg, "-name-width=", 12))
+ name_width = strtoul(arg + 12, &end, 10);
+ break;
+
+ case '=':
+ width = strtoul(arg+1, &end, 10);
+ if (*end == ',')
+ name_width = strtoul(end+1, &end, 10);
+ }
+
+ /* Important! This checks all the error cases! */
+ if (*end)
+ return 0;
options->output_format |= DIFF_FORMAT_DIFFSTAT;
+ options->stat_name_width = name_width;
+ options->stat_width = width;
}
else if (!strcmp(arg, "--check"))
options->output_format |= DIFF_FORMAT_CHECKDIFF;
next prev parent reply other threads:[~2006-09-28 22:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-27 2:40 [PATCH 1/3] diff --stat: allow custom diffstat output width Junio C Hamano
2006-09-27 3:11 ` David Rientjes
2006-09-28 20:54 ` Linus Torvalds
2006-09-28 21:27 ` Junio C Hamano
2006-09-28 22:07 ` Linus Torvalds [this message]
2006-09-29 1:35 ` Junio C Hamano
2006-09-29 5:26 ` Junio C Hamano
2006-09-29 5:58 ` Linus Torvalds
2006-09-29 6:11 ` Junio C Hamano
2006-09-29 6:17 ` Linus Torvalds
2006-09-28 22:24 ` Adrian Bunk
2006-09-28 22:26 ` Johannes Schindelin
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=Pine.LNX.4.64.0609281458420.3952@g5.osdl.org \
--to=torvalds@osdl.org \
--cc=bunk@stusta.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).