From dd2e794a214350711db46c4e08d9b19188a7d63a Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Mon, 19 Oct 2009 17:48:08 +0200 Subject: Refactor pretty_print_commit arguments into a struct pretty_print_commit() has a bunch of rarely-used arguments, and introducing more of them requires yet another update of all the call sites. Refactor most of them into a struct to make future extensions easier. The ones that stay "plain" arguments were chosen on the grounds that all callers put real arguments there, whereas some callers have 0/NULL for all arguments that were factored into the struct. We declare the struct 'const' to ensure none of the callers are bitten by the changed (no longer call-by-value) semantics. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- builtin-log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 25e21ed415..207a36178b 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -1304,8 +1304,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) if (verbose) { struct strbuf buf = STRBUF_INIT; + struct pretty_print_context ctx = {0}; pretty_print_commit(CMIT_FMT_ONELINE, commit, - &buf, 0, NULL, NULL, 0, 0); + &buf, &ctx); printf("%c %s %s\n", sign, sha1_to_hex(commit->object.sha1), buf.buf); strbuf_release(&buf); -- cgit v1.2.3 From 1d46f2ea143534e46e6bfee3f34cd90b734bfe80 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 4 Nov 2009 02:19:40 -0500 Subject: format-patch: make "-p" suppress diffstat Once upon a time, format-patch would use its default stat plus patch format only when no diff format was given on the command line. This meant that "format-patch -p" would suppress the stat and show just the patch. Commit 68daa64 changed this to keep the stat format when we had an "implicit" patch format, like "-U5". As a side effect, this meant that an explicit patch format was now ignored (because cmd_format_patch didn't know the reason that the format was set way down in diff_opt_parse). This patch unbreaks what 68daa64 did (while still preserving what 68daa64 was trying to do), reinstating "-p" to suppress the default behavior. We do this by parsing "-p" ourselves in format-patch, and noting whether it was used explicitly. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-log.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 25e21ed415..7b91c91423 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -891,6 +891,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) struct patch_ids ids; char *add_signoff = NULL; struct strbuf buf = STRBUF_INIT; + int use_patch_format = 0; const struct option builtin_format_patch_options[] = { { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL, "use [PATCH n/m] even with a single patch", @@ -920,6 +921,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback }, OPT_BOOLEAN(0, "no-binary", &no_binary_diff, "don't output binary diffs"), + OPT_BOOLEAN('p', NULL, &use_patch_format, + "show patch format instead of default (patch + stat)"), OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream, "don't include a patch matching a commit upstream"), OPT_GROUP("Messaging"), @@ -1027,8 +1030,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (argc > 1) die ("unrecognized argument: %s", argv[1]); - if (!rev.diffopt.output_format - || rev.diffopt.output_format == DIFF_FORMAT_PATCH) + if (use_patch_format) + rev.diffopt.output_format |= DIFF_FORMAT_PATCH; + else if (!rev.diffopt.output_format || + rev.diffopt.output_format == DIFF_FORMAT_PATCH) rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH; if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff) -- cgit v1.2.3 From fef34270f209eb5d2cde01b8175b24d96d1cff21 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 9 Nov 2009 09:04:43 -0600 Subject: Show usage string for 'git cherry -h' Treat an "-h" option as a request for help, rather than an "Unknown commit -h" error. "cherry -h" could be asking to compare histories that leads to our HEAD and a commit that can be named as "-h". Strictly speaking, that may be a valid refname, but the user would have to say something like "tags/-h" to name such a pathological ref already, so it is not such a big deal. The "-h" option keeps its meaning even if preceded by other options or followed by other arguments. This keeps the command-line syntax closer to what parse_options would give and supports shell aliases like 'alias cherry="git cherry -v"' a little better. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin-log.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 207a36178b..524850735a 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -1237,6 +1237,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) argv++; } + if (argc > 1 && !strcmp(argv[1], "-h")) + usage(cherry_usage); + switch (argc) { case 4: limit = argv[3]; -- cgit v1.2.3 From 02bc5b03f54b51f8b45c81cce74284ced602e6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Sat, 7 Nov 2009 10:51:56 +0100 Subject: format-patch: Always generate a patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jeff King recently reinstated -p to suppress the default diffstat (as -p used to work before 68daa64, about 14 months ago). However, -p is also needed in combination with certain options (e.g. --stat or --numstat) in order to produce any patch at all. The documentation does not mention this. Since the purpose of format-patch is to produce a patch that can be emailed, it does not make sense that certain combination of options will suppress the generation of the patch itself. Therefore: * Update 'git format-patch' to always generate a patch. * Since the --name-only, --name-status, and --check suppresses the generation of the patch, disallow those options, and remove the description of them in the documentation. * Remove the reference to -p in the description of -U. * Remove the descriptions of the options that are synonyms for -p plus another option (--patch-with-raw and --patch-with-stat). * While at it, slightly tweak the description of -p itself to say that it generates "plain patches", so that you can think of -p as "plain patch" as an mnemonic aid. Signed-off-by: Björn Gustavsson Signed-off-by: Junio C Hamano --- builtin-log.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 7b91c91423..ce7ab810c8 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -921,10 +921,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback }, OPT_BOOLEAN(0, "no-binary", &no_binary_diff, "don't output binary diffs"), - OPT_BOOLEAN('p', NULL, &use_patch_format, - "show patch format instead of default (patch + stat)"), OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream, "don't include a patch matching a commit upstream"), + OPT_BOOLEAN('p', NULL, &use_patch_format, + "show patch format instead of default (patch + stat)"), OPT_GROUP("Messaging"), { OPTION_CALLBACK, 0, "add-header", NULL, "header", "add email header", PARSE_OPT_NONEG, @@ -1030,11 +1030,20 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (argc > 1) die ("unrecognized argument: %s", argv[1]); - if (use_patch_format) - rev.diffopt.output_format |= DIFF_FORMAT_PATCH; - else if (!rev.diffopt.output_format || - rev.diffopt.output_format == DIFF_FORMAT_PATCH) - rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH; + if (rev.diffopt.output_format & DIFF_FORMAT_NAME) + die("--name-only does not make sense"); + if (rev.diffopt.output_format & DIFF_FORMAT_NAME_STATUS) + die("--name-status does not make sense"); + if (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF) + die("--check does not make sense"); + + if (!use_patch_format && + (!rev.diffopt.output_format || + rev.diffopt.output_format == DIFF_FORMAT_PATCH)) + rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY; + + /* Always generate a patch */ + rev.diffopt.output_format |= DIFF_FORMAT_PATCH; if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff) DIFF_OPT_SET(&rev.diffopt, BINARY); -- cgit v1.2.3 From 2cfa8330e414bc73b01d45f232f8566afc56dd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Sat, 7 Nov 2009 10:58:55 +0100 Subject: format-patch: Add "--no-stat" as a synonym for "-p" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "-p" means "generate patch" in 'git log' and 'git diff', so it's quite surprising that it means "suppress diffstat" in 'git format-patch'. Keep the "-p" option for backward compatibility, but add "--no-stat" as a more intuitive synonym. For backward compatibility with scripts, we must allow combinations of --stat and --no-stat. Signed-off-by: Björn Gustavsson Signed-off-by: Junio C Hamano --- builtin-log.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index ce7ab810c8..06424f3ca8 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -923,8 +923,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) "don't output binary diffs"), OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream, "don't include a patch matching a commit upstream"), - OPT_BOOLEAN('p', NULL, &use_patch_format, - "show patch format instead of default (patch + stat)"), + { OPTION_BOOLEAN, 'p', "no-stat", &use_patch_format, NULL, + "show patch format instead of default (patch + stat)", + PARSE_OPT_NONEG | PARSE_OPT_NOARG }, OPT_GROUP("Messaging"), { OPTION_CALLBACK, 0, "add-header", NULL, "header", "add email header", PARSE_OPT_NONEG, -- cgit v1.2.3 From 99caeed05d3e89176d352104a2b70a77aa7e5d81 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 9 Nov 2009 09:05:01 -0600 Subject: Let 'git -h' show usage without a git dir There is no need for "git -h" to depend on being inside a repository. Reported by Gerfried Fuchs through http://bugs.debian.org/462557 Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin-log.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 524850735a..a0fa30c408 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -50,6 +50,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, if (default_date_mode) rev->date_mode = parse_date_format(default_date_mode); + /* + * Check for -h before setup_revisions(), or "git log -h" will + * fail when run without a git directory. + */ + if (argc == 2 && !strcmp(argv[1], "-h")) + usage(builtin_log_usage); argc = setup_revisions(argc, argv, rev, "HEAD"); if (rev->diffopt.pickaxe || rev->diffopt.filter) -- cgit v1.2.3 From 382da4023f155eabdda58ebd595a1e142408a56d Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 26 Nov 2009 21:11:59 +0200 Subject: format-patch: fix parsing of "--" on the command line When given a pathspec that does not match any path in the current work tree with an explicit "--": git format-patch -- the command still complains that does not exist in the current work tree and the user needs to explicitly specify "--" and errors out. This is because it incorrectly removes "--" from the command line arguments that is later passed to setup_revisions(). Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- builtin-log.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin-log.c') diff --git a/builtin-log.c b/builtin-log.c index 25e21ed415..cac98afddb 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -966,7 +966,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) */ argc = parse_options(argc, argv, prefix, builtin_format_patch_options, builtin_format_patch_usage, - PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN | + PARSE_OPT_KEEP_DASHDASH); if (do_signoff) { const char *committer; -- cgit v1.2.3