From 6e359978e9792a83e8b45c0b76c3974518d2c738 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 11 Feb 2010 16:06:01 -0500 Subject: cherry-pick: rewrap advice message The current message overflows on an 80-character terminal. While we're at it, fix the spelling of 'committing'. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-revert.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index 8ac86f0943..83e5c0a755 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -213,13 +213,13 @@ static char *help_msg(const unsigned char *sha1) return msg; strcpy(helpbuf, " After resolving the conflicts,\n" - "mark the corrected paths with 'git add ' " - "or 'git rm ' and commit the result."); + "mark the corrected paths with 'git add ' or 'git rm '\n" + "and commit the result."); if (action == CHERRY_PICK) { sprintf(helpbuf + strlen(helpbuf), - "\nWhen commiting, use the option " - "'-c %s' to retain authorship and message.", + " When committing, use the option '-c %s'\n" + "to retain authorship and message.", find_unique_abbrev(sha1, DEFAULT_ABBREV)); } return helpbuf; -- cgit v1.2.3 From dd9314cc2a2f353bf9438db14cbbf02a1c219bda Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 11 Feb 2010 16:06:43 -0500 Subject: cherry-pick: refactor commit parsing code These lines are really just lookup_commit_reference re-implemented. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-revert.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index 83e5c0a755..012c64644d 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -68,15 +68,9 @@ static void parse_args(int argc, const char **argv) if (get_sha1(arg, sha1)) die ("Cannot find '%s'", arg); - commit = (struct commit *)parse_object(sha1); + commit = lookup_commit_reference(sha1); if (!commit) - die ("Could not find %s", sha1_to_hex(sha1)); - if (commit->object.type == OBJ_TAG) { - commit = (struct commit *) - deref_tag((struct object *)commit, arg, strlen(arg)); - } - if (commit->object.type != OBJ_COMMIT) - die ("'%s' does not point to a commit", arg); + exit(1); } static char *get_oneline(const char *message) -- cgit v1.2.3 From 08565bdb4b5d1da597ed8b90d1a23729f7c006d0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 11 Feb 2010 16:07:06 -0500 Subject: cherry-pick: format help message as strbuf This gets rid of the fixed-size buffer and an unchecked sprintf. That sprintf is actually OK as the only variable-sized thing put in it is an abbreviated sha1, which is bounded at 40 characters. However, the next patch will change that to something unbounded. Note that this function now returns an allocated buffer instead of a static one; however, it doesn't matter as the only caller exits immediately. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-revert.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index 012c64644d..77e4f4eed3 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -200,23 +200,23 @@ static void set_author_ident_env(const char *message) static char *help_msg(const unsigned char *sha1) { - static char helpbuf[1024]; + struct strbuf helpbuf = STRBUF_INIT; char *msg = getenv("GIT_CHERRY_PICK_HELP"); if (msg) return msg; - strcpy(helpbuf, " After resolving the conflicts,\n" + strbuf_addstr(&helpbuf, " After resolving the conflicts,\n" "mark the corrected paths with 'git add ' or 'git rm '\n" "and commit the result."); if (action == CHERRY_PICK) { - sprintf(helpbuf + strlen(helpbuf), + strbuf_addf(&helpbuf, " When committing, use the option '-c %s'\n" "to retain authorship and message.", find_unique_abbrev(sha1, DEFAULT_ABBREV)); } - return helpbuf; + return strbuf_detach(&helpbuf, NULL); } static struct tree *empty_tree(void) -- cgit v1.2.3 From 97915544f84132b210a336d5877fafd7cb104abe Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 11 Feb 2010 16:08:15 -0500 Subject: cherry-pick: show commit name instead of sha1 When we have a conflict, we advise the user to do: git commit -c $sha1 This works fine, but is unnecessarily confusing and annoying for the user to type, when: git commit -c $the_thing_you_called_cherry_pick_with works just as well. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-revert.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index 77e4f4eed3..ad612497a2 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -38,6 +38,7 @@ static const char * const cherry_pick_usage[] = { static int edit, no_replay, no_commit, mainline, signoff; static enum { REVERT, CHERRY_PICK } action; static struct commit *commit; +static const char *commit_name; static int allow_rerere_auto; static const char *me; @@ -49,7 +50,6 @@ static void parse_args(int argc, const char **argv) const char * const * usage_str = action == REVERT ? revert_usage : cherry_pick_usage; unsigned char sha1[20]; - const char *arg; int noop; struct option options[] = { OPT_BOOLEAN('n', "no-commit", &no_commit, "don't automatically commit"), @@ -64,10 +64,10 @@ static void parse_args(int argc, const char **argv) if (parse_options(argc, argv, NULL, options, usage_str, 0) != 1) usage_with_options(usage_str, options); - arg = argv[0]; - if (get_sha1(arg, sha1)) - die ("Cannot find '%s'", arg); + commit_name = argv[0]; + if (get_sha1(commit_name, sha1)) + die ("Cannot find '%s'", commit_name); commit = lookup_commit_reference(sha1); if (!commit) exit(1); @@ -198,7 +198,7 @@ static void set_author_ident_env(const char *message) sha1_to_hex(commit->object.sha1)); } -static char *help_msg(const unsigned char *sha1) +static char *help_msg(const char *name) { struct strbuf helpbuf = STRBUF_INIT; char *msg = getenv("GIT_CHERRY_PICK_HELP"); @@ -214,7 +214,7 @@ static char *help_msg(const unsigned char *sha1) strbuf_addf(&helpbuf, " When committing, use the option '-c %s'\n" "to retain authorship and message.", - find_unique_abbrev(sha1, DEFAULT_ABBREV)); + name); } return strbuf_detach(&helpbuf, NULL); } @@ -403,7 +403,7 @@ static int revert_or_cherry_pick(int argc, const char **argv) if (commit_lock_file(&msg_file) < 0) die ("Error wrapping up %s", defmsg); fprintf(stderr, "Automatic %s failed.%s\n", - me, help_msg(commit->object.sha1)); + me, help_msg(commit_name)); rerere(allow_rerere_auto); exit(1); } -- cgit v1.2.3 From 4d128884fbcce6c7effc729e1c52f06ce17037ee Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 11 Feb 2010 16:19:37 -0500 Subject: cherry-pick: prettify the advice message It's hard to see the "how to commit" part of this message, which users may want to cut and paste. On top of that, having it in paragraph form means that a really long commit name may cause ugly wrapping. Let's make it prettier, like: Automatic cherry-pick failed. After resolving the conflicts, mark the corrected paths with 'git add ' or 'git rm ' and commit the result with: git commit -c HEAD~23 Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- builtin-revert.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/builtin-revert.c b/builtin-revert.c index ad612497a2..eff52687a8 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -208,14 +208,16 @@ static char *help_msg(const char *name) strbuf_addstr(&helpbuf, " After resolving the conflicts,\n" "mark the corrected paths with 'git add ' or 'git rm '\n" - "and commit the result."); + "and commit the result"); if (action == CHERRY_PICK) { - strbuf_addf(&helpbuf, - " When committing, use the option '-c %s'\n" - "to retain authorship and message.", + strbuf_addf(&helpbuf, " with: \n" + "\n" + " git commit -c %s\n", name); } + else + strbuf_addch(&helpbuf, '.'); return strbuf_detach(&helpbuf, NULL); } -- cgit v1.2.3