{"thread":{"id":"27931","subject":"[PATCH 00/18] GSoC update: Sequencer for inclusion v3","startedAt":"2011-07-27T03:18:57Z","lastAt":"2011-08-01T17:37:22Z","messageCount":79,"participants":["Ramkumar Ramachandra","Jonathan Nieder","Jeff King","Junio C Hamano","Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":18},"messages":[{"id":"172098","messageId":"1311736755-24205-1-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":null,"subject":"[PATCH 00/18] GSoC update: Sequencer for inclusion v3","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:18:57Z","receivedAt":"2011-07-27T03:18:57Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nNothing new has been introduced; a couple of minor changes have been\nmade since last time (rewrite \"config: Introduce functions to write\nnon-standard file\" and remove \"Please, \" in hint: messages).  I will\nhencefourth refer to this series as \"sequencer-stable\" -- I've started\nbuilding post midterm work* on top of this.  If something critical\ncomes up, I can always fixup this series, rebase and quickly continue\nmy work.\n\nWhile Junio and others are not entirely happy with \"revert: Remove\nsequencer state when no commits are pending\", and there is still some\nconfusion about how '--abort' will work in the future, I think we have\ndiscussed these issues sufficiently.\n\n* I haven't made anything public yet, because it's still in its\n  infancy stages; I'll hopefully have something to show by the end of\n  the week.\n\nThanks for reading.\n\n-- Ram\n\nRamkumar Ramachandra (18):\n  advice: Introduce error_resolve_conflict\n  config: Introduce functions to write non-standard file\n  revert: Simplify and inline add_message_to_msg\n  revert: Don't check lone argument in get_encoding\n  revert: Rename no_replay to record_origin\n  revert: Propogate errors upwards from do_pick_commit\n  revert: Eliminate global \"commit\" variable\n  revert: Introduce struct to keep command-line options\n  revert: Separate cmdline parsing from functional code\n  revert: Don't create invalid replay_opts in parse_args\n  revert: Save data for continuing after conflict resolution\n  revert: Save command-line options for continuing operation\n  revert: Make pick_commits functionally act on a commit list\n  revert: Introduce --reset to remove sequencer state\n  reset: Make reset remove the sequencer state\n  revert: Remove sequencer state when no commits are pending\n  revert: Don't implictly stomp pending sequencer operation\n  revert: Introduce --continue to continue the operation\n\n Documentation/git-cherry-pick.txt |    6 +\n Documentation/git-revert.txt      |    6 +\n Documentation/sequencer.txt       |    9 +\n Makefile                          |    2 +\n advice.c                          |   31 ++-\n advice.h                          |    3 +-\n branch.c                          |    2 +\n builtin/revert.c                  |  743 +++++++++++++++++++++++++++++--------\n cache.h                           |    2 +\n config.c                          |   36 ++-\n sequencer.c                       |   19 +\n sequencer.h                       |   20 +\n t/7106-reset-sequence.sh          |   43 +++\n t/t3510-cherry-pick-sequence.sh   |  219 +++++++++++\n 14 files changed, 969 insertions(+), 172 deletions(-)\n create mode 100644 Documentation/sequencer.txt\n create mode 100644 sequencer.c\n create mode 100644 sequencer.h\n create mode 100755 t/7106-reset-sequence.sh\n create mode 100755 t/t3510-cherry-pick-sequence.sh\n\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172099","messageId":"1311736755-24205-2-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 01/18] advice: Introduce error_resolve_conflict","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:18:58Z","receivedAt":"2011-07-27T03:18:58Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Enable future callers to report a conflict and not die immediately by\nintroducing a new function called error_resolve_conflict.\nRe-implement die_resolve_conflict as a call to error_resolve_conflict\nfollowed by a call to die.  Consequently, the message printed by\ndie_resolve_conflict changes from\n\nfatal: 'commit' is not possible because you have unmerged files.\n       Please, fix them up in the work tree ...\n       ...\n\nto\n\nerror: 'commit' is not possible because you have unmerged files.\nhint: Please, fix them up in the work tree ...\nhint: ...\nfatal: Exiting because of an unresolved conflict.\n\nHints are printed using the same advise function introduced in\nv1.7.3-rc0~26^2~3 (Introduce advise() to print hints, 2010-08-11).\n\nInspired-by: Christian Couder <chistian.couder@gmail.com>\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n advice.c         |   31 ++++++++++++++++++++++++-------\n advice.h         |    3 ++-\n builtin/revert.c |    9 ---------\n 3 files changed, 26 insertions(+), 17 deletions(-)\n\ndiff --git a/advice.c b/advice.c\nindex 0be4b5f..e02e632 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -19,6 +19,15 @@ static struct {\n \t{ \"detachedhead\", &advice_detached_head },\n };\n \n+void advise(const char *advice, ...)\n+{\n+\tva_list params;\n+\n+\tva_start(params, advice);\n+\tvreportf(\"hint: \", advice, params);\n+\tva_end(params);\n+}\n+\n int git_default_advice_config(const char *var, const char *value)\n {\n \tconst char *k = skip_prefix(var, \"advice.\");\n@@ -34,16 +43,24 @@ int git_default_advice_config(const char *var, const char *value)\n \treturn 0;\n }\n \n-void NORETURN die_resolve_conflict(const char *me)\n+int error_resolve_conflict(const char *me)\n {\n-\tif (advice_resolve_conflict)\n+\terror(\"'%s' is not possible because you have unmerged files.\", me);\n+\tif (advice_resolve_conflict) {\n \t\t/*\n \t\t * Message used both when 'git commit' fails and when\n \t\t * other commands doing a merge do.\n \t\t */\n-\t\tdie(\"'%s' is not possible because you have unmerged files.\\n\"\n-\t\t    \"Please, fix them up in the work tree, and then use 'git add/rm <file>' as\\n\"\n-\t\t    \"appropriate to mark resolution and make a commit, or use 'git commit -a'.\", me);\n-\telse\n-\t\tdie(\"'%s' is not possible because you have unmerged files.\", me);\n+\t\tadvise(\"Fix them up in the work tree,\");\n+\t\tadvise(\"and then use 'git add/rm <file>' as\");\n+\t\tadvise(\"appropriate to mark resolution and make a commit,\");\n+\t\tadvise(\"or use 'git commit -a'.\");\n+\t}\n+\treturn -1;\n+}\n+\n+void NORETURN die_resolve_conflict(const char *me)\n+{\n+\terror_resolve_conflict(me);\n+\tdie(\"Exiting because of an unresolved conflict.\");\n }\ndiff --git a/advice.h b/advice.h\nindex 3244ebb..e5d0af7 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -11,7 +11,8 @@ extern int advice_implicit_identity;\n extern int advice_detached_head;\n \n int git_default_advice_config(const char *var, const char *value);\n-\n+void advise(const char *advice, ...);\n+int error_resolve_conflict(const char *me);\n extern void NORETURN die_resolve_conflict(const char *me);\n \n #endif /* ADVICE_H */\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 1f27c63..2df3f3b 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -214,15 +214,6 @@ static void write_cherry_pick_head(void)\n \tstrbuf_release(&buf);\n }\n \n-static void advise(const char *advice, ...)\n-{\n-\tva_list params;\n-\n-\tva_start(params, advice);\n-\tvreportf(\"hint: \", advice, params);\n-\tva_end(params);\n-}\n-\n static void print_advice(void)\n {\n \tchar *msg = getenv(\"GIT_CHERRY_PICK_HELP\");\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172100","messageId":"1311736755-24205-3-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 02/18] config: Introduce functions to write non-standard file","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:18:59Z","receivedAt":"2011-07-27T03:18:59Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Introduce two new functions corresponding to \"git_config_set\" and\n\"git_config_set_multivar\" to write a non-standard configuration file.\nExpose thse new functions in cache.h for other git programs to use.\n\nHelped-by: Jeff King <peff@peff.net>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n cache.h  |    2 ++\n config.c |   36 +++++++++++++++++++++++++++---------\n 2 files changed, 29 insertions(+), 9 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 9e12d55..33d3428 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1069,9 +1069,11 @@ extern int git_config_bool(const char *, const char *);\n extern int git_config_maybe_bool(const char *, const char *);\n extern int git_config_string(const char **, const char *, const char *);\n extern int git_config_pathname(const char **, const char *, const char *);\n+extern int git_config_set_in_file(const char *, const char *, const char *);\n extern int git_config_set(const char *, const char *);\n extern int git_config_parse_key(const char *, char **, int *);\n extern int git_config_set_multivar(const char *, const char *, const char *, int);\n+extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int);\n extern int git_config_rename_section(const char *, const char *);\n extern const char *git_etc_gitconfig(void);\n extern int check_repository_format_version(const char *var, const char *value, void *cb);\ndiff --git a/config.c b/config.c\nindex 6b61a84..a0578b2 100644\n--- a/config.c\n+++ b/config.c\n@@ -1092,6 +1092,12 @@ contline:\n \treturn offset;\n }\n \n+int git_config_set_in_file(const char *config_filename,\n+\t\t\tconst char *key, const char *value)\n+{\n+\treturn git_config_set_multivar_in_file(config_filename, key, value, NULL, 0);\n+}\n+\n int git_config_set(const char *key, const char *value)\n {\n \treturn git_config_set_multivar(key, value, NULL, 0);\n@@ -1189,19 +1195,14 @@ out_free_ret_1:\n  * - the config file is removed and the lock file rename()d to it.\n  *\n  */\n-int git_config_set_multivar(const char *key, const char *value,\n-\tconst char *value_regex, int multi_replace)\n+int git_config_set_multivar_in_file(const char *config_filename,\n+\t\t\t\tconst char *key, const char *value,\n+\t\t\t\tconst char *value_regex, int multi_replace)\n {\n \tint fd = -1, in_fd;\n \tint ret;\n-\tchar *config_filename;\n \tstruct lock_file *lock = NULL;\n \n-\tif (config_exclusive_filename)\n-\t\tconfig_filename = xstrdup(config_exclusive_filename);\n-\telse\n-\t\tconfig_filename = git_pathdup(\"config\");\n-\n \t/* parse-key returns negative; flip the sign to feed exit(3) */\n \tret = 0 - git_config_parse_key(key, &store.key, &store.baselen);\n \tif (ret)\n@@ -1378,7 +1379,6 @@ int git_config_set_multivar(const char *key, const char *value,\n out_free:\n \tif (lock)\n \t\trollback_lock_file(lock);\n-\tfree(config_filename);\n \treturn ret;\n \n write_err_out:\n@@ -1387,6 +1387,24 @@ write_err_out:\n \n }\n \n+int git_config_set_multivar(const char *key, const char *value,\n+\t\t\tconst char *value_regex, int multi_replace)\n+{\n+\tconst char *config_filename;\n+\tchar *filename_buf = NULL;\n+\tint ret;\n+\n+\tif (config_exclusive_filename)\n+\t\tconfig_filename = config_exclusive_filename;\n+\telse\n+\t\tconfig_filename = filename_buf = git_pathdup(\"config\");\n+\n+\tret = git_config_set_multivar_in_file(config_filename, key, value,\n+\t\t\t\t\tvalue_regex, multi_replace);\n+\tfree(filename_buf);\n+\treturn ret;\n+}\n+\n static int section_name_match (const char *buf, const char *name)\n {\n \tint i = 0, j = 0, dot = 0;\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172101","messageId":"1311736755-24205-4-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 03/18] revert: Simplify and inline add_message_to_msg","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:00Z","receivedAt":"2011-07-27T03:19:00Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"The add_message_to_msg function has some dead code, an unclear API,\nonly one callsite.  While it originally intended fill up an empty\ncommit message with the commit object name while picking, it really\ndoesn't do this -- a bug introduced in 9509af6 (Make git-revert &\ngit-cherry-pick a builtin, 2007-03-01).  Today, tests in\nt3505-cherry-pick-empty.sh indicate that not filling up an empty\ncommit message is the desired behavior.  Re-implement and inline the\nfunction accordingly.\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nMentored-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |   28 ++++++++++++++--------------\n 1 files changed, 14 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 2df3f3b..7dfe295 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -185,19 +185,6 @@ static char *get_encoding(const char *message)\n \treturn NULL;\n }\n \n-static void add_message_to_msg(struct strbuf *msgbuf, const char *message)\n-{\n-\tconst char *p = message;\n-\twhile (*p && (*p != '\\n' || p[1] != '\\n'))\n-\t\tp++;\n-\n-\tif (!*p)\n-\t\tstrbuf_addstr(msgbuf, sha1_to_hex(commit->object.sha1));\n-\n-\tp += 2;\n-\tstrbuf_addstr(msgbuf, p);\n-}\n-\n static void write_cherry_pick_head(void)\n {\n \tint fd;\n@@ -462,11 +449,24 @@ static int do_pick_commit(void)\n \t\t}\n \t\tstrbuf_addstr(&msgbuf, \".\\n\");\n \t} else {\n+\t\tconst char *p;\n+\n \t\tbase = parent;\n \t\tbase_label = msg.parent_label;\n \t\tnext = commit;\n \t\tnext_label = msg.label;\n-\t\tadd_message_to_msg(&msgbuf, msg.message);\n+\n+\t\t/*\n+\t\t * Append the commit log message to msgbuf; it starts\n+\t\t * after the tree, parent, author, committer\n+\t\t * information followed by \"\\n\\n\".\n+\t\t */\n+\t\tp = strstr(msg.message, \"\\n\\n\");\n+\t\tif (p) {\n+\t\t\tp += 2;\n+\t\t\tstrbuf_addstr(&msgbuf, p);\n+\t\t}\n+\n \t\tif (no_replay) {\n \t\t\tstrbuf_addstr(&msgbuf, \"(cherry picked from commit \");\n \t\t\tstrbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172102","messageId":"1311736755-24205-5-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 04/18] revert: Don't check lone argument in get_encoding","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:01Z","receivedAt":"2011-07-27T03:19:01Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"The get_encoding function has only one callsite, and its caller makes\nsure that a NULL argument isn't passed.  Remove a string marked for\ntranslation that will never be shown by not unnecessarily\ndouble-checking the argument.\n\nSuggested-by: Jonathan Nieder <jrnieder@gmail.com>\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |    3 ---\n 1 files changed, 0 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 7dfe295..30b39c0 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -167,9 +167,6 @@ static char *get_encoding(const char *message)\n {\n \tconst char *p = message, *eol;\n \n-\tif (!p)\n-\t\tdie (_(\"Could not read commit message of %s\"),\n-\t\t\t\tsha1_to_hex(commit->object.sha1));\n \twhile (*p && *p != '\\n') {\n \t\tfor (eol = p + 1; *eol && *eol != '\\n'; eol++)\n \t\t\t; /* do nothing */\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172104","messageId":"1311736755-24205-6-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 05/18] revert: Rename no_replay to record_origin","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:02Z","receivedAt":"2011-07-27T03:19:02Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"The \"-x\" command-line option is used to record the name of the\noriginal commits being picked in the commit message.  The variable\ncorresponding to this option is named \"no_replay\" for historical\nreasons; the name is especially confusing because the term \"replay\" is\nused to describe what cherry-pick does (for example, in the\ndocumentation of the \"--mainline\" option).  So, give the variable\ncorresponding to the \"-x\" command-line option a better name:\n\"record_origin\".\n\nMentored-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 30b39c0..794c050 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -35,7 +35,7 @@ static const char * const cherry_pick_usage[] = {\n \tNULL\n };\n \n-static int edit, no_replay, no_commit, mainline, signoff, allow_ff;\n+static int edit, record_origin, no_commit, mainline, signoff, allow_ff;\n static enum { REVERT, CHERRY_PICK } action;\n static struct commit *commit;\n static int commit_argc;\n@@ -91,7 +91,7 @@ static void parse_args(int argc, const char **argv)\n \n \tif (action == CHERRY_PICK) {\n \t\tstruct option cp_extra[] = {\n-\t\t\tOPT_BOOLEAN('x', NULL, &no_replay, \"append commit name\"),\n+\t\t\tOPT_BOOLEAN('x', NULL, &record_origin, \"append commit name\"),\n \t\t\tOPT_BOOLEAN(0, \"ff\", &allow_ff, \"allow fast-forward\"),\n \t\t\tOPT_END(),\n \t\t};\n@@ -464,7 +464,7 @@ static int do_pick_commit(void)\n \t\t\tstrbuf_addstr(&msgbuf, p);\n \t\t}\n \n-\t\tif (no_replay) {\n+\t\tif (record_origin) {\n \t\t\tstrbuf_addstr(&msgbuf, \"(cherry picked from commit \");\n \t\t\tstrbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));\n \t\t\tstrbuf_addstr(&msgbuf, \")\\n\");\n@@ -559,7 +559,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with --signoff\"));\n \t\tif (no_commit)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with --no-commit\"));\n-\t\tif (no_replay)\n+\t\tif (record_origin)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with -x\"));\n \t\tif (edit)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with --edit\"));\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172103","messageId":"1311736755-24205-7-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 06/18] revert: Propogate errors upwards from do_pick_commit","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:03Z","receivedAt":"2011-07-27T03:19:03Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Currently, revert_or_cherry_pick can fail in two ways.  If it\nencounters a conflict, it returns a positive number indicating the\nintended exit status for the git wrapper to pass on; for all other\nerrors, it calls die().  The latter behavior is inconsiderate towards\ncallers, as it denies them the opportunity to recover from errors and\ndo other things.\n\nAfter this patch, revert_or_cherry_pick will still return a positive\nreturn value to indicate an exit status for conflicts as before, while\nfor some other errors, it will print an error message and return -1\ninstead of die()-ing.  The cmd_revert and cmd_cherry_pick are adjusted\nto handle the fatal errors by die()-ing themselves.\n\nWhile the full benefits of this patch will only be seen once all the\n\"die\" calls are replaced with calls to \"error\", its immediate impact\nis to change some \"fatal:\" messages to say \"error:\" and to add a new\n\"fatal: cherry-pick failed\" message at the end when the operation\nfails.\n\nInspired-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Jonathan Nieder <jrnieder@gmail.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |   67 ++++++++++++++++++++++++++++-------------------------\n 1 files changed, 35 insertions(+), 32 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 794c050..ee9b4cd 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -241,25 +241,20 @@ static struct tree *empty_tree(void)\n \treturn tree;\n }\n \n-static NORETURN void die_dirty_index(const char *me)\n+static int error_dirty_index(const char *me)\n {\n-\tif (read_cache_unmerged()) {\n-\t\tdie_resolve_conflict(me);\n-\t} else {\n-\t\tif (advice_commit_before_merge) {\n-\t\t\tif (action == REVERT)\n-\t\t\t\tdie(_(\"Your local changes would be overwritten by revert.\\n\"\n-\t\t\t\t\t  \"Please, commit your changes or stash them to proceed.\"));\n-\t\t\telse\n-\t\t\t\tdie(_(\"Your local changes would be overwritten by cherry-pick.\\n\"\n-\t\t\t\t\t  \"Please, commit your changes or stash them to proceed.\"));\n-\t\t} else {\n-\t\t\tif (action == REVERT)\n-\t\t\t\tdie(_(\"Your local changes would be overwritten by revert.\\n\"));\n-\t\t\telse\n-\t\t\t\tdie(_(\"Your local changes would be overwritten by cherry-pick.\\n\"));\n-\t\t}\n-\t}\n+\tif (read_cache_unmerged())\n+\t\treturn error_resolve_conflict(me);\n+\n+\t/* Different translation strings for cherry-pick and revert */\n+\tif (action == CHERRY_PICK)\n+\t\terror(_(\"Your local changes would be overwritten by cherry-pick.\"));\n+\telse\n+\t\terror(_(\"Your local changes would be overwritten by revert.\"));\n+\n+\tif (advice_commit_before_merge)\n+\t\tadvise(_(\"Commit your changes or stash them to proceed.\"));\n+\treturn -1;\n }\n \n static int fast_forward_to(const unsigned char *to, const unsigned char *from)\n@@ -376,9 +371,9 @@ static int do_pick_commit(void)\n \t\t\tdie (_(\"Your index file is unmerged.\"));\n \t} else {\n \t\tif (get_sha1(\"HEAD\", head))\n-\t\t\tdie (_(\"You do not have a valid HEAD\"));\n+\t\t\treturn error(_(\"You do not have a valid HEAD\"));\n \t\tif (index_differs_from(\"HEAD\", 0))\n-\t\t\tdie_dirty_index(me);\n+\t\t\treturn error_dirty_index(me);\n \t}\n \tdiscard_cache();\n \n@@ -391,20 +386,20 @@ static int do_pick_commit(void)\n \t\tstruct commit_list *p;\n \n \t\tif (!mainline)\n-\t\t\tdie(_(\"Commit %s is a merge but no -m option was given.\"),\n-\t\t\t    sha1_to_hex(commit->object.sha1));\n+\t\t\treturn error(_(\"Commit %s is a merge but no -m option was given.\"),\n+\t\t\t\tsha1_to_hex(commit->object.sha1));\n \n \t\tfor (cnt = 1, p = commit->parents;\n \t\t     cnt != mainline && p;\n \t\t     cnt++)\n \t\t\tp = p->next;\n \t\tif (cnt != mainline || !p)\n-\t\t\tdie(_(\"Commit %s does not have parent %d\"),\n-\t\t\t    sha1_to_hex(commit->object.sha1), mainline);\n+\t\t\treturn error(_(\"Commit %s does not have parent %d\"),\n+\t\t\t\tsha1_to_hex(commit->object.sha1), mainline);\n \t\tparent = p->item;\n \t} else if (0 < mainline)\n-\t\tdie(_(\"Mainline was specified but commit %s is not a merge.\"),\n-\t\t    sha1_to_hex(commit->object.sha1));\n+\t\treturn error(_(\"Mainline was specified but commit %s is not a merge.\"),\n+\t\t\tsha1_to_hex(commit->object.sha1));\n \telse\n \t\tparent = commit->parents->item;\n \n@@ -414,12 +409,12 @@ static int do_pick_commit(void)\n \tif (parent && parse_commit(parent) < 0)\n \t\t/* TRANSLATORS: The first %s will be \"revert\" or\n \t\t   \"cherry-pick\", the second %s a SHA1 */\n-\t\tdie(_(\"%s: cannot parse parent commit %s\"),\n-\t\t    me, sha1_to_hex(parent->object.sha1));\n+\t\treturn error(_(\"%s: cannot parse parent commit %s\"),\n+\t\t\tme, sha1_to_hex(parent->object.sha1));\n \n \tif (get_message(commit->buffer, &msg) != 0)\n-\t\tdie(_(\"Cannot get commit message for %s\"),\n-\t\t\t\tsha1_to_hex(commit->object.sha1));\n+\t\treturn error(_(\"Cannot get commit message for %s\"),\n+\t\t\tsha1_to_hex(commit->object.sha1));\n \n \t/*\n \t * \"commit\" is an existing commit.  We would want to apply\n@@ -580,14 +575,22 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \n int cmd_revert(int argc, const char **argv, const char *prefix)\n {\n+\tint res;\n \tif (isatty(0))\n \t\tedit = 1;\n \taction = REVERT;\n-\treturn revert_or_cherry_pick(argc, argv);\n+\tres = revert_or_cherry_pick(argc, argv);\n+\tif (res < 0)\n+\t\tdie(_(\"revert failed\"));\n+\treturn res;\n }\n \n int cmd_cherry_pick(int argc, const char **argv, const char *prefix)\n {\n+\tint res;\n \taction = CHERRY_PICK;\n-\treturn revert_or_cherry_pick(argc, argv);\n+\tres = revert_or_cherry_pick(argc, argv);\n+\tif (res < 0)\n+\t\tdie(_(\"cherry-pick failed\"));\n+\treturn res;\n }\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172105","messageId":"1311736755-24205-8-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 07/18] revert: Eliminate global \"commit\" variable","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:04Z","receivedAt":"2011-07-27T03:19:04Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Functions which act on commits currently rely on a file-scope static\nvariable to be set before they're called.  Consequently, the API and\ncorresponding callsites are ugly and unclear.  Remove this variable\nand change their API to accept the commit to act on as additional\nargument so that the callsites change from looking like\n\ncommit = prepare_a_commit();\nact_on_commit();\n\nto looking like\n\ncommit = prepare_a_commit();\nact_on_commit(commit);\n\nThis change is also in line with our long-term goal of exposing some\nof these functions through a public API.\n\nInspired-by: Christian Couder <chriscool@tuxfamily.org>\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |   22 +++++++++++-----------\n 1 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex ee9b4cd..7c4a9c5 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -37,7 +37,6 @@ static const char * const cherry_pick_usage[] = {\n \n static int edit, record_origin, no_commit, mainline, signoff, allow_ff;\n static enum { REVERT, CHERRY_PICK } action;\n-static struct commit *commit;\n static int commit_argc;\n static const char **commit_argv;\n static int allow_rerere_auto;\n@@ -116,25 +115,25 @@ struct commit_message {\n \tconst char *message;\n };\n \n-static int get_message(const char *raw_message, struct commit_message *out)\n+static int get_message(struct commit *commit, struct commit_message *out)\n {\n \tconst char *encoding;\n \tconst char *abbrev, *subject;\n \tint abbrev_len, subject_len;\n \tchar *q;\n \n-\tif (!raw_message)\n+\tif (!commit->buffer)\n \t\treturn -1;\n-\tencoding = get_encoding(raw_message);\n+\tencoding = get_encoding(commit->buffer);\n \tif (!encoding)\n \t\tencoding = \"UTF-8\";\n \tif (!git_commit_encoding)\n \t\tgit_commit_encoding = \"UTF-8\";\n \n \tout->reencoded_message = NULL;\n-\tout->message = raw_message;\n+\tout->message = commit->buffer;\n \tif (strcmp(encoding, git_commit_encoding))\n-\t\tout->reencoded_message = reencode_string(raw_message,\n+\t\tout->reencoded_message = reencode_string(commit->buffer,\n \t\t\t\t\tgit_commit_encoding, encoding);\n \tif (out->reencoded_message)\n \t\tout->message = out->reencoded_message;\n@@ -182,7 +181,7 @@ static char *get_encoding(const char *message)\n \treturn NULL;\n }\n \n-static void write_cherry_pick_head(void)\n+static void write_cherry_pick_head(struct commit *commit)\n {\n \tint fd;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -350,7 +349,7 @@ static int run_git_commit(const char *defmsg)\n \treturn run_command_v_opt(args, RUN_GIT_CMD);\n }\n \n-static int do_pick_commit(void)\n+static int do_pick_commit(struct commit *commit)\n {\n \tunsigned char head[20];\n \tstruct commit *base, *next, *parent;\n@@ -412,7 +411,7 @@ static int do_pick_commit(void)\n \t\treturn error(_(\"%s: cannot parse parent commit %s\"),\n \t\t\tme, sha1_to_hex(parent->object.sha1));\n \n-\tif (get_message(commit->buffer, &msg) != 0)\n+\tif (get_message(commit, &msg) != 0)\n \t\treturn error(_(\"Cannot get commit message for %s\"),\n \t\t\tsha1_to_hex(commit->object.sha1));\n \n@@ -465,7 +464,7 @@ static int do_pick_commit(void)\n \t\t\tstrbuf_addstr(&msgbuf, \")\\n\");\n \t\t}\n \t\tif (!no_commit)\n-\t\t\twrite_cherry_pick_head();\n+\t\t\twrite_cherry_pick_head(commit);\n \t}\n \n \tif (!strategy || !strcmp(strategy, \"recursive\") || action == REVERT) {\n@@ -543,6 +542,7 @@ static void read_and_refresh_cache(const char *me)\n static int revert_or_cherry_pick(int argc, const char **argv)\n {\n \tstruct rev_info revs;\n+\tstruct commit *commit;\n \n \tgit_config(git_default_config, NULL);\n \tme = action == REVERT ? \"revert\" : \"cherry-pick\";\n@@ -565,7 +565,7 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n \tprepare_revs(&revs);\n \n \twhile ((commit = get_revision(&revs))) {\n-\t\tint res = do_pick_commit();\n+\t\tint res = do_pick_commit(commit);\n \t\tif (res)\n \t\t\treturn res;\n \t}\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172113","messageId":"1311736755-24205-9-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 08/18] revert: Introduce struct to keep command-line options","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:05Z","receivedAt":"2011-07-27T03:19:05Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"The current code uses a set of file-scope static variables to tell the\ncherry-pick/ revert machinery how to replay the changes, and\ninitializes them by parsing the command-line arguments.  In later\nsteps in this series, we would like to introduce an API function that\ncalls into this machinery directly and have a way to tell it what to\ndo.  Hence, introduce a structure to group these variables, so that\nthe API can take them as a single replay_options parameter.  The only\nexception is the variable \"me\" -- remove it since it not an\nindependent option, and can be inferred from the action.\n\nUnfortunately, this patch introduces a minor regression.  Parsing\nstrategy-option violates a C89 rule: Initializers cannot refer to\nvariables whose address is not known at compile time.  Currently, this\nrule is violated by some other parts of Git as well, and it is\npossible to get GCC to report these instances using the \"-std=c89\n-pedantic\" option.\n\nInspired-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Jonathan Nieder <jrnieder@gmail.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |  199 ++++++++++++++++++++++++++++++------------------------\n 1 files changed, 112 insertions(+), 87 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 7c4a9c5..58e0dd5 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -35,76 +35,94 @@ static const char * const cherry_pick_usage[] = {\n \tNULL\n };\n \n-static int edit, record_origin, no_commit, mainline, signoff, allow_ff;\n-static enum { REVERT, CHERRY_PICK } action;\n-static int commit_argc;\n-static const char **commit_argv;\n-static int allow_rerere_auto;\n-\n-static const char *me;\n-\n-/* Merge strategy. */\n-static const char *strategy;\n-static const char **xopts;\n-static size_t xopts_nr, xopts_alloc;\n+enum replay_action { REVERT, CHERRY_PICK };\n+\n+struct replay_opts {\n+\tenum replay_action action;\n+\n+\t/* Boolean options */\n+\tint edit;\n+\tint record_origin;\n+\tint no_commit;\n+\tint signoff;\n+\tint allow_ff;\n+\tint allow_rerere_auto;\n+\n+\tint mainline;\n+\tint commit_argc;\n+\tconst char **commit_argv;\n+\n+\t/* Merge strategy */\n+\tconst char *strategy;\n+\tconst char **xopts;\n+\tsize_t xopts_nr, xopts_alloc;\n+};\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \n+static const char *action_name(const struct replay_opts *opts)\n+{\n+\treturn opts->action == REVERT ? \"revert\" : \"cherry-pick\";\n+}\n+\n static char *get_encoding(const char *message);\n \n-static const char * const *revert_or_cherry_pick_usage(void)\n+static const char * const *revert_or_cherry_pick_usage(struct replay_opts *opts)\n {\n-\treturn action == REVERT ? revert_usage : cherry_pick_usage;\n+\treturn opts->action == REVERT ? revert_usage : cherry_pick_usage;\n }\n \n static int option_parse_x(const struct option *opt,\n \t\t\t  const char *arg, int unset)\n {\n+\tstruct replay_opts **opts_ptr = opt->value;\n+\tstruct replay_opts *opts = *opts_ptr;\n+\n \tif (unset)\n \t\treturn 0;\n \n-\tALLOC_GROW(xopts, xopts_nr + 1, xopts_alloc);\n-\txopts[xopts_nr++] = xstrdup(arg);\n+\tALLOC_GROW(opts->xopts, opts->xopts_nr + 1, opts->xopts_alloc);\n+\topts->xopts[opts->xopts_nr++] = xstrdup(arg);\n \treturn 0;\n }\n \n-static void parse_args(int argc, const char **argv)\n+static void parse_args(int argc, const char **argv, struct replay_opts *opts)\n {\n-\tconst char * const * usage_str = revert_or_cherry_pick_usage();\n+\tconst char * const * usage_str = revert_or_cherry_pick_usage(opts);\n \tint noop;\n \tstruct option options[] = {\n-\t\tOPT_BOOLEAN('n', \"no-commit\", &no_commit, \"don't automatically commit\"),\n-\t\tOPT_BOOLEAN('e', \"edit\", &edit, \"edit the commit message\"),\n+\t\tOPT_BOOLEAN('n', \"no-commit\", &opts->no_commit, \"don't automatically commit\"),\n+\t\tOPT_BOOLEAN('e', \"edit\", &opts->edit, \"edit the commit message\"),\n \t\t{ OPTION_BOOLEAN, 'r', NULL, &noop, NULL, \"no-op (backward compatibility)\",\n \t\t  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 0 },\n-\t\tOPT_BOOLEAN('s', \"signoff\", &signoff, \"add Signed-off-by:\"),\n-\t\tOPT_INTEGER('m', \"mainline\", &mainline, \"parent number\"),\n-\t\tOPT_RERERE_AUTOUPDATE(&allow_rerere_auto),\n-\t\tOPT_STRING(0, \"strategy\", &strategy, \"strategy\", \"merge strategy\"),\n-\t\tOPT_CALLBACK('X', \"strategy-option\", &xopts, \"option\",\n+\t\tOPT_BOOLEAN('s', \"signoff\", &opts->signoff, \"add Signed-off-by:\"),\n+\t\tOPT_INTEGER('m', \"mainline\", &opts->mainline, \"parent number\"),\n+\t\tOPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto),\n+\t\tOPT_STRING(0, \"strategy\", &opts->strategy, \"strategy\", \"merge strategy\"),\n+\t\tOPT_CALLBACK('X', \"strategy-option\", &opts, \"option\",\n \t\t\t\"option for merge strategy\", option_parse_x),\n \t\tOPT_END(),\n \t\tOPT_END(),\n \t\tOPT_END(),\n \t};\n \n-\tif (action == CHERRY_PICK) {\n+\tif (opts->action == CHERRY_PICK) {\n \t\tstruct option cp_extra[] = {\n-\t\t\tOPT_BOOLEAN('x', NULL, &record_origin, \"append commit name\"),\n-\t\t\tOPT_BOOLEAN(0, \"ff\", &allow_ff, \"allow fast-forward\"),\n+\t\t\tOPT_BOOLEAN('x', NULL, &opts->record_origin, \"append commit name\"),\n+\t\t\tOPT_BOOLEAN(0, \"ff\", &opts->allow_ff, \"allow fast-forward\"),\n \t\t\tOPT_END(),\n \t\t};\n \t\tif (parse_options_concat(options, ARRAY_SIZE(options), cp_extra))\n \t\t\tdie(_(\"program error\"));\n \t}\n \n-\tcommit_argc = parse_options(argc, argv, NULL, options, usage_str,\n-\t\t\t\t    PARSE_OPT_KEEP_ARGV0 |\n-\t\t\t\t    PARSE_OPT_KEEP_UNKNOWN);\n-\tif (commit_argc < 2)\n+\topts->commit_argc = parse_options(argc, argv, NULL, options, usage_str,\n+\t\t\t\t\tPARSE_OPT_KEEP_ARGV0 |\n+\t\t\t\t\tPARSE_OPT_KEEP_UNKNOWN);\n+\tif (opts->commit_argc < 2)\n \t\tusage_with_options(usage_str, options);\n \n-\tcommit_argv = argv;\n+\topts->commit_argv = argv;\n }\n \n struct commit_message {\n@@ -240,13 +258,13 @@ static struct tree *empty_tree(void)\n \treturn tree;\n }\n \n-static int error_dirty_index(const char *me)\n+static int error_dirty_index(struct replay_opts *opts)\n {\n \tif (read_cache_unmerged())\n-\t\treturn error_resolve_conflict(me);\n+\t\treturn error_resolve_conflict(action_name(opts));\n \n \t/* Different translation strings for cherry-pick and revert */\n-\tif (action == CHERRY_PICK)\n+\tif (opts->action == CHERRY_PICK)\n \t\terror(_(\"Your local changes would be overwritten by cherry-pick.\"));\n \telse\n \t\terror(_(\"Your local changes would be overwritten by revert.\"));\n@@ -269,7 +287,8 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from)\n \n static int do_recursive_merge(struct commit *base, struct commit *next,\n \t\t\t      const char *base_label, const char *next_label,\n-\t\t\t      unsigned char *head, struct strbuf *msgbuf)\n+\t\t\t      unsigned char *head, struct strbuf *msgbuf,\n+\t\t\t      struct replay_opts *opts)\n {\n \tstruct merge_options o;\n \tstruct tree *result, *next_tree, *base_tree, *head_tree;\n@@ -290,7 +309,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n \tnext_tree = next ? next->tree : empty_tree();\n \tbase_tree = base ? base->tree : empty_tree();\n \n-\tfor (xopt = xopts; xopt != xopts + xopts_nr; xopt++)\n+\tfor (xopt = opts->xopts; xopt != opts->xopts + opts->xopts_nr; xopt++)\n \t\tparse_merge_opt(&o, *xopt);\n \n \tclean = merge_trees(&o,\n@@ -301,7 +320,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n \t    (write_cache(index_fd, active_cache, active_nr) ||\n \t     commit_locked_index(&index_lock)))\n \t\t/* TRANSLATORS: %s will be \"revert\" or \"cherry-pick\" */\n-\t\tdie(_(\"%s: Unable to write new index file\"), me);\n+\t\tdie(_(\"%s: Unable to write new index file\"), action_name(opts));\n \trollback_lock_file(&index_lock);\n \n \tif (!clean) {\n@@ -330,7 +349,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,\n  * If we are revert, or if our cherry-pick results in a hand merge,\n  * we had better say that the current user is responsible for that.\n  */\n-static int run_git_commit(const char *defmsg)\n+static int run_git_commit(const char *defmsg, struct replay_opts *opts)\n {\n \t/* 6 is max possible length of our args array including NULL */\n \tconst char *args[6];\n@@ -338,9 +357,9 @@ static int run_git_commit(const char *defmsg)\n \n \targs[i++] = \"commit\";\n \targs[i++] = \"-n\";\n-\tif (signoff)\n+\tif (opts->signoff)\n \t\targs[i++] = \"-s\";\n-\tif (!edit) {\n+\tif (!opts->edit) {\n \t\targs[i++] = \"-F\";\n \t\targs[i++] = defmsg;\n \t}\n@@ -349,7 +368,7 @@ static int run_git_commit(const char *defmsg)\n \treturn run_command_v_opt(args, RUN_GIT_CMD);\n }\n \n-static int do_pick_commit(struct commit *commit)\n+static int do_pick_commit(struct commit *commit, struct replay_opts *opts)\n {\n \tunsigned char head[20];\n \tstruct commit *base, *next, *parent;\n@@ -359,7 +378,7 @@ static int do_pick_commit(struct commit *commit)\n \tstruct strbuf msgbuf = STRBUF_INIT;\n \tint res;\n \n-\tif (no_commit) {\n+\tif (opts->no_commit) {\n \t\t/*\n \t\t * We do not intend to commit immediately.  We just want to\n \t\t * merge the differences in, so let's compute the tree\n@@ -372,7 +391,7 @@ static int do_pick_commit(struct commit *commit)\n \t\tif (get_sha1(\"HEAD\", head))\n \t\t\treturn error(_(\"You do not have a valid HEAD\"));\n \t\tif (index_differs_from(\"HEAD\", 0))\n-\t\t\treturn error_dirty_index(me);\n+\t\t\treturn error_dirty_index(opts);\n \t}\n \tdiscard_cache();\n \n@@ -384,32 +403,32 @@ static int do_pick_commit(struct commit *commit)\n \t\tint cnt;\n \t\tstruct commit_list *p;\n \n-\t\tif (!mainline)\n+\t\tif (!opts->mainline)\n \t\t\treturn error(_(\"Commit %s is a merge but no -m option was given.\"),\n \t\t\t\tsha1_to_hex(commit->object.sha1));\n \n \t\tfor (cnt = 1, p = commit->parents;\n-\t\t     cnt != mainline && p;\n+\t\t     cnt != opts->mainline && p;\n \t\t     cnt++)\n \t\t\tp = p->next;\n-\t\tif (cnt != mainline || !p)\n+\t\tif (cnt != opts->mainline || !p)\n \t\t\treturn error(_(\"Commit %s does not have parent %d\"),\n-\t\t\t\tsha1_to_hex(commit->object.sha1), mainline);\n+\t\t\t\tsha1_to_hex(commit->object.sha1), opts->mainline);\n \t\tparent = p->item;\n-\t} else if (0 < mainline)\n+\t} else if (0 < opts->mainline)\n \t\treturn error(_(\"Mainline was specified but commit %s is not a merge.\"),\n \t\t\tsha1_to_hex(commit->object.sha1));\n \telse\n \t\tparent = commit->parents->item;\n \n-\tif (allow_ff && parent && !hashcmp(parent->object.sha1, head))\n+\tif (opts->allow_ff && parent && !hashcmp(parent->object.sha1, head))\n \t\treturn fast_forward_to(commit->object.sha1, head);\n \n \tif (parent && parse_commit(parent) < 0)\n \t\t/* TRANSLATORS: The first %s will be \"revert\" or\n \t\t   \"cherry-pick\", the second %s a SHA1 */\n \t\treturn error(_(\"%s: cannot parse parent commit %s\"),\n-\t\t\tme, sha1_to_hex(parent->object.sha1));\n+\t\t\taction_name(opts), sha1_to_hex(parent->object.sha1));\n \n \tif (get_message(commit, &msg) != 0)\n \t\treturn error(_(\"Cannot get commit message for %s\"),\n@@ -424,7 +443,7 @@ static int do_pick_commit(struct commit *commit)\n \n \tdefmsg = git_pathdup(\"MERGE_MSG\");\n \n-\tif (action == REVERT) {\n+\tif (opts->action == REVERT) {\n \t\tbase = commit;\n \t\tbase_label = msg.label;\n \t\tnext = parent;\n@@ -458,18 +477,18 @@ static int do_pick_commit(struct commit *commit)\n \t\t\tstrbuf_addstr(&msgbuf, p);\n \t\t}\n \n-\t\tif (record_origin) {\n+\t\tif (opts->record_origin) {\n \t\t\tstrbuf_addstr(&msgbuf, \"(cherry picked from commit \");\n \t\t\tstrbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));\n \t\t\tstrbuf_addstr(&msgbuf, \")\\n\");\n \t\t}\n-\t\tif (!no_commit)\n+\t\tif (!opts->no_commit)\n \t\t\twrite_cherry_pick_head(commit);\n \t}\n \n-\tif (!strategy || !strcmp(strategy, \"recursive\") || action == REVERT) {\n+\tif (!opts->strategy || !strcmp(opts->strategy, \"recursive\") || opts->action == REVERT) {\n \t\tres = do_recursive_merge(base, next, base_label, next_label,\n-\t\t\t\t\t head, &msgbuf);\n+\t\t\t\t\t head, &msgbuf, opts);\n \t\twrite_message(&msgbuf, defmsg);\n \t} else {\n \t\tstruct commit_list *common = NULL;\n@@ -479,23 +498,23 @@ static int do_pick_commit(struct commit *commit)\n \n \t\tcommit_list_insert(base, &common);\n \t\tcommit_list_insert(next, &remotes);\n-\t\tres = try_merge_command(strategy, xopts_nr, xopts, common,\n-\t\t\t\t\tsha1_to_hex(head), remotes);\n+\t\tres = try_merge_command(opts->strategy, opts->xopts_nr, opts->xopts,\n+\t\t\t\t\tcommon, sha1_to_hex(head), remotes);\n \t\tfree_commit_list(common);\n \t\tfree_commit_list(remotes);\n \t}\n \n \tif (res) {\n-\t\terror(action == REVERT\n+\t\terror(opts->action == REVERT\n \t\t      ? _(\"could not revert %s... %s\")\n \t\t      : _(\"could not apply %s... %s\"),\n \t\t      find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),\n \t\t      msg.subject);\n \t\tprint_advice();\n-\t\trerere(allow_rerere_auto);\n+\t\trerere(opts->allow_rerere_auto);\n \t} else {\n-\t\tif (!no_commit)\n-\t\t\tres = run_git_commit(defmsg);\n+\t\tif (!opts->no_commit)\n+\t\t\tres = run_git_commit(defmsg, opts);\n \t}\n \n \tfree_message(&msg);\n@@ -504,18 +523,18 @@ static int do_pick_commit(struct commit *commit)\n \treturn res;\n }\n \n-static void prepare_revs(struct rev_info *revs)\n+static void prepare_revs(struct rev_info *revs, struct replay_opts *opts)\n {\n \tint argc;\n \n \tinit_revisions(revs, NULL);\n \trevs->no_walk = 1;\n-\tif (action != REVERT)\n+\tif (opts->action != REVERT)\n \t\trevs->reverse = 1;\n \n-\targc = setup_revisions(commit_argc, commit_argv, revs, NULL);\n+\targc = setup_revisions(opts->commit_argc, opts->commit_argv, revs, NULL);\n \tif (argc > 1)\n-\t\tusage(*revert_or_cherry_pick_usage());\n+\t\tusage(*revert_or_cherry_pick_usage(opts));\n \n \tif (prepare_revision_walk(revs))\n \t\tdie(_(\"revision walk setup failed\"));\n@@ -524,48 +543,48 @@ static void prepare_revs(struct rev_info *revs)\n \t\tdie(_(\"empty commit set passed\"));\n }\n \n-static void read_and_refresh_cache(const char *me)\n+static void read_and_refresh_cache(struct replay_opts *opts)\n {\n \tstatic struct lock_file index_lock;\n \tint index_fd = hold_locked_index(&index_lock, 0);\n \tif (read_index_preload(&the_index, NULL) < 0)\n-\t\tdie(_(\"git %s: failed to read the index\"), me);\n+\t\tdie(_(\"git %s: failed to read the index\"), action_name(opts));\n \trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, NULL, NULL, NULL);\n \tif (the_index.cache_changed) {\n \t\tif (write_index(&the_index, index_fd) ||\n \t\t    commit_locked_index(&index_lock))\n-\t\t\tdie(_(\"git %s: failed to refresh the index\"), me);\n+\t\t\tdie(_(\"git %s: failed to refresh the index\"), action_name(opts));\n \t}\n \trollback_lock_file(&index_lock);\n }\n \n-static int revert_or_cherry_pick(int argc, const char **argv)\n+static int revert_or_cherry_pick(int argc, const char **argv,\n+\t\t\t\tstruct replay_opts *opts)\n {\n \tstruct rev_info revs;\n \tstruct commit *commit;\n \n \tgit_config(git_default_config, NULL);\n-\tme = action == REVERT ? \"revert\" : \"cherry-pick\";\n-\tsetenv(GIT_REFLOG_ACTION, me, 0);\n-\tparse_args(argc, argv);\n+\tsetenv(GIT_REFLOG_ACTION, action_name(opts), 0);\n+\tparse_args(argc, argv, opts);\n \n-\tif (allow_ff) {\n-\t\tif (signoff)\n+\tif (opts->allow_ff) {\n+\t\tif (opts->signoff)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with --signoff\"));\n-\t\tif (no_commit)\n+\t\tif (opts->no_commit)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with --no-commit\"));\n-\t\tif (record_origin)\n+\t\tif (opts->record_origin)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with -x\"));\n-\t\tif (edit)\n+\t\tif (opts->edit)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with --edit\"));\n \t}\n \n-\tread_and_refresh_cache(me);\n+\tread_and_refresh_cache(opts);\n \n-\tprepare_revs(&revs);\n+\tprepare_revs(&revs, opts);\n \n \twhile ((commit = get_revision(&revs))) {\n-\t\tint res = do_pick_commit(commit);\n+\t\tint res = do_pick_commit(commit, opts);\n \t\tif (res)\n \t\t\treturn res;\n \t}\n@@ -576,10 +595,13 @@ static int revert_or_cherry_pick(int argc, const char **argv)\n int cmd_revert(int argc, const char **argv, const char *prefix)\n {\n \tint res;\n+\tstruct replay_opts opts;\n+\n+\tmemset(&opts, 0, sizeof(struct replay_opts));\n \tif (isatty(0))\n-\t\tedit = 1;\n-\taction = REVERT;\n-\tres = revert_or_cherry_pick(argc, argv);\n+\t\topts.edit = 1;\n+\topts.action = REVERT;\n+\tres = revert_or_cherry_pick(argc, argv, &opts);\n \tif (res < 0)\n \t\tdie(_(\"revert failed\"));\n \treturn res;\n@@ -588,8 +610,11 @@ int cmd_revert(int argc, const char **argv, const char *prefix)\n int cmd_cherry_pick(int argc, const char **argv, const char *prefix)\n {\n \tint res;\n-\taction = CHERRY_PICK;\n-\tres = revert_or_cherry_pick(argc, argv);\n+\tstruct replay_opts opts;\n+\n+\tmemset(&opts, 0, sizeof(struct replay_opts));\n+\topts.action = CHERRY_PICK;\n+\tres = revert_or_cherry_pick(argc, argv, &opts);\n \tif (res < 0)\n \t\tdie(_(\"cherry-pick failed\"));\n \treturn res;\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172111","messageId":"1311736755-24205-10-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 09/18] revert: Separate cmdline parsing from functional code","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:06Z","receivedAt":"2011-07-27T03:19:06Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Currently, revert_or_cherry_pick sets up a default git config, parses\ncommand-line arguments, before preparing to pick commits.  This makes\nfor a bad API as the central worry of callers is to assert whether or\nnot a conflict occured while cherry picking.  The current API is like:\n\nif (revert_or_cherry_pick(argc, argv, opts) < 0)\n   print \"Something failed, we're not sure what\"\n\nSimplify and rename revert_or_cherry_pick to pick_commits so that it\nonly has the responsibility of setting up the revision walker and\npicking commits in a loop.  Transfer the remaining work to its\ncallers.  Now, the API is simplified as:\n\nif (parse_args(argc, argv, opts) < 0)\n   print \"Can't parse arguments\"\nif (pick_commits(opts) < 0)\n   print \"Error encountered in picking machinery\"\n\nLater in the series, pick_commits will also serve as the starting\npoint for continuing a cherry-pick or revert.\n\nInspired-by: Christian Couder <chriscool@tuxfamily.org>\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |   14 +++++++-------\n 1 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 58e0dd5..ab7f0bb 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -558,16 +558,12 @@ static void read_and_refresh_cache(struct replay_opts *opts)\n \trollback_lock_file(&index_lock);\n }\n \n-static int revert_or_cherry_pick(int argc, const char **argv,\n-\t\t\t\tstruct replay_opts *opts)\n+static int pick_commits(struct replay_opts *opts)\n {\n \tstruct rev_info revs;\n \tstruct commit *commit;\n \n-\tgit_config(git_default_config, NULL);\n \tsetenv(GIT_REFLOG_ACTION, action_name(opts), 0);\n-\tparse_args(argc, argv, opts);\n-\n \tif (opts->allow_ff) {\n \t\tif (opts->signoff)\n \t\t\tdie(_(\"cherry-pick --ff cannot be used with --signoff\"));\n@@ -601,7 +597,9 @@ int cmd_revert(int argc, const char **argv, const char *prefix)\n \tif (isatty(0))\n \t\topts.edit = 1;\n \topts.action = REVERT;\n-\tres = revert_or_cherry_pick(argc, argv, &opts);\n+\tgit_config(git_default_config, NULL);\n+\tparse_args(argc, argv, &opts);\n+\tres = pick_commits(&opts);\n \tif (res < 0)\n \t\tdie(_(\"revert failed\"));\n \treturn res;\n@@ -614,7 +612,9 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)\n \n \tmemset(&opts, 0, sizeof(struct replay_opts));\n \topts.action = CHERRY_PICK;\n-\tres = revert_or_cherry_pick(argc, argv, &opts);\n+\tgit_config(git_default_config, NULL);\n+\tparse_args(argc, argv, &opts);\n+\tres = pick_commits(&opts);\n \tif (res < 0)\n \t\tdie(_(\"cherry-pick failed\"));\n \treturn res;\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172106","messageId":"1311736755-24205-11-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 10/18] revert: Don't create invalid replay_opts in parse_args","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:07Z","receivedAt":"2011-07-27T03:19:07Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"The \"--ff\" command-line option cannot be used with some other\ncommand-line options.  However, parse_args still parses these\nincompatible options into a replay_opts structure for use by the rest\nof the program.  Although pick_commits, the current gatekeeper to the\ncherry-pick machinery, checks the validity of the replay_opts\nstructure before before starting its operation, there will be multiple\nentry points to the cherry-pick machinery in future.  To futureproof\nthe code and catch these errors in one place, make sure that an\ninvalid replay_opts structure is not created by parse_args in the\nfirst place.  We still check the replay_opts structure for validity in\npick_commits, but this is an assert() now to emphasize that it's the\ncaller's responsibility to get it right.\n\nInspired-by: Christian Couder <chriscool@tuxfamily.org>\nMentored-by: Jonathan Nieder <jrnieder@gmail.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |   38 +++++++++++++++++++++++++++-----------\n 1 files changed, 27 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex ab7f0bb..5e26a43 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -86,9 +86,26 @@ static int option_parse_x(const struct option *opt,\n \treturn 0;\n }\n \n+static void verify_opt_compatible(const char *me, const char *base_opt, ...)\n+{\n+\tconst char *this_opt;\n+\tva_list ap;\n+\tint set;\n+\n+\tva_start(ap, base_opt);\n+\twhile ((this_opt = va_arg(ap, const char *))) {\n+\t\tset = va_arg(ap, int);\n+\t\tif (set)\n+\t\t\tdie(_(\"%s: %s cannot be used with %s\"),\n+\t\t\t\tme, this_opt, base_opt);\n+\t}\n+\tva_end(ap);\n+}\n+\n static void parse_args(int argc, const char **argv, struct replay_opts *opts)\n {\n \tconst char * const * usage_str = revert_or_cherry_pick_usage(opts);\n+\tconst char *me = action_name(opts);\n \tint noop;\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN('n', \"no-commit\", &opts->no_commit, \"don't automatically commit\"),\n@@ -122,6 +139,13 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)\n \tif (opts->commit_argc < 2)\n \t\tusage_with_options(usage_str, options);\n \n+\tif (opts->allow_ff)\n+\t\tverify_opt_compatible(me, \"--ff\",\n+\t\t\t\t\"--signoff\", opts->signoff,\n+\t\t\t\t\"--no-commit\", opts->no_commit,\n+\t\t\t\t\"-x\", opts->record_origin,\n+\t\t\t\t\"--edit\", opts->edit,\n+\t\t\t\tNULL);\n \topts->commit_argv = argv;\n }\n \n@@ -564,17 +588,9 @@ static int pick_commits(struct replay_opts *opts)\n \tstruct commit *commit;\n \n \tsetenv(GIT_REFLOG_ACTION, action_name(opts), 0);\n-\tif (opts->allow_ff) {\n-\t\tif (opts->signoff)\n-\t\t\tdie(_(\"cherry-pick --ff cannot be used with --signoff\"));\n-\t\tif (opts->no_commit)\n-\t\t\tdie(_(\"cherry-pick --ff cannot be used with --no-commit\"));\n-\t\tif (opts->record_origin)\n-\t\t\tdie(_(\"cherry-pick --ff cannot be used with -x\"));\n-\t\tif (opts->edit)\n-\t\t\tdie(_(\"cherry-pick --ff cannot be used with --edit\"));\n-\t}\n-\n+\tif (opts->allow_ff)\n+\t\tassert(!(opts->signoff || opts->no_commit ||\n+\t\t\t\topts->record_origin || opts->edit));\n \tread_and_refresh_cache(opts);\n \n \tprepare_revs(&revs, opts);\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172107","messageId":"1311736755-24205-12-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 11/18] revert: Save data for continuing after conflict resolution","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:08Z","receivedAt":"2011-07-27T03:19:08Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Ever since v1.7.2-rc1~4^2~7 (revert: allow cherry-picking more than\none commit, 2010-06-02), a single invocation of \"git cherry-pick\" or\n\"git revert\" can perform picks of several individual commits.  To\nimplement features like \"--continue\" to continue the whole operation,\nwe will need to store some information about the state and the plan at\nthe beginning.  Introduce a \".git/sequencer/head\" file to store this\nstate, and \".git/sequencer/todo\" file to store the plan.  The head\nfile contains the SHA-1 of the HEAD before the start of the operation,\nand the todo file contains an instruction sheet whose format is\ninspired by the format of the \"rebase -i\" instruction sheet.  As a\nresult, a typical todo file looks like:\n\npick 8537f0e submodule add: test failure when url is not configured\npick 4d68932 submodule add: allow relative repository path\npick f22a17e submodule add: clean up duplicated code\npick 59a5775 make copy_ref globally available\n\nSince SHA-1 hex is abbreviated using an find_unique_abbrev(), it is\nunambiguous.  This does not guarantee that there will be no ambiguity\nwhen more objects are added to the repository.\n\nThat these two files alone are not enough to implement a \"--continue\"\nthat remembers the command-line options specified; later patches in\nthe series save them too.\n\nThese new files are unrelated to the existing .git/CHERRY_PICK_HEAD,\nwhich will still be useful while committing after a conflict\nresolution.\n\nInspired-by: Christian Couder <chriscool@tuxfamily.org>\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c                |  222 +++++++++++++++++++++++++++++++++++++-\n t/t3510-cherry-pick-sequence.sh |   48 +++++++++\n 2 files changed, 264 insertions(+), 6 deletions(-)\n create mode 100755 t/t3510-cherry-pick-sequence.sh\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 5e26a43..b3b1bf8 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -13,6 +13,7 @@\n #include \"rerere.h\"\n #include \"merge-recursive.h\"\n #include \"refs.h\"\n+#include \"dir.h\"\n \n /*\n  * This implements the builtins revert and cherry-pick.\n@@ -59,6 +60,11 @@ struct replay_opts {\n };\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n+#define MAYBE_UNUSED __attribute__((__unused__))\n+\n+#define SEQ_DIR         \"sequencer\"\n+#define SEQ_HEAD_FILE   \"sequencer/head\"\n+#define SEQ_TODO_FILE   \"sequencer/todo\"\n \n static const char *action_name(const struct replay_opts *opts)\n {\n@@ -269,7 +275,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename)\n \t\tdie_errno(_(\"Could not write to %s.\"), filename);\n \tstrbuf_release(msgbuf);\n \tif (commit_lock_file(&msg_file) < 0)\n-\t\tdie(_(\"Error wrapping up %s\"), filename);\n+\t\tdie(_(\"Error wrapping up %s.\"), filename);\n }\n \n static struct tree *empty_tree(void)\n@@ -582,10 +588,199 @@ static void read_and_refresh_cache(struct replay_opts *opts)\n \trollback_lock_file(&index_lock);\n }\n \n-static int pick_commits(struct replay_opts *opts)\n+/*\n+ * Append a commit to the end of the commit_list.\n+ *\n+ * next starts by pointing to the variable that holds the head of an\n+ * empty commit_list, and is updated to point to the \"next\" field of\n+ * the last item on the list as new commits are appended.\n+ *\n+ * Usage example:\n+ *\n+ *     struct commit_list *list;\n+ *     struct commit_list **next = &list;\n+ *\n+ *     next = commit_list_append(c1, next);\n+ *     next = commit_list_append(c2, next);\n+ *     assert(commit_list_count(list) == 2);\n+ *     return list;\n+ */\n+struct commit_list **commit_list_append(struct commit *commit,\n+\t\t\t\t\tstruct commit_list **next)\n+{\n+\tstruct commit_list *new = xmalloc(sizeof(struct commit_list));\n+\tnew->item = commit;\n+\t*next = new;\n+\tnew->next = NULL;\n+\treturn &new->next;\n+}\n+\n+static int format_todo(struct strbuf *buf, struct commit_list *todo_list,\n+\t\tstruct replay_opts *opts)\n+{\n+\tstruct commit_list *cur = NULL;\n+\tstruct commit_message msg = { NULL, NULL, NULL, NULL, NULL };\n+\tconst char *sha1_abbrev = NULL;\n+\tconst char *action_str = opts->action == REVERT ? \"revert\" : \"pick\";\n+\n+\tfor (cur = todo_list; cur; cur = cur->next) {\n+\t\tsha1_abbrev = find_unique_abbrev(cur->item->object.sha1, DEFAULT_ABBREV);\n+\t\tif (get_message(cur->item, &msg))\n+\t\t\treturn error(_(\"Cannot get commit message for %s\"), sha1_abbrev);\n+\t\tstrbuf_addf(buf, \"%s %s %s\\n\", action_str, sha1_abbrev, msg.subject);\n+\t}\n+\treturn 0;\n+}\n+\n+static struct commit *parse_insn_line(char *start, struct replay_opts *opts)\n+{\n+\tunsigned char commit_sha1[20];\n+\tchar sha1_abbrev[40];\n+\tstruct commit *commit;\n+\tenum replay_action action;\n+\tint insn_len = 0;\n+\tchar *p, *q;\n+\n+\tif (!prefixcmp(start, \"pick \")) {\n+\t\taction = CHERRY_PICK;\n+\t\tinsn_len = strlen(\"pick\");\n+\t\tp = start + insn_len + 1;\n+\t}\n+\telse if (!prefixcmp(start, \"revert \")) {\n+\t\taction = REVERT;\n+\t\tinsn_len = strlen(\"revert\");\n+\t\tp = start + insn_len + 1;\n+\t}\n+\telse\n+\t\treturn NULL;\n+\n+\tq = strchr(p, ' ');\n+\tif (!q)\n+\t\treturn NULL;\n+\tq++;\n+\n+\tstrlcpy(sha1_abbrev, p, q - p);\n+\n+\t/*\n+\t * Verify that the action matches up with the one in\n+\t * opts; we don't support arbitrary instructions\n+\t */\n+\tif (action != opts->action) {\n+\t\tconst char *action_str;\n+\t\taction_str = action == REVERT ? \"revert\" : \"cherry-pick\";\n+\t\terror(_(\"Cannot %s during a %s\"), action_str, action_name(opts));\n+\t\treturn NULL;\n+\t}\n+\n+\tif ((get_sha1(sha1_abbrev, commit_sha1) < 0)\n+\t\t|| !(commit = lookup_commit_reference(commit_sha1)))\n+\t\treturn NULL;\n+\n+\treturn commit;\n+}\n+\n+static void MAYBE_UNUSED read_populate_todo(struct commit_list **todo_list,\n+\t\t\t\t\tstruct replay_opts *opts)\n+{\n+\tconst char *todo_file = git_path(SEQ_TODO_FILE);\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct commit_list **next;\n+\tstruct commit *commit;\n+\tchar *p;\n+\tint fd;\n+\n+\tfd = open(todo_file, O_RDONLY);\n+\tif (fd < 0) {\n+\t\tstrbuf_release(&buf);\n+\t\tdie_errno(_(\"Could not open %s.\"), todo_file);\n+\t}\n+\tif (strbuf_read(&buf, fd, 0) < buf.len) {\n+\t\tclose(fd);\n+\t\tstrbuf_release(&buf);\n+\t\tdie(_(\"Could not read %s.\"), todo_file);\n+\t}\n+\tclose(fd);\n+\n+\tnext = todo_list;\n+\tfor (p = buf.buf; *p; p = strchr(p, '\\n') + 1) {\n+\t\tif (!(commit = parse_insn_line(p, opts)))\n+\t\t\tgoto error;\n+\t\tnext = commit_list_append(commit, next);\n+\t}\n+\tif (!*todo_list)\n+\t\tgoto error;\n+\tstrbuf_release(&buf);\n+\treturn;\n+error:\n+\tstrbuf_release(&buf);\n+\tdie(_(\"Unusable instruction sheet: %s\"), todo_file);\n+}\n+\n+static void walk_revs_populate_todo(struct commit_list **todo_list,\n+\t\t\t\tstruct replay_opts *opts)\n {\n \tstruct rev_info revs;\n \tstruct commit *commit;\n+\tstruct commit_list **next;\n+\n+\tprepare_revs(&revs, opts);\n+\n+\tnext = todo_list;\n+\twhile ((commit = get_revision(&revs)))\n+\t\tnext = commit_list_append(commit, next);\n+}\n+\n+static void create_seq_dir(void)\n+{\n+\tconst char *seq_dir = git_path(SEQ_DIR);\n+\n+\tif (!file_exists(seq_dir) && mkdir(seq_dir, 0777) < 0)\n+\t\tdie_errno(_(\"Could not create sequencer directory '%s'.\"), seq_dir);\n+}\n+\n+static void save_head(const char *head)\n+{\n+\tconst char *head_file = git_path(SEQ_HEAD_FILE);\n+\tstatic struct lock_file head_lock;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint fd;\n+\n+\tfd = hold_lock_file_for_update(&head_lock, head_file, LOCK_DIE_ON_ERROR);\n+\tstrbuf_addf(&buf, \"%s\\n\", head);\n+\tif (write_in_full(fd, buf.buf, buf.len) < 0)\n+\t\tdie_errno(_(\"Could not write to %s.\"), head_file);\n+\tif (commit_lock_file(&head_lock) < 0)\n+\t\tdie(_(\"Error wrapping up %s.\"), head_file);\n+}\n+\n+static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)\n+{\n+\tconst char *todo_file = git_path(SEQ_TODO_FILE);\n+\tstatic struct lock_file todo_lock;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint fd;\n+\n+\tfd = hold_lock_file_for_update(&todo_lock, todo_file, LOCK_DIE_ON_ERROR);\n+\tif (format_todo(&buf, todo_list, opts) < 0)\n+\t\tdie(_(\"Could not format %s.\"), todo_file);\n+\tif (write_in_full(fd, buf.buf, buf.len) < 0) {\n+\t\tstrbuf_release(&buf);\n+\t\tdie_errno(_(\"Could not write to %s.\"), todo_file);\n+\t}\n+\tif (commit_lock_file(&todo_lock) < 0) {\n+\t\tstrbuf_release(&buf);\n+\t\tdie(_(\"Error wrapping up %s.\"), todo_file);\n+\t}\n+\tstrbuf_release(&buf);\n+}\n+\n+static int pick_commits(struct replay_opts *opts)\n+{\n+\tstruct commit_list *todo_list = NULL;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tunsigned char sha1[20];\n+\tstruct commit_list *cur;\n+\tint res;\n \n \tsetenv(GIT_REFLOG_ACTION, action_name(opts), 0);\n \tif (opts->allow_ff)\n@@ -593,14 +788,29 @@ static int pick_commits(struct replay_opts *opts)\n \t\t\t\topts->record_origin || opts->edit));\n \tread_and_refresh_cache(opts);\n \n-\tprepare_revs(&revs, opts);\n-\n-\twhile ((commit = get_revision(&revs))) {\n-\t\tint res = do_pick_commit(commit, opts);\n+\twalk_revs_populate_todo(&todo_list, opts);\n+\tcreate_seq_dir();\n+\tif (get_sha1(\"HEAD\", sha1)) {\n+\t\tif (opts->action == REVERT)\n+\t\t\treturn error(_(\"Can't revert as initial commit\"));\n+\t\treturn error(_(\"Can't cherry-pick into empty head\"));\n+\t} else\n+\t\tsave_head(sha1_to_hex(sha1));\n+\tsave_todo(todo_list, opts);\n+\n+\tfor (cur = todo_list; cur; cur = cur->next) {\n+\t\tsave_todo(cur, opts);\n+\t\tres = do_pick_commit(cur->item, opts);\n \t\tif (res)\n \t\t\treturn res;\n \t}\n \n+\t/*\n+\t * Sequence of picks finished successfully; cleanup by\n+\t * removing the .git/sequencer directory\n+\t */\n+\tstrbuf_addf(&buf, \"%s\", git_path(SEQ_DIR));\n+\tremove_dir_recursively(&buf, 0);\n \treturn 0;\n }\n \ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nnew file mode 100755\nindex 0000000..64eaa20\n--- /dev/null\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -0,0 +1,48 @@\n+#!/bin/sh\n+\n+test_description='Test cherry-pick continuation features\n+\n+  + anotherpick: rewrites foo to d\n+  + picked: rewrites foo to c\n+  + unrelatedpick: rewrites unrelated to reallyunrelated\n+  + base: rewrites foo to b\n+  + initial: writes foo as a, unrelated as unrelated\n+\n+'\n+\n+. ./test-lib.sh\n+\n+pristine_detach () {\n+\tgit checkout -f \"$1^0\" &&\n+\tgit read-tree -u --reset HEAD &&\n+\tgit clean -d -f -f -q -x\n+}\n+\n+test_expect_success setup '\n+\techo unrelated >unrelated &&\n+\tgit add unrelated &&\n+\ttest_commit initial foo a &&\n+\ttest_commit base foo b &&\n+\ttest_commit unrelatedpick unrelated reallyunrelated &&\n+\ttest_commit picked foo c &&\n+\ttest_commit anotherpick foo d &&\n+\tgit config advice.detachedhead false\n+\n+'\n+\n+test_expect_success 'cherry-pick persists data on failure' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..anotherpick &&\n+\ttest_path_is_dir .git/sequencer &&\n+\ttest_path_is_file .git/sequencer/head &&\n+\ttest_path_is_file .git/sequencer/todo &&\n+\trm -rf .git/sequencer\n+'\n+\n+test_expect_success 'cherry-pick cleans up sequencer state upon success' '\n+\tpristine_detach initial &&\n+\tgit cherry-pick initial..picked &&\n+\ttest_path_is_missing .git/sequencer\n+'\n+\n+test_done\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172109","messageId":"1311736755-24205-13-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 12/18] revert: Save command-line options for continuing operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:09Z","receivedAt":"2011-07-27T03:19:09Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"In the same spirit as \".git/sequencer/head\" and \".git/sequencer/todo\",\nintroduce \".git/sequencer/opts\" to persist the replay_opts structure\nfor continuing after a conflict resolution.  Use the gitconfig format\nfor this file so that it looks like:\n\n[core]\n\tsignoff = true\n\trecord-origin = true\n\tmainline = 1\n\tstrategy = recursive\n\tstrategy-option = patience\n\tstrategy-option = ours\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c                |   78 +++++++++++++++++++++++++++++++++++++++\n t/t3510-cherry-pick-sequence.sh |   28 +++++++++++++-\n 2 files changed, 105 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex b3b1bf8..b02d3d2 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -65,6 +65,7 @@ struct replay_opts {\n #define SEQ_DIR         \"sequencer\"\n #define SEQ_HEAD_FILE   \"sequencer/head\"\n #define SEQ_TODO_FILE   \"sequencer/todo\"\n+#define SEQ_OPTS_FILE   \"sequencer/opts\"\n \n static const char *action_name(const struct replay_opts *opts)\n {\n@@ -716,6 +717,49 @@ error:\n \tdie(_(\"Unusable instruction sheet: %s\"), todo_file);\n }\n \n+static int populate_opts_cb(const char *key, const char *value, void *data)\n+{\n+\tstruct replay_opts *opts = data;\n+\tint error_flag = 1;\n+\n+\tif (!value)\n+\t\terror_flag = 0;\n+\telse if (!strcmp(key, \"core.no-commit\"))\n+\t\topts->no_commit = git_config_bool_or_int(key, value, &error_flag);\n+\telse if (!strcmp(key, \"core.edit\"))\n+\t\topts->edit = git_config_bool_or_int(key, value, &error_flag);\n+\telse if (!strcmp(key, \"core.signoff\"))\n+\t\topts->signoff = git_config_bool_or_int(key, value, &error_flag);\n+\telse if (!strcmp(key, \"core.record-origin\"))\n+\t\topts->record_origin = git_config_bool_or_int(key, value, &error_flag);\n+\telse if (!strcmp(key, \"core.allow-ff\"))\n+\t\topts->allow_ff = git_config_bool_or_int(key, value, &error_flag);\n+\telse if (!strcmp(key, \"core.mainline\"))\n+\t\topts->mainline = git_config_int(key, value);\n+\telse if (!strcmp(key, \"core.strategy\"))\n+\t\tgit_config_string(&opts->strategy, key, value);\n+\telse if (!strcmp(key, \"core.strategy-option\")) {\n+\t\tALLOC_GROW(opts->xopts, opts->xopts_nr + 1, opts->xopts_alloc);\n+\t\topts->xopts[opts->xopts_nr++] = xstrdup(value);\n+\t} else\n+\t\treturn error(_(\"Invalid key: %s\"), key);\n+\n+\tif (!error_flag)\n+\t\treturn error(_(\"Invalid value for %s: %s\"), key, value);\n+\n+\treturn 0;\n+}\n+\n+static void MAYBE_UNUSED read_populate_opts(struct replay_opts **opts_ptr)\n+{\n+\tconst char *opts_file = git_path(SEQ_OPTS_FILE);\n+\n+\tif (!file_exists(opts_file))\n+\t\treturn;\n+\tif (git_config_from_file(populate_opts_cb, opts_file, *opts_ptr) < 0)\n+\t\tdie(_(\"Malformed options sheet: %s\"), opts_file);\n+}\n+\n static void walk_revs_populate_todo(struct commit_list **todo_list,\n \t\t\t\tstruct replay_opts *opts)\n {\n@@ -774,6 +818,39 @@ static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)\n \tstrbuf_release(&buf);\n }\n \n+static void save_opts(struct replay_opts *opts)\n+{\n+\tconst char *opts_file = git_path(SEQ_OPTS_FILE);\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint i;\n+\n+\tif (opts->no_commit)\n+\t\tgit_config_set_in_file(opts_file, \"core.no-commit\", \"true\");\n+\tif (opts->edit)\n+\t\tgit_config_set_in_file(opts_file, \"core.edit\", \"true\");\n+\tif (opts->signoff)\n+\t\tgit_config_set_in_file(opts_file, \"core.signoff\", \"true\");\n+\tif (opts->record_origin)\n+\t\tgit_config_set_in_file(opts_file, \"core.record-origin\", \"true\");\n+\tif (opts->allow_ff)\n+\t\tgit_config_set_in_file(opts_file, \"core.allow-ff\", \"true\");\n+\tif (opts->mainline) {\n+\t\tstrbuf_reset(&buf);\n+\t\tstrbuf_addf(&buf, \"%d\", opts->mainline);\n+\t\tgit_config_set_in_file(opts_file, \"core.mainline\", buf.buf);\n+\t}\n+\tif (opts->strategy)\n+\t\tgit_config_set_in_file(opts_file, \"core.strategy\", opts->strategy);\n+\tif (opts->xopts) {\n+\t\tfor (i = 0; i < opts->xopts_nr; i ++)\n+\t\t\tgit_config_set_multivar_in_file(opts_file,\n+\t\t\t\t\t\t\t\"core.strategy-option\",\n+\t\t\t\t\t\t\topts->xopts[i], \"^$\", 0);\n+\t}\n+\n+\tstrbuf_release(&buf);\n+}\n+\n static int pick_commits(struct replay_opts *opts)\n {\n \tstruct commit_list *todo_list = NULL;\n@@ -796,6 +873,7 @@ static int pick_commits(struct replay_opts *opts)\n \t\treturn error(_(\"Can't cherry-pick into empty head\"));\n \t} else\n \t\tsave_head(sha1_to_hex(sha1));\n+\tsave_opts(opts);\n \tsave_todo(todo_list, opts);\n \n \tfor (cur = todo_list; cur; cur = cur->next) {\ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nindex 64eaa20..79d868f 100755\n--- a/t/t3510-cherry-pick-sequence.sh\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -32,10 +32,36 @@ test_expect_success setup '\n \n test_expect_success 'cherry-pick persists data on failure' '\n \tpristine_detach initial &&\n-\ttest_must_fail git cherry-pick base..anotherpick &&\n+\ttest_must_fail git cherry-pick -s base..anotherpick &&\n \ttest_path_is_dir .git/sequencer &&\n \ttest_path_is_file .git/sequencer/head &&\n \ttest_path_is_file .git/sequencer/todo &&\n+\ttest_path_is_file .git/sequencer/opts &&\n+\trm -rf .git/sequencer\n+'\n+\n+test_expect_success 'cherry-pick persists opts correctly' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours base..anotherpick &&\n+\ttest_path_is_dir .git/sequencer &&\n+\ttest_path_is_file .git/sequencer/head &&\n+\ttest_path_is_file .git/sequencer/todo &&\n+\ttest_path_is_file .git/sequencer/opts &&\n+\techo \"true\" >expect\n+\tgit config --file=.git/sequencer/opts --get-all core.signoff >actual &&\n+\ttest_cmp expect actual &&\n+\techo \"1\" >expect\n+\tgit config --file=.git/sequencer/opts --get-all core.mainline >actual &&\n+\ttest_cmp expect actual &&\n+\techo \"recursive\" >expect\n+\tgit config --file=.git/sequencer/opts --get-all core.strategy >actual &&\n+\ttest_cmp expect actual &&\n+\tcat >expect <<-\\EOF\n+\tpatience\n+\tours\n+\tEOF\n+\tgit config --file=.git/sequencer/opts --get-all core.strategy-option >actual &&\n+\ttest_cmp expect actual &&\n \trm -rf .git/sequencer\n '\n \n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172112","messageId":"1311736755-24205-14-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 13/18] revert: Make pick_commits functionally act on a commit list","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:10Z","receivedAt":"2011-07-27T03:19:10Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Apart from its central objective of calling into the picking\nmechanism, pick_commits creates a sequencer directory, prepares a todo\nlist, and even acts upon the \"--reset\" subcommand.  This makes for a\nbad API since the central worry of callers is to figure out whether or\nnot any conflicts were encountered during the cherry picking.  The\ncurrent API is like:\n\nif (pick_commits(opts) < 0)\n   print \"Something failed, we're not sure what\"\n\nSo, change pick_commits so that it's only responsible for picking\ncommits in a loop and reporting any errors, leaving the rest to a new\nfunction called pick_revisions.  Consequently, the API of pick_commits\nbecomes much clearer:\n\nact_on_subcommand(opts->subcommand);\ntodo_list = prepare_todo_list();\nif (pick_commits(todo_list, opts) < 0)\n   print \"Error encountered while picking commits\"\n\nNow, callers can easily call-in to the cherry-picking machinery by\nconstructing an arbitrary todo list along with some options.\n\nHelped-by: Jonathan Nieder <jrnider@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c |   46 ++++++++++++++++++++++++++++++----------------\n 1 files changed, 30 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex b02d3d2..46b1371 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -851,11 +851,9 @@ static void save_opts(struct replay_opts *opts)\n \tstrbuf_release(&buf);\n }\n \n-static int pick_commits(struct replay_opts *opts)\n+static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)\n {\n-\tstruct commit_list *todo_list = NULL;\n \tstruct strbuf buf = STRBUF_INIT;\n-\tunsigned char sha1[20];\n \tstruct commit_list *cur;\n \tint res;\n \n@@ -865,17 +863,6 @@ static int pick_commits(struct replay_opts *opts)\n \t\t\t\topts->record_origin || opts->edit));\n \tread_and_refresh_cache(opts);\n \n-\twalk_revs_populate_todo(&todo_list, opts);\n-\tcreate_seq_dir();\n-\tif (get_sha1(\"HEAD\", sha1)) {\n-\t\tif (opts->action == REVERT)\n-\t\t\treturn error(_(\"Can't revert as initial commit\"));\n-\t\treturn error(_(\"Can't cherry-pick into empty head\"));\n-\t} else\n-\t\tsave_head(sha1_to_hex(sha1));\n-\tsave_opts(opts);\n-\tsave_todo(todo_list, opts);\n-\n \tfor (cur = todo_list; cur; cur = cur->next) {\n \t\tsave_todo(cur, opts);\n \t\tres = do_pick_commit(cur->item, opts);\n@@ -892,6 +879,27 @@ static int pick_commits(struct replay_opts *opts)\n \treturn 0;\n }\n \n+static int pick_revisions(struct replay_opts *opts)\n+{\n+\tstruct commit_list *todo_list = NULL;\n+\tunsigned char sha1[20];\n+\n+\tread_and_refresh_cache(opts);\n+\n+\twalk_revs_populate_todo(&todo_list, opts);\n+\tcreate_seq_dir();\n+\tif (get_sha1(\"HEAD\", sha1)) {\n+\t\tif (opts->action == REVERT)\n+\t\t\treturn error(_(\"Can't revert as initial commit\"));\n+\t\treturn error(_(\"Can't cherry-pick into empty head\"));\n+\t} else\n+\t\tsave_head(sha1_to_hex(sha1));\n+\tsave_opts(opts);\n+\tsave_todo(todo_list, opts);\n+\n+\treturn pick_commits(todo_list, opts);\n+}\n+\n int cmd_revert(int argc, const char **argv, const char *prefix)\n {\n \tint res;\n@@ -903,7 +911,13 @@ int cmd_revert(int argc, const char **argv, const char *prefix)\n \topts.action = REVERT;\n \tgit_config(git_default_config, NULL);\n \tparse_args(argc, argv, &opts);\n-\tres = pick_commits(&opts);\n+\n+\t/*\n+\t * Decide what to do depending on the arguments; a fresh\n+\t * cherry-pick should be handled differently from an existing\n+\t * one that is being continued\n+\t */\n+\tres = pick_revisions(&opts);\n \tif (res < 0)\n \t\tdie(_(\"revert failed\"));\n \treturn res;\n@@ -918,7 +932,7 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)\n \topts.action = CHERRY_PICK;\n \tgit_config(git_default_config, NULL);\n \tparse_args(argc, argv, &opts);\n-\tres = pick_commits(&opts);\n+\tres = pick_revisions(&opts);\n \tif (res < 0)\n \t\tdie(_(\"cherry-pick failed\"));\n \treturn res;\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172108","messageId":"1311736755-24205-15-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 14/18] revert: Introduce --reset to remove sequencer state","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:11Z","receivedAt":"2011-07-27T03:19:11Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"To explicitly remove the sequencer state for a fresh cherry-pick or\nrevert invocation, introduce a new subcommand called \"--reset\" to\nremove the sequencer state.\n\nTake the opportunity to publicly expose the sequencer paths, and a\ngeneric function called \"remove_sequencer_state\" that various git\nprograms can use to remove the sequencer state in a uniform manner;\n\"git reset\" uses it later in this series.  Introducing this public API\nis also in line with our long-term goal of eventually factoring out\nfunctions from revert.c into a generic commit sequencer.\n\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-cherry-pick.txt |    5 +++\n Documentation/git-revert.txt      |    5 +++\n Documentation/sequencer.txt       |    4 ++\n Makefile                          |    2 +\n builtin/revert.c                  |   65 +++++++++++++++++++++++++-----------\n sequencer.c                       |   19 +++++++++++\n sequencer.h                       |   20 +++++++++++\n t/t3510-cherry-pick-sequence.sh   |   16 ++++++++-\n 8 files changed, 114 insertions(+), 22 deletions(-)\n create mode 100644 Documentation/sequencer.txt\n create mode 100644 sequencer.c\n create mode 100644 sequencer.h\n\ndiff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt\nindex 9d8fe0d..138a292 100644\n--- a/Documentation/git-cherry-pick.txt\n+++ b/Documentation/git-cherry-pick.txt\n@@ -8,6 +8,7 @@ git-cherry-pick - Apply the changes introduced by some existing commits\n SYNOPSIS\n --------\n 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...\n+'git cherry-pick' --reset\n \n DESCRIPTION\n -----------\n@@ -109,6 +110,10 @@ effect to your index in a row.\n \tPass the merge strategy-specific option through to the\n \tmerge strategy.  See linkgit:git-merge[1] for details.\n \n+SEQUENCER SUBCOMMANDS\n+---------------------\n+include::sequencer.txt[]\n+\n EXAMPLES\n --------\n git cherry-pick master::\ndiff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt\nindex 6a21b37..b6789be 100644\n--- a/Documentation/git-revert.txt\n+++ b/Documentation/git-revert.txt\n@@ -8,6 +8,7 @@ git-revert - Revert some existing commits\n SYNOPSIS\n --------\n 'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>...\n+'git revert' --reset\n \n DESCRIPTION\n -----------\n@@ -90,6 +91,10 @@ effect to your index in a row.\n \tPass the merge strategy-specific option through to the\n \tmerge strategy.  See linkgit:git-merge[1] for details.\n \n+SEQUENCER SUBCOMMANDS\n+---------------------\n+include::sequencer.txt[]\n+\n EXAMPLES\n --------\n git revert HEAD~3::\ndiff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt\nnew file mode 100644\nindex 0000000..16ce88c\n--- /dev/null\n+++ b/Documentation/sequencer.txt\n@@ -0,0 +1,4 @@\n+--reset::\n+\tForget about the current operation in progress.  Can be used\n+\tto clear the sequencer state after a failed cherry-pick or\n+\trevert.\ndiff --git a/Makefile b/Makefile\nindex 4ed7996..afd7673 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -554,6 +554,7 @@ LIB_H += rerere.h\n LIB_H += resolve-undo.h\n LIB_H += revision.h\n LIB_H += run-command.h\n+LIB_H += sequencer.h\n LIB_H += sha1-array.h\n LIB_H += sha1-lookup.h\n LIB_H += sideband.h\n@@ -658,6 +659,7 @@ LIB_OBJS += revision.o\n LIB_OBJS += run-command.o\n LIB_OBJS += server-info.o\n LIB_OBJS += setup.o\n+LIB_OBJS += sequencer.o\n LIB_OBJS += sha1-array.o\n LIB_OBJS += sha1-lookup.o\n LIB_OBJS += sha1_file.o\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 46b1371..3c792fa 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -14,6 +14,7 @@\n #include \"merge-recursive.h\"\n #include \"refs.h\"\n #include \"dir.h\"\n+#include \"sequencer.h\"\n \n /*\n  * This implements the builtins revert and cherry-pick.\n@@ -28,18 +29,22 @@\n \n static const char * const revert_usage[] = {\n \t\"git revert [options] <commit-ish>\",\n+\t\"git revert <subcommand>\",\n \tNULL\n };\n \n static const char * const cherry_pick_usage[] = {\n \t\"git cherry-pick [options] <commit-ish>\",\n+\t\"git cherry-pick <subcommand>\",\n \tNULL\n };\n \n enum replay_action { REVERT, CHERRY_PICK };\n+enum replay_subcommand { REPLAY_NONE, REPLAY_RESET };\n \n struct replay_opts {\n \tenum replay_action action;\n+\tenum replay_subcommand subcommand;\n \n \t/* Boolean options */\n \tint edit;\n@@ -62,11 +67,6 @@ struct replay_opts {\n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n #define MAYBE_UNUSED __attribute__((__unused__))\n \n-#define SEQ_DIR         \"sequencer\"\n-#define SEQ_HEAD_FILE   \"sequencer/head\"\n-#define SEQ_TODO_FILE   \"sequencer/todo\"\n-#define SEQ_OPTS_FILE   \"sequencer/opts\"\n-\n static const char *action_name(const struct replay_opts *opts)\n {\n \treturn opts->action == REVERT ? \"revert\" : \"cherry-pick\";\n@@ -114,7 +114,9 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)\n \tconst char * const * usage_str = revert_or_cherry_pick_usage(opts);\n \tconst char *me = action_name(opts);\n \tint noop;\n+\tint reset = 0;\n \tstruct option options[] = {\n+\t\tOPT_BOOLEAN(0, \"reset\", &reset, \"forget the current operation\"),\n \t\tOPT_BOOLEAN('n', \"no-commit\", &opts->no_commit, \"don't automatically commit\"),\n \t\tOPT_BOOLEAN('e', \"edit\", &opts->edit, \"edit the commit message\"),\n \t\t{ OPTION_BOOLEAN, 'r', NULL, &noop, NULL, \"no-op (backward compatibility)\",\n@@ -143,7 +145,27 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)\n \topts->commit_argc = parse_options(argc, argv, NULL, options, usage_str,\n \t\t\t\t\tPARSE_OPT_KEEP_ARGV0 |\n \t\t\t\t\tPARSE_OPT_KEEP_UNKNOWN);\n-\tif (opts->commit_argc < 2)\n+\n+\t/* Set the subcommand */\n+\tif (reset)\n+\t\topts->subcommand = REPLAY_RESET;\n+\telse\n+\t\topts->subcommand = REPLAY_NONE;\n+\n+\t/* Check for incompatible command line arguments */\n+\tif (opts->subcommand == REPLAY_RESET) {\n+\t\tverify_opt_compatible(me, \"--reset\",\n+\t\t\t\t\"--no-commit\", opts->no_commit,\n+\t\t\t\t\"--signoff\", opts->signoff,\n+\t\t\t\t\"--mainline\", opts->mainline,\n+\t\t\t\t\"--strategy\", opts->strategy ? 1 : 0,\n+\t\t\t\t\"--strategy-option\", opts->xopts ? 1 : 0,\n+\t\t\t\t\"-x\", opts->record_origin,\n+\t\t\t\t\"--ff\", opts->allow_ff,\n+\t\t\t\tNULL);\n+\t}\n+\n+\telse if (opts->commit_argc < 2)\n \t\tusage_with_options(usage_str, options);\n \n \tif (opts->allow_ff)\n@@ -853,7 +875,6 @@ static void save_opts(struct replay_opts *opts)\n \n static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)\n {\n-\tstruct strbuf buf = STRBUF_INIT;\n \tstruct commit_list *cur;\n \tint res;\n \n@@ -874,8 +895,7 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)\n \t * Sequence of picks finished successfully; cleanup by\n \t * removing the .git/sequencer directory\n \t */\n-\tstrbuf_addf(&buf, \"%s\", git_path(SEQ_DIR));\n-\tremove_dir_recursively(&buf, 0);\n+\tremove_sequencer_state(1);\n \treturn 0;\n }\n \n@@ -886,17 +906,22 @@ static int pick_revisions(struct replay_opts *opts)\n \n \tread_and_refresh_cache(opts);\n \n-\twalk_revs_populate_todo(&todo_list, opts);\n-\tcreate_seq_dir();\n-\tif (get_sha1(\"HEAD\", sha1)) {\n-\t\tif (opts->action == REVERT)\n-\t\t\treturn error(_(\"Can't revert as initial commit\"));\n-\t\treturn error(_(\"Can't cherry-pick into empty head\"));\n-\t} else\n-\t\tsave_head(sha1_to_hex(sha1));\n-\tsave_opts(opts);\n-\tsave_todo(todo_list, opts);\n-\n+\tif (opts->subcommand == REPLAY_RESET) {\n+\t\tremove_sequencer_state(1);\n+\t\treturn 0;\n+\t} else {\n+\t\t/* Start a new cherry-pick/ revert sequence */\n+\t\twalk_revs_populate_todo(&todo_list, opts);\n+\t\tcreate_seq_dir();\n+\t\tif (get_sha1(\"HEAD\", sha1)) {\n+\t\t\tif (opts->action == REVERT)\n+\t\t\t\treturn error(_(\"Can't revert as initial commit\"));\n+\t\t\treturn error(_(\"Can't cherry-pick into empty head\"));\n+\t\t} else\n+\t\t\tsave_head(sha1_to_hex(sha1));\n+\t\tsave_opts(opts);\n+\t\tsave_todo(todo_list, opts);\n+\t}\n \treturn pick_commits(todo_list, opts);\n }\n \ndiff --git a/sequencer.c b/sequencer.c\nnew file mode 100644\nindex 0000000..bc2c046\n--- /dev/null\n+++ b/sequencer.c\n@@ -0,0 +1,19 @@\n+#include \"cache.h\"\n+#include \"sequencer.h\"\n+#include \"strbuf.h\"\n+#include \"dir.h\"\n+\n+void remove_sequencer_state(int aggressive)\n+{\n+\tstruct strbuf seq_dir = STRBUF_INIT;\n+\tstruct strbuf seq_old_dir = STRBUF_INIT;\n+\n+\tstrbuf_addf(&seq_dir, \"%s\", git_path(SEQ_DIR));\n+\tstrbuf_addf(&seq_old_dir, \"%s\", git_path(SEQ_OLD_DIR));\n+\tremove_dir_recursively(&seq_old_dir, 0);\n+\trename(git_path(SEQ_DIR), git_path(SEQ_OLD_DIR));\n+\tif (aggressive)\n+\t\tremove_dir_recursively(&seq_old_dir, 0);\n+\tstrbuf_release(&seq_dir);\n+\tstrbuf_release(&seq_old_dir);\n+}\ndiff --git a/sequencer.h b/sequencer.h\nnew file mode 100644\nindex 0000000..905d295\n--- /dev/null\n+++ b/sequencer.h\n@@ -0,0 +1,20 @@\n+#ifndef SEQUENCER_H\n+#define SEQUENCER_H\n+\n+#define SEQ_DIR\t\t\"sequencer\"\n+#define SEQ_OLD_DIR\t\"sequencer-old\"\n+#define SEQ_HEAD_FILE\t\"sequencer/head\"\n+#define SEQ_TODO_FILE\t\"sequencer/todo\"\n+#define SEQ_OPTS_FILE\t\"sequencer/opts\"\n+\n+/*\n+ * Removes SEQ_OLD_DIR and renames SEQ_DIR to SEQ_OLD_DIR, ignoring\n+ * any errors.  Intended to be used by 'git reset'.\n+ *\n+ * With the aggressive flag, it additionally removes SEQ_OLD_DIR,\n+ * ignoring any errors.  Inteded to be used by the sequencer's\n+ * '--reset' subcommand.\n+ */\n+void remove_sequencer_state(int aggressive);\n+\n+#endif\ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nindex 79d868f..aea4f6c 100755\n--- a/t/t3510-cherry-pick-sequence.sh\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -37,7 +37,7 @@ test_expect_success 'cherry-pick persists data on failure' '\n \ttest_path_is_file .git/sequencer/head &&\n \ttest_path_is_file .git/sequencer/todo &&\n \ttest_path_is_file .git/sequencer/opts &&\n-\trm -rf .git/sequencer\n+\tgit cherry-pick --reset\n '\n \n test_expect_success 'cherry-pick persists opts correctly' '\n@@ -62,7 +62,7 @@ test_expect_success 'cherry-pick persists opts correctly' '\n \tEOF\n \tgit config --file=.git/sequencer/opts --get-all core.strategy-option >actual &&\n \ttest_cmp expect actual &&\n-\trm -rf .git/sequencer\n+\tgit cherry-pick --reset\n '\n \n test_expect_success 'cherry-pick cleans up sequencer state upon success' '\n@@ -71,4 +71,16 @@ test_expect_success 'cherry-pick cleans up sequencer state upon success' '\n \ttest_path_is_missing .git/sequencer\n '\n \n+test_expect_success '--reset does not complain when no cherry-pick is in progress' '\n+\tpristine_detach initial &&\n+\tgit cherry-pick --reset\n+'\n+\n+test_expect_success '--reset cleans up sequencer state' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..picked &&\n+\tgit cherry-pick --reset &&\n+\ttest_path_is_missing .git/sequencer\n+'\n+\n test_done\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172110","messageId":"1311736755-24205-16-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 15/18] reset: Make reset remove the sequencer state","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:12Z","receivedAt":"2011-07-27T03:19:12Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Years of muscle memory have trained users to use \"git reset --hard\" to\nremove the branch state after any sort operation.  Make it also remove\nthe sequencer state to facilitate this established workflow:\n\n$ git cherry-pick foo..bar\n... conflict encountered ...\n$ git reset --hard # Oops, I didn't mean that\n$ git cherry-pick quux..bar\n... cherry-pick succeeded ...\n\nGuard against accidental removal of the sequencer state by providing\none level of \"undo\".  In the first \"reset\" invocation,\n\".git/sequencer\" is moved to \".git/sequencer-old\"; it is completely\nremoved only in the second invocation.\n\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n branch.c                 |    2 ++\n t/7106-reset-sequence.sh |   43 +++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 45 insertions(+), 0 deletions(-)\n create mode 100755 t/7106-reset-sequence.sh\n\ndiff --git a/branch.c b/branch.c\nindex c0c865a..d06aec4 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -3,6 +3,7 @@\n #include \"refs.h\"\n #include \"remote.h\"\n #include \"commit.h\"\n+#include \"sequencer.h\"\n \n struct tracking {\n \tstruct refspec spec;\n@@ -228,4 +229,5 @@ void remove_branch_state(void)\n \tunlink(git_path(\"MERGE_MSG\"));\n \tunlink(git_path(\"MERGE_MODE\"));\n \tunlink(git_path(\"SQUASH_MSG\"));\n+\tremove_sequencer_state(0);\n }\ndiff --git a/t/7106-reset-sequence.sh b/t/7106-reset-sequence.sh\nnew file mode 100755\nindex 0000000..c61c62d\n--- /dev/null\n+++ b/t/7106-reset-sequence.sh\n@@ -0,0 +1,43 @@\n+#!/bin/sh\n+\n+test_description='Test interaction of reset --hard with sequencer\n+\n+  + anotherpick: rewrites foo to d\n+  + picked: rewrites foo to c\n+  + unrelatedpick: rewrites unrelated to reallyunrelated\n+  + base: rewrites foo to b\n+  + initial: writes foo as a, unrelated as unrelated\n+'\n+\n+. ./test-lib.sh\n+\n+pristine_detach () {\n+\tgit checkout -f \"$1^0\" &&\n+\tgit read-tree -u --reset HEAD &&\n+\tgit clean -d -f -f -q -x\n+}\n+\n+test_expect_success setup '\n+\techo unrelated >unrelated &&\n+\tgit add unrelated &&\n+\ttest_commit initial foo a &&\n+\ttest_commit base foo b &&\n+\ttest_commit unrelatedpick unrelated reallyunrelated &&\n+\ttest_commit picked foo c &&\n+\ttest_commit anotherpick foo d &&\n+\tgit config advice.detachedhead false\n+\n+'\n+\n+test_expect_success 'reset --hard cleans up sequencer state, providing one-level undo' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..anotherpick &&\n+\ttest_path_is_dir .git/sequencer &&\n+\tgit reset --hard &&\n+\ttest_path_is_missing .git/sequencer &&\n+\ttest_path_is_dir .git/sequencer-old &&\n+\tgit reset --hard &&\n+\ttest_path_is_missing .git/sequencer-old\n+'\n+\n+test_done\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172114","messageId":"1311736755-24205-17-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:13Z","receivedAt":"2011-07-27T03:19:13Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"When cherry-pick or revert is called on a list of commits, and a\nconflict encountered somewhere in the middle, the data in\n\".git/sequencer\" is required to continue the operation.  However, when\na conflict is encountered in the very last commit, the user will have\nto \"continue\" after resolving the conflict and committing just so that\nthe sequencer state is removed.  This is how the current \"rebase -i\"\nscript works as well.\n\n$ git cherry-pick foo..bar\n... conflict encountered while picking \"bar\" ...\n$ echo \"resolved\" >problematicfile\n$ git add problematicfile\n$ git commit\n$ git cherry-pick --continue # This would be a noop\n\nChange this so that the sequencer state is cleared when a conflict is\nencountered in the last commit.  Incidentally, this patch makes sure\nthat some existing tests don't break when features like \"--reset\" and\n\"--continue\" are implemented later in the series.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c                |   12 +++++++++++-\n t/t3510-cherry-pick-sequence.sh |   24 ++++++++++++++++++++++++\n 2 files changed, 35 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 3c792fa..09d479b 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -887,8 +887,18 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)\n \tfor (cur = todo_list; cur; cur = cur->next) {\n \t\tsave_todo(cur, opts);\n \t\tres = do_pick_commit(cur->item, opts);\n-\t\tif (res)\n+\t\tif (res) {\n+\t\t\tif (!cur->next)\n+\t\t\t\t/*\n+\t\t\t\t * An error was encountered while\n+\t\t\t\t * picking the last commit; the\n+\t\t\t\t * sequencer state is useless now --\n+\t\t\t\t * the user simply needs to resolve\n+\t\t\t\t * the conflict and commit\n+\t\t\t\t */\n+\t\t\t\tremove_sequencer_state(0);\n \t\t\treturn res;\n+\t\t}\n \t}\n \n \t/*\ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nindex aea4f6c..428b5bf 100755\n--- a/t/t3510-cherry-pick-sequence.sh\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -83,4 +83,28 @@ test_expect_success '--reset cleans up sequencer state' '\n \ttest_path_is_missing .git/sequencer\n '\n \n+test_expect_success 'cherry-pick cleans up sequencer state when one commit is left' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..picked &&\n+\ttest_path_is_missing .git/sequencer &&\n+\techo \"resolved\" >foo &&\n+\tgit add foo &&\n+\tgit commit &&\n+\t{\n+\t\tgit rev-list HEAD |\n+\t\tgit diff-tree --root --stdin |\n+\t\tsed \"s/$_x40/OBJID/g\"\n+\t} >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tOBJID\n+\t:100644 100644 OBJID OBJID M\tfoo\n+\tOBJID\n+\t:100644 100644 OBJID OBJID M\tunrelated\n+\tOBJID\n+\t:000000 100644 OBJID OBJID A\tfoo\n+\t:000000 100644 OBJID OBJID A\tunrelated\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172115","messageId":"1311736755-24205-18-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 17/18] revert: Don't implictly stomp pending sequencer operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:14Z","receivedAt":"2011-07-27T03:19:14Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Protect the user from forgetting about a pending sequencer operation\nby immediately erroring out when an existing cherry-pick or revert\noperation is in progress like:\n\n$ git cherry-pick foo\n... conflict ...\n$ git cherry-pick moo\nerror: .git/sequencer already exists\nhint: A cherry-pick or revert is in progress\nhint: Use --reset to forget about it\nfatal: cherry-pick failed\n\nA naive version of this would break the following established ways of\nworking:\n\n$ git cherry-pick foo\n... conflict ...\n$ git reset --hard  # I actually meant \"moo\" when I said \"foo\"\n$ git cherry-pick moo\n\n$ git cherry-pick foo\n... conflict ...\n$ git commit # commit the resolution\n$ git cherry-pick moo # New operation\n\nHowever, the previous patches \"reset: Make reset remove the sequencer\nstate\" and \"revert: Remove sequencer state when no commits are\npending\" make sure that this does not happen.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n builtin/revert.c                |   21 +++++++++++++++++----\n t/t3510-cherry-pick-sequence.sh |   10 ++++++++++\n 2 files changed, 27 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 09d479b..11973e6 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -796,12 +796,15 @@ static void walk_revs_populate_todo(struct commit_list **todo_list,\n \t\tnext = commit_list_append(commit, next);\n }\n \n-static void create_seq_dir(void)\n+static int create_seq_dir(void)\n {\n \tconst char *seq_dir = git_path(SEQ_DIR);\n \n-\tif (!file_exists(seq_dir) && mkdir(seq_dir, 0777) < 0)\n+\tif (file_exists(seq_dir))\n+\t\treturn error(_(\"%s already exists.\"), seq_dir);\n+\telse if (mkdir(seq_dir, 0777) < 0)\n \t\tdie_errno(_(\"Could not create sequencer directory '%s'.\"), seq_dir);\n+\treturn 0;\n }\n \n static void save_head(const char *head)\n@@ -912,6 +915,7 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)\n static int pick_revisions(struct replay_opts *opts)\n {\n \tstruct commit_list *todo_list = NULL;\n+\tconst char *me = action_name(opts);\n \tunsigned char sha1[20];\n \n \tread_and_refresh_cache(opts);\n@@ -920,9 +924,18 @@ static int pick_revisions(struct replay_opts *opts)\n \t\tremove_sequencer_state(1);\n \t\treturn 0;\n \t} else {\n-\t\t/* Start a new cherry-pick/ revert sequence */\n+\t\t/*\n+\t\t * Start a new cherry-pick/ revert sequence; but\n+\t\t * first, make sure that an existing one isn't in\n+\t\t * progress\n+\t\t */\n+\n \t\twalk_revs_populate_todo(&todo_list, opts);\n-\t\tcreate_seq_dir();\n+\t\tif (create_seq_dir() < 0) {\n+\t\t\tadvise(_(\"A cherry-pick or revert is in progress.\"));\n+\t\t\tadvise(_(\"Use --reset to forget about it\"));\n+\t\t\treturn -1;\n+\t\t}\n \t\tif (get_sha1(\"HEAD\", sha1)) {\n \t\t\tif (opts->action == REVERT)\n \t\t\t\treturn error(_(\"Can't revert as initial commit\"));\ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nindex 428b5bf..44277f5 100755\n--- a/t/t3510-cherry-pick-sequence.sh\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -107,4 +107,14 @@ test_expect_success 'cherry-pick cleans up sequencer state when one commit is le\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..anotherpick &&\n+\ttest-chmtime -v +0 .git/sequencer >expect &&\n+\ttest_must_fail git cherry-pick unrelatedpick &&\n+\ttest-chmtime -v +0 .git/sequencer >actual &&\n+\ttest_cmp expect actual &&\n+\tgit cherry-pick --reset\n+'\n+\n test_done\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172116","messageId":"1311736755-24205-19-git-send-email-artagnon@gmail.com","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 18/18] revert: Introduce --continue to continue the operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T03:19:15Z","receivedAt":"2011-07-27T03:19:15Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Introduce a new \"git cherry-pick --continue\" command which uses the\ninformation in \".git/sequencer\" to continue a cherry-pick that stopped\nbecause of a conflict or other error.  It works by dropping the first\ninstruction from .git/sequencer/todo and performing the remaining\ncherry-picks listed there, with options (think \"-s\" and \"-X\") from the\ninitial command listed in \".git/sequencer/opts\".\n\nSo now you can do:\n\n$ git cherry-pick -Xpatience foo..bar\n... description conflict in commit moo ...\n$ git cherry-pick --continue\nerror: 'cherry-pick' is not possible because you have unmerged files.\nfatal: failed to resume cherry-pick\n$ echo resolved >conflictingfile\n$ git add conflictingfile && git commit\n$ git cherry-pick --continue; # resumes with the commit after \"moo\"\n\nDuring the \"git commit\" stage, CHERRY_PICK_HEAD will aid by providing\nthe commit message from the conflicting \"moo\" commit.  Note that the\ncherry-pick mechanism has no control at this stage, so the user is\nfree to violate anything that was specified during the first\ncherry-pick invocation.  For example, if \"-x\" was specified during the\nfirst cherry-pick invocation, the user is free to edit out the message\nduring commit time.  One glitch to note is that the \"--signoff\" option\nspecified at cherry-pick invocation time is not reflected in the\ncommit message provided by CHERRY_PICK_HEAD; the user must take care\nto add \"--signoff\" during the \"git commit\" invocation.\n\nHelped-by: Jonathan Nieder <jrnieder@gmail.com>\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-cherry-pick.txt |    1 +\n Documentation/git-revert.txt      |    1 +\n Documentation/sequencer.txt       |    5 ++\n builtin/revert.c                  |   67 ++++++++++++++++++++++---\n t/t3510-cherry-pick-sequence.sh   |   99 +++++++++++++++++++++++++++++++++++++\n 5 files changed, 165 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt\nindex 138a292..663186b 100644\n--- a/Documentation/git-cherry-pick.txt\n+++ b/Documentation/git-cherry-pick.txt\n@@ -9,6 +9,7 @@ SYNOPSIS\n --------\n 'git cherry-pick' [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...\n 'git cherry-pick' --reset\n+'git cherry-pick' --continue\n \n DESCRIPTION\n -----------\ndiff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt\nindex b6789be..923ae51 100644\n--- a/Documentation/git-revert.txt\n+++ b/Documentation/git-revert.txt\n@@ -9,6 +9,7 @@ SYNOPSIS\n --------\n 'git revert' [--edit | --no-edit] [-n] [-m parent-number] [-s] <commit>...\n 'git revert' --reset\n+'git revert' --continue\n \n DESCRIPTION\n -----------\ndiff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt\nindex 16ce88c..3e6df33 100644\n--- a/Documentation/sequencer.txt\n+++ b/Documentation/sequencer.txt\n@@ -2,3 +2,8 @@\n \tForget about the current operation in progress.  Can be used\n \tto clear the sequencer state after a failed cherry-pick or\n \trevert.\n+\n+--continue::\n+\tContinue the operation in progress using the information in\n+\t'.git/sequencer'.  Can be used to continue after resolving\n+\tconflicts in a failed cherry-pick or revert.\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 11973e6..4069abc 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -40,7 +40,7 @@ static const char * const cherry_pick_usage[] = {\n };\n \n enum replay_action { REVERT, CHERRY_PICK };\n-enum replay_subcommand { REPLAY_NONE, REPLAY_RESET };\n+enum replay_subcommand { REPLAY_NONE, REPLAY_RESET, REPLAY_CONTINUE };\n \n struct replay_opts {\n \tenum replay_action action;\n@@ -65,7 +65,6 @@ struct replay_opts {\n };\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n-#define MAYBE_UNUSED __attribute__((__unused__))\n \n static const char *action_name(const struct replay_opts *opts)\n {\n@@ -109,14 +108,40 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)\n \tva_end(ap);\n }\n \n+static void verify_opt_mutually_compatible(const char *me, ...)\n+{\n+       const char *opt1, *opt2;\n+       va_list ap;\n+       int set;\n+\n+       va_start(ap, me);\n+       while ((opt1 = va_arg(ap, const char *))) {\n+\t       set = va_arg(ap, int);\n+\t       if (set)\n+\t\t       break;\n+       }\n+       if (!opt1)\n+\t       goto ok;\n+       while ((opt2 = va_arg(ap, const char *))) {\n+\t       set = va_arg(ap, int);\n+\t       if (set)\n+\t\t       die(_(\"%s: %s cannot be used with %s\"),\n+\t\t\t       me, opt1, opt2);\n+       }\n+ok:\n+       va_end(ap);\n+}\n+\n static void parse_args(int argc, const char **argv, struct replay_opts *opts)\n {\n \tconst char * const * usage_str = revert_or_cherry_pick_usage(opts);\n \tconst char *me = action_name(opts);\n \tint noop;\n \tint reset = 0;\n+\tint contin = 0;\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN(0, \"reset\", &reset, \"forget the current operation\"),\n+\t\tOPT_BOOLEAN(0, \"continue\", &contin, \"continue the current operation\"),\n \t\tOPT_BOOLEAN('n', \"no-commit\", &opts->no_commit, \"don't automatically commit\"),\n \t\tOPT_BOOLEAN('e', \"edit\", &opts->edit, \"edit the commit message\"),\n \t\t{ OPTION_BOOLEAN, 'r', NULL, &noop, NULL, \"no-op (backward compatibility)\",\n@@ -146,15 +171,29 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)\n \t\t\t\t\tPARSE_OPT_KEEP_ARGV0 |\n \t\t\t\t\tPARSE_OPT_KEEP_UNKNOWN);\n \n+\t/* Check for incompatible subcommands */\n+\tverify_opt_mutually_compatible(me,\n+\t\t\t\t\"--reset\", reset,\n+\t\t\t\t\"--continue\", contin,\n+\t\t\t\tNULL);\n+\n \t/* Set the subcommand */\n \tif (reset)\n \t\topts->subcommand = REPLAY_RESET;\n+\telse if (contin)\n+\t\topts->subcommand = REPLAY_CONTINUE;\n \telse\n \t\topts->subcommand = REPLAY_NONE;\n \n \t/* Check for incompatible command line arguments */\n-\tif (opts->subcommand == REPLAY_RESET) {\n-\t\tverify_opt_compatible(me, \"--reset\",\n+\tif (opts->subcommand != REPLAY_NONE) {\n+\t\tchar *this_operation;\n+\t\tif (opts->subcommand == REPLAY_RESET)\n+\t\t\tthis_operation = \"--reset\";\n+\t\telse\n+\t\t\tthis_operation = \"--continue\";\n+\n+\t\tverify_opt_compatible(me, this_operation,\n \t\t\t\t\"--no-commit\", opts->no_commit,\n \t\t\t\t\"--signoff\", opts->signoff,\n \t\t\t\t\"--mainline\", opts->mainline,\n@@ -702,8 +741,8 @@ static struct commit *parse_insn_line(char *start, struct replay_opts *opts)\n \treturn commit;\n }\n \n-static void MAYBE_UNUSED read_populate_todo(struct commit_list **todo_list,\n-\t\t\t\t\tstruct replay_opts *opts)\n+static void read_populate_todo(struct commit_list **todo_list,\n+\t\t\tstruct replay_opts *opts)\n {\n \tconst char *todo_file = git_path(SEQ_TODO_FILE);\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -772,7 +811,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)\n \treturn 0;\n }\n \n-static void MAYBE_UNUSED read_populate_opts(struct replay_opts **opts_ptr)\n+static void read_populate_opts(struct replay_opts **opts_ptr)\n {\n \tconst char *opts_file = git_path(SEQ_OPTS_FILE);\n \n@@ -923,6 +962,15 @@ static int pick_revisions(struct replay_opts *opts)\n \tif (opts->subcommand == REPLAY_RESET) {\n \t\tremove_sequencer_state(1);\n \t\treturn 0;\n+\t} else if (opts->subcommand == REPLAY_CONTINUE) {\n+\t\tif (!file_exists(git_path(SEQ_TODO_FILE)))\n+\t\t\tgoto error;\n+\t\tread_populate_opts(&opts);\n+\t\tread_populate_todo(&todo_list, opts);\n+\n+\t\t/* Verify that the conflict has been resolved */\n+\t\tif (!index_differs_from(\"HEAD\", 0))\n+\t\t\ttodo_list = todo_list->next;\n \t} else {\n \t\t/*\n \t\t * Start a new cherry-pick/ revert sequence; but\n@@ -933,7 +981,8 @@ static int pick_revisions(struct replay_opts *opts)\n \t\twalk_revs_populate_todo(&todo_list, opts);\n \t\tif (create_seq_dir() < 0) {\n \t\t\tadvise(_(\"A cherry-pick or revert is in progress.\"));\n-\t\t\tadvise(_(\"Use --reset to forget about it\"));\n+\t\t\tadvise(_(\"Use --continue to continue the operation\"));\n+\t\t\tadvise(_(\"or --reset to forget about it\"));\n \t\t\treturn -1;\n \t\t}\n \t\tif (get_sha1(\"HEAD\", sha1)) {\n@@ -946,6 +995,8 @@ static int pick_revisions(struct replay_opts *opts)\n \t\tsave_todo(todo_list, opts);\n \t}\n \treturn pick_commits(todo_list, opts);\n+error:\n+\treturn error(_(\"No %s in progress\"), me);\n }\n \n int cmd_revert(int argc, const char **argv, const char *prefix)\ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nindex 44277f5..0267714 100755\n--- a/t/t3510-cherry-pick-sequence.sh\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -117,4 +117,103 @@ test_expect_success 'cherry-pick does not implicitly stomp an existing operation\n \tgit cherry-pick --reset\n '\n \n+test_expect_success '--continue complains when no cherry-pick is in progress' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick --continue\n+'\n+\n+test_expect_success '--continue complains when there are unresolved conflicts' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..picked &&\n+\ttest_must_fail git cherry-pick --continue &&\n+\tgit cherry-pick --reset\n+'\n+\n+test_expect_success '--continue continues after conflicts are resolved' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..anotherpick &&\n+\techo \"c\" >foo &&\n+\tgit add foo &&\n+\tgit commit &&\n+\tgit cherry-pick --continue &&\n+\ttest_path_is_missing .git/sequencer &&\n+\t{\n+\t\tgit rev-list HEAD |\n+\t\tgit diff-tree --root --stdin |\n+\t\tsed \"s/$_x40/OBJID/g\"\n+\t} >actual &&\n+\tcat >expect <<-\\EOF &&\n+\tOBJID\n+\t:100644 100644 OBJID OBJID M\tfoo\n+\tOBJID\n+\t:100644 100644 OBJID OBJID M\tfoo\n+\tOBJID\n+\t:100644 100644 OBJID OBJID M\tunrelated\n+\tOBJID\n+\t:000000 100644 OBJID OBJID A\tfoo\n+\t:000000 100644 OBJID OBJID A\tunrelated\n+\tEOF\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success '--continue respects opts' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick -x base..anotherpick &&\n+\techo \"c\" >foo &&\n+\tgit add foo &&\n+\tgit commit &&\n+\tgit cherry-pick --continue &&\n+\ttest_path_is_missing .git/sequencer &&\n+\tgit cat-file commit HEAD >anotherpick_msg &&\n+\tgit cat-file commit HEAD~1 >picked_msg &&\n+\tgit cat-file commit HEAD~2 >unrelatedpick_msg &&\n+\tgit cat-file commit HEAD~3 >initial_msg &&\n+\ttest_must_fail grep \"cherry picked from\" initial_msg &&\n+\tgrep \"cherry picked from\" unrelatedpick_msg &&\n+\tgrep \"cherry picked from\" picked_msg &&\n+\tgrep \"cherry picked from\" anotherpick_msg\n+'\n+\n+test_expect_success '--signoff is not automatically propogated to resolved conflict' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick --signoff base..anotherpick &&\n+\techo \"c\" >foo &&\n+\tgit add foo &&\n+\tgit commit &&\n+\tgit cherry-pick --continue &&\n+\ttest_path_is_missing .git/sequencer &&\n+\tgit cat-file commit HEAD >anotherpick_msg &&\n+\tgit cat-file commit HEAD~1 >picked_msg &&\n+\tgit cat-file commit HEAD~2 >unrelatedpick_msg &&\n+\tgit cat-file commit HEAD~3 >initial_msg &&\n+\ttest_must_fail grep \"Signed-off-by:\" initial_msg &&\n+\tgrep \"Signed-off-by:\" unrelatedpick_msg &&\n+\ttest_must_fail grep \"Signed-off-by:\" picked_msg &&\n+\tgrep \"Signed-off-by:\" anotherpick_msg\n+'\n+\n+test_expect_success 'malformed instruction sheet 1' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..picked &&\n+\techo \"resolved\" >foo &&\n+\tgit add foo &&\n+\tgit commit &&\n+\tsed \"s/pick /pick/\" .git/sequencer/todo >new_sheet\n+\tcp new_sheet .git/sequencer/todo\n+\ttest_must_fail git cherry-pick --continue &&\n+\tgit cherry-pick --reset\n+'\n+\n+test_expect_success 'malformed instruction sheet 2' '\n+\tpristine_detach initial &&\n+\ttest_must_fail git cherry-pick base..picked &&\n+\techo \"resolved\" >foo &&\n+\tgit add foo &&\n+\tgit commit &&\n+\tsed \"s/pick/revert/\" .git/sequencer/todo >new_sheet\n+\tcp new_sheet .git/sequencer/todo\n+\ttest_must_fail git cherry-pick --continue &&\n+\tgit cherry-pick --reset\n+'\n+\n test_done\n-- \n1.7.4.rc1.7.g2cf08.dirty\n"},{"id":"172117","messageId":"20110727033956.GA18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-3-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 02/18] config: Introduce functions to write non-standard file","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T03:39:56Z","receivedAt":"2011-07-27T03:39:56Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> --- a/config.c\n> +++ b/config.c\n> @@ -1387,6 +1387,24 @@ write_err_out:\n>  \n>  }\n>  \n> +int git_config_set_multivar(const char *key, const char *value,\n> +\t\t\tconst char *value_regex, int multi_replace)\n> +{\n> +\tconst char *config_filename;\n> +\tchar *filename_buf = NULL;\n> +\tint ret;\n> +\n> +\tif (config_exclusive_filename)\n> +\t\tconfig_filename = config_exclusive_filename;\n> +\telse\n> +\t\tconfig_filename = filename_buf = git_pathdup(\"config\");\n\nI know my sloppy example before is to blame for this, but the\n\"filename_buf\" variable name is needlessly verbose --- its semantics\nare just that it is something to be free()ed.  So if I were submitting\nthis I would use \"buf\".\n\nThe change description needs copyediting.\n\nAnyway, with or without the variable name change,\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThanks.  Patch 1 also looks sensible.\n"},{"id":"172118","messageId":"20110727041809.GB18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-4-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 03/18] revert: Simplify and inline add_message_to_msg","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T04:18:09Z","receivedAt":"2011-07-27T04:18:09Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> [Subject: [PATCH 03/18] revert: Simplify and inline add_message_to_msg]\n\nBefore, I wrote that it would be better to present this as a bugfix\nthan as a code reorganization, since the former is more likely to\naffect people upgrading or to be relevant if this later turns out to\nhave a regression and someone wonders why not to just revert it.  Was\nI wrong?\n\nTestcase below.  It makes a commit like this:\n\n\ttree f0db5ba931b3f121d2050e23ac3cd47ac2233306\n\tparent 43991719f0536a734e91e94f40361114477b3b5e\n\tauthor A U Thor <author@example.com> 1112912113 -0700\n\tcommitter C O Mitter <committer@example.com> 1112912113 -0700\n\nwith no blank line afterwards.  I think this is relevant and not a\n\"what if cosmic rays corrupt that pointer\" kind of thing because\npeople use non-git programs or libraries to write to git object stores\npretty often.  If this object were invalid, it would still not be a\ngood behavior to segfault (better to die() or give some\narbitrary-but-sane result).  Not sure whether the object should be\nconsidered invalid (e.g., \"git fsck\" accepts it).\n\nUnfortunately it fails for me even after the patch.  If the test looks\nreasonable to you, it could be worth adding marked with\n\"test_expect_failure\".\n\n t/t3501-revert-cherry-pick.sh |   25 +++++++++++++++++++++++++\n 1 files changed, 25 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh\nindex 595d2ff9..e46e7131 100755\n--- a/t/t3501-revert-cherry-pick.sh\n+++ b/t/t3501-revert-cherry-pick.sh\n@@ -12,6 +12,12 @@ test_description='test cherry-pick and revert with renames\n \n . ./test-lib.sh\n \n+remove_object() {\n+\tfile=$(echo \"$*\" | sed 's#..#.git/objects/&#') &&\n+\ttest -e \"$file\" &&\n+\trm -f \"$file\"\n+}\n+\n test_expect_success setup '\n \n \tfor l in a b c d e f g h i j k l m n o\n@@ -70,6 +76,25 @@ test_expect_success 'cherry-pick after renaming branch' '\n \n '\n \n+test_expect_success 'cherry-pick commit with no delimiter after header' '\n+\n+\tprintf \"%s\\n\" rename1 initial >expect &&\n+\n+\tgit cat-file commit rename1 >cmit &&\n+\tsed -e \"/^\\$/ Q\" <cmit >newcmit &&\n+\tobjname=$(git hash-object -t commit -w newcmit) &&\n+\ttest_when_finished \"remove_object $objname\" &&\n+\n+\tgit checkout initial &&\n+\tgit cherry-pick \"$objname\" &&\n+\n+\ttest_path_is_missing oops &&\n+\ttest_path_is_file spoo &&\n+\tgit log --format=%s >actual &&\n+\ttest_cmp expect actual\n+\n+'\n+\n test_expect_success 'revert after renaming branch' '\n \n \tgit checkout rename1 &&\n-- \n1.7.6\n"},{"id":"172119","messageId":"20110727043205.GC18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-5-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 04/18] revert: Don't check lone argument in get_encoding","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T04:32:05Z","receivedAt":"2011-07-27T04:32:05Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> The get_encoding function has only one callsite, and its caller makes\n> sure that a NULL argument isn't passed.  Remove a string marked for\n> translation that will never be shown by not unnecessarily\n> double-checking the argument.\n\nThe above just doesn't parse for me.  Isn't the truth something like:\n\n\"The only place get_encoding uses the 'commit' global is when writing\n an error message explaining that its text was NULL.  Since the only\n caller to get_encoding already ensures that the text is not NULL, we\n can remove this check, with two beneficial consequences:\n\n 1) the function doesn't use the \"commit\" global any more, bringing\n    us closer to removing that global altogether;\n 2) translators no longer need to localize this error message that\n    would never be shown.\n\n In a sense, after this patch there is an implied assert() replacing\n the \"if ... die()\" from before, since the function dereferences the\n pointer to commit object text and would segfault immediately if some\n future caller starts passing in NULL.\"\n\nPlease forgive the unclear phrasing; it is getting close to the time\nI should sleep.  Hopefully the intent is clear (i.e., please, imagine\nthat the reader does not already know what is going on and help him).\n\nSorry to nitpick so.  The patch proper is obviously good.\n"},{"id":"172120","messageId":"20110727043908.GD18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-7-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 06/18] revert: Propogate errors upwards from do_pick_commit","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T04:39:08Z","receivedAt":"2011-07-27T04:39:08Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Currently, revert_or_cherry_pick can fail in two ways.  If it\n> encounters a conflict, it returns a positive number indicating the\n> intended exit status for the git wrapper to pass on; for all other\n> errors, it calls die().  The latter behavior is inconsiderate towards\n> callers, as it denies them the opportunity to recover from errors and\n> do other things.\n\nPatch 5 is good.  I still find patch 6 unconvincing, since it makes\nthe behavior inconsistent (there are still many ways for\nrevert_or_cherry_pick to exit() or die()), does not help with anything\nthat comes later, and it is more of a burden than most of the rest of\nthe patches to review (since one has to look at context not contained\nin the diff to see if it is safe to continue running after an error\nthat previously would exit).  In the long term, I really do want this\nchange, though.  If you'd like, I can rebase to put it at the end of\nthe series (which shouldn't be hard).\n"},{"id":"172121","messageId":"20110727044341.GE18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-8-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 07/18] revert: Eliminate global \"commit\" variable","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T04:43:41Z","receivedAt":"2011-07-27T04:43:41Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Functions which act on commits currently rely on a file-scope static\n> variable to be set before they're called.  Consequently, the API and\n> corresponding callsites are ugly and unclear.  Remove this variable\n> and change their API to accept the commit to act on as additional\n> argument so that the callsites change from looking like\n>\n> commit = prepare_a_commit();\n> act_on_commit();\n>\n> to looking like\n>\n> commit = prepare_a_commit();\n> act_on_commit(commit);\n\nVery sane, and from a cursory look, it seems to be implemented well.\n\nTiny commit message nit: code, diagrams, and other text for which line\nbreaks are significant are more easily read when indented so the\nreader knows you are not just editing with a funny line width (e.g.,\ngrepping for : at ends of lines in the pager shown by \"git log\" should\nshow some examples).\n"},{"id":"172122","messageId":"20110727044651.GF18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-11-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 10/18] revert: Don't create invalid replay_opts in parse_args","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T04:46:51Z","receivedAt":"2011-07-27T04:46:51Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> To futureproof\n> the code and catch these errors in one place, make sure that an\n> invalid replay_opts structure is not created by parse_args in the\n> first place.\n\nFWIW, patches 8-10 all have reasonable goals and look like they\naddress them in a sane way from a quick glance.\n"},{"id":"172123","messageId":"20110727050220.GG18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-12-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 11/18] revert: Save data for continuing after conflict resolution","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T05:02:20Z","receivedAt":"2011-07-27T05:02:20Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> --- a/builtin/revert.c\n> +++ b/builtin/revert.c\n[...]\n> @@ -269,7 +275,7 @@ static void write_message(struct strbuf *msgbuf, const char *filename)\n>  \t\tdie_errno(_(\"Could not write to %s.\"), filename);\n>  \tstrbuf_release(msgbuf);\n>  \tif (commit_lock_file(&msg_file) < 0)\n> -\t\tdie(_(\"Error wrapping up %s\"), filename);\n> +\t\tdie(_(\"Error wrapping up %s.\"), filename);\n>  }\n>  \n>  static struct tree *empty_tree(void)\n\nSnuck in to the wrong patch, I guess?\n\n[...]\n> @@ -582,10 +588,199 @@ static struct commit *parse_insn_line(char *start, struct replay_opts *opts)\n[...]\n> +\tif (!prefixcmp(start, \"pick \")) {\n> +\t\taction = CHERRY_PICK;\n> +\t\tinsn_len = strlen(\"pick\");\n> +\t\tp = start + insn_len + 1;\n> +\t}\n> +\telse if (!prefixcmp(start, \"revert \")) {\n> +\t\taction = REVERT;\n> +\t\tinsn_len = strlen(\"revert\");\n> +\t\tp = start + insn_len + 1;\n> +\t}\n> +\telse\n> +\t\treturn NULL;\n> +\n\nStyle: git uses \"cuddled braces\".\n\n\tif (...) {\n\t\t...\n\t} else if (...) {\n\t\t...\n\t} ...\n\n[...]\n> +\tif ((get_sha1(sha1_abbrev, commit_sha1) < 0)\n> +\t\t|| !(commit = lookup_commit_reference(commit_sha1)))\n> +\t\treturn NULL;\n> +\n> +\treturn commit;\n\nWould be clearer to write:\n\n\tif (get_sha1(...))\n\t\treturn NULL;\n\n\treturn lookup_commit_reference(...);\n\n[...]\n> @@ -59,6 +60,11 @@ struct replay_opts {\n>  };\n>  \n>  #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n> +#define MAYBE_UNUSED __attribute__((__unused__))\n[...]\n> +}\n> +\n> +static void MAYBE_UNUSED read_populate_todo(struct commit_list **todo_list,\n> +\t\t\t\t\tstruct replay_opts *opts)\n\nThis MAYBE_UNUSED with no conditional involved feels ugly.  Why is it\nneeded?  Why not define read_populate_todo in the patch that first\nuses it, or barring that, tolerate a warning in this step within the\npatch series?\n\n[...]\n> +\t\tif (!(commit = parse_insn_line(p, opts)))\n> +\t\t\tgoto error;\n\nSee Documentation/CodingGuidelines: \"We try to avoid assignments\ninside if()\".\n\n> +static void walk_revs_populate_todo(struct commit_list **todo_list,\n> +\t\t\t\tstruct replay_opts *opts)\n>  {\n>  \tstruct rev_info revs;\n>  \tstruct commit *commit;\n> +\tstruct commit_list **next;\n> +\n> +\tprepare_revs(&revs, opts);\n> +\n> +\tnext = todo_list;\n> +\twhile ((commit = get_revision(&revs)))\n> +\t\tnext = commit_list_append(commit, next);\n> +}\n> +\n> +static void create_seq_dir(void)\n> +{\n> +\tconst char *seq_dir = git_path(SEQ_DIR);\n> +\n> +\tif (!file_exists(seq_dir) && mkdir(seq_dir, 0777) < 0)\n> +\t\tdie_errno(_(\"Could not create sequencer directory '%s'.\"), seq_dir);\n\nWhat happens if seq_dir exists and is a file?\n\n[...]\n> @@ -593,14 +788,29 @@ static int pick_commits(struct replay_opts *opts)\n[...]\n> +\tif (get_sha1(\"HEAD\", sha1)) {\n> +\t\tif (opts->action == REVERT)\n> +\t\t\treturn error(_(\"Can't revert as initial commit\"));\n> +\t\treturn error(_(\"Can't cherry-pick into empty head\"));\n> +\t} else\n> +\t\tsave_head(sha1_to_hex(sha1));\n\nClearer without the \"else\":\n\n\tif (get_sha1(...)) {\n\t\t...\n\t\treturn error(...);\n\t}\n\tsave_head(sha1);\n\n> +\tsave_todo(todo_list, opts);\n> +\n> +\tfor (cur = todo_list; cur; cur = cur->next) {\n> +\t\tsave_todo(cur, opts);\n> +\t\tres = do_pick_commit(cur->item, opts);\n>  \t\tif (res)\n>  \t\t\treturn res;\n>  \t}\n\nIsn't the save_todo() before the \"for\" loop redundant?\n>  \n> +\t/*\n> +\t * Sequence of picks finished successfully; cleanup by\n> +\t * removing the .git/sequencer directory\n> +\t */\n> +\tstrbuf_addf(&buf, \"%s\", git_path(SEQ_DIR));\n> +\tremove_dir_recursively(&buf, 0);\n\nWhat is the content of \"buf\" before?  If it's supposed to be empty,\nI'd suggest using \"strbuf_reset\" to make sure that remains so for\nthe reader's peace of mind.\n\nCiao,\nJonathan\n"},{"id":"172124","messageId":"20110727050515.GH18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-13-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 12/18] revert: Save command-line options for continuing operation","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T05:05:15Z","receivedAt":"2011-07-27T05:05:15Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> In the same spirit as \".git/sequencer/head\" and \".git/sequencer/todo\",\n> introduce \".git/sequencer/opts\" to persist the replay_opts structure\n> for continuing after a conflict resolution.  Use the gitconfig format\n> for this file so that it looks like:\n>\n> [core]\n> \tsignoff = true\n> \trecord-origin = true\n> \tmainline = 1\n> \tstrategy = recursive\n> \tstrategy-option = patience\n> \tstrategy-option = ours\n\nMaybe \"[options]\" instead of \"[core]\" would be more self-explanatory.\n\nIf this is meant to be closely analagous to the gitconfig file, then\nvariable names should not contain dashes.  It would be nice if some\nday the config parser could learn to treat dashes as insignificant,\njust like it already treats case distinctions as insignificant.\n"},{"id":"172125","messageId":"20110727051115.GI18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-15-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 14/18] revert: Introduce --reset to remove sequencer state","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T05:11:15Z","receivedAt":"2011-07-27T05:11:15Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> --- /dev/null\n> +++ b/Documentation/sequencer.txt\n> @@ -0,0 +1,4 @@\n> +--reset::\n> +\tForget about the current operation in progress.  Can be used\n> +\tto clear the sequencer state after a failed cherry-pick or\n> +\trevert.\n\nProbably worth mentioning that the index, HEAD, and worktree are left\nalone.\n\n> +++ b/builtin/revert.c\n[...]\n> @@ -886,17 +906,22 @@ static int pick_revisions(struct replay_opts *opts)\n[...]\n> +\tif (opts->subcommand == REPLAY_RESET) {\n> +\t\tremove_sequencer_state(1);\n> +\t\treturn 0;\n> +\t} else {\n> +\t\t/* Start a new cherry-pick/ revert sequence */\n\nCan un-indent by dropping the \"else\":\n\n\tif (opts->subcommand == REPLAY_RESET) {\n\t\t...\n\t\treturn 0;\n\t}\n\n\t/* Start a new cherry-pick or revert. */\n\t...\n\n[...]\n> --- a/t/t3510-cherry-pick-sequence.sh\n> +++ b/t/t3510-cherry-pick-sequence.sh\n> @@ -37,7 +37,7 @@ test_expect_success 'cherry-pick persists data on failure' '\n>  \ttest_path_is_file .git/sequencer/head &&\n>  \ttest_path_is_file .git/sequencer/todo &&\n>  \ttest_path_is_file .git/sequencer/opts &&\n> -\trm -rf .git/sequencer\n> +\tgit cherry-pick --reset\n>  '\n\nThis is not about this patch, but ideally the cleanup would come at\nthe beginning of the next test, so if one test fails it does not take\ndown all the tests that come after it.\n"},{"id":"172126","messageId":"20110727051612.GJ18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-16-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 15/18] reset: Make reset remove the sequencer state","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T05:16:12Z","receivedAt":"2011-07-27T05:16:12Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> [Subject: reset: Make reset remove the sequencer state]\n\nThe chosen strategy here also affects some other commands, most notably\n\"git checkout\".\n\n[...]\n> Guard against accidental removal of the sequencer state by providing\n> one level of \"undo\".  In the first \"reset\" invocation,\n> \".git/sequencer\" is moved to \".git/sequencer-old\"; it is completely\n> removed only in the second invocation.\n\nThat doesn't help much if the user doesn't know about it, I fear.\nAny ideas about how to address that?\n\nEspecially, if I run\n\n\tgit checkout HEAD^\n\nand get the response\n\n\tnote: removing pending cherry-pick state\n\thint: use \"git cherry-pick --revive\" to return to the cherry-pick\n\nthen I probably would not be too annoyed.  And on the other hand,\nif I run\n\n\tgit reset --hard\n\nto clear away an ugly conflict in the course of a long\ncherry-pick-many and suddenly \"git cherry-pick --continue\" stops\nworking without explanation and the only way I know to finish the job\nI was working on is to start over, that would be an unpleasant\nexperience.\n"},{"id":"172127","messageId":"20110727051755.GK18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-17-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T05:17:55Z","receivedAt":"2011-07-27T05:17:55Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Change this so that the sequencer state is cleared when a conflict is\n> encountered in the last commit.\n\nThis defeats the point of keeping a \".git/sequencer/head\" file.  Why\nnot remove the cherry-pick state when it is known no longer to be needed,\nnamely after the conflict resolution is commited?\n"},{"id":"172128","messageId":"20110727051947.GL18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-18-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 17/18] revert: Don't implictly stomp pending sequencer operation","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T05:19:47Z","receivedAt":"2011-07-27T05:19:47Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n[...]\n> +\t\tif (create_seq_dir() < 0) {\n> +\t\t\tadvise(_(\"A cherry-pick or revert is in progress.\"));\n> +\t\t\tadvise(_(\"Use --reset to forget about it\"));\n> +\t\t\treturn -1;\n> +\t\t}\n\nThe usual formula is:\n\n\terror(... description of error ...)\n\tif (advice_foo_bar [i.e., if the user is not tired of the advice already]) {\n\t\tadvise(... how to recover from error ...);\n\t\tadvise(... more lines ...);\n\t}\n"},{"id":"172129","messageId":"20110727052211.GM18470@elie","threadId":"27931","inReplyTo":"1311736755-24205-19-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 18/18] revert: Introduce --continue to continue the operation","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T05:22:11Z","receivedAt":"2011-07-27T05:22:11Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> during commit time.  One glitch to note is that the \"--signoff\" option\n> specified at cherry-pick invocation time is not reflected in the\n> commit message provided by CHERRY_PICK_HEAD; the user must take care\n> to add \"--signoff\" during the \"git commit\" invocation.\n\nDoes this reflect the previous discussion of whether this is a glitch\nor an intentional behavior?\n"},{"id":"172130","messageId":"20110727054256.GA28821@sigill.intra.peff.net","threadId":"27931","inReplyTo":"1311736755-24205-3-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 02/18] config: Introduce functions to write non-standard file","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-07-27T05:42:56Z","receivedAt":"2011-07-27T05:42:56Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jul 27, 2011 at 08:48:59AM +0530, Ramkumar Ramachandra wrote:\n\n> Introduce two new functions corresponding to \"git_config_set\" and\n> \"git_config_set_multivar\" to write a non-standard configuration file.\n> Expose thse new functions in cache.h for other git programs to use.\n\nThanks, this one looks much nicer to me (though I also agree with\nJonathan's style micronit).\n\n-Peff\n"},{"id":"172142","messageId":"CALkWK0=Bsq5RpmHLj9H0yVw-ALGWqOaOM2r9SyeBAPHqiwazew@mail.gmail.com","threadId":"27931","inReplyTo":"20110727044341.GE18470@elie","subject":"Re: [PATCH 07/18] revert: Eliminate global \"commit\" variable","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T08:59:49Z","receivedAt":"2011-07-27T08:59:49Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Tiny commit message nit: code, diagrams, and other text for which line\n> breaks are significant are more easily read when indented so the\n> reader knows you are not just editing with a funny line width (e.g.,\n> grepping for : at ends of lines in the pager shown by \"git log\" should\n> show some examples).\n\nFixed.  Thanks.\n\n-- Ram\n"},{"id":"172145","messageId":"CALkWK0nX5GsfGi9ifxkfvoZWxVzFKBs8X60Svda0rQWKzz0aww@mail.gmail.com","threadId":"27931","inReplyTo":"20110727052211.GM18470@elie","subject":"Re: [PATCH 18/18] revert: Introduce --continue to continue the operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T09:36:14Z","receivedAt":"2011-07-27T09:36:14Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Jonathan,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> during commit time.  One glitch to note is that the \"--signoff\" option\n>> specified at cherry-pick invocation time is not reflected in the\n>> commit message provided by CHERRY_PICK_HEAD; the user must take care\n>> to add \"--signoff\" during the \"git commit\" invocation.\n>\n> Does this reflect the previous discussion of whether this is a glitch\n> or an intentional behavior?\n\nThe previous discussion thread for your reference [1] -- I thought we\nagreed that it was a glitch.  Neither of us can find any traces of it\nbeing intentional, and the commit that introduced this option doesn't\nsay this: v1.5.6-rc0~83^2 (Allow cherry-pick (and revert) to add\nsignoff line, 2008-04-26).\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/176855/\n\n-- Ram\n"},{"id":"172146","messageId":"CALkWK0noPtLgr_t=DC_XFdLrWUNCLhUd00Mw1HbmWRJjeT4jew@mail.gmail.com","threadId":"27931","inReplyTo":"20110727051755.GK18470@elie","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T09:42:23Z","receivedAt":"2011-07-27T09:42:23Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> Change this so that the sequencer state is cleared when a conflict is\n>> encountered in the last commit.\n>\n> This defeats the point of keeping a \".git/sequencer/head\" file.  Why\n> not remove the cherry-pick state when it is known no longer to be needed,\n> namely after the conflict resolution is commited?\n\nSounds nice in theory, but how do we do it?  Remove the state at \"git\ncommit\" time?  I've already thought about the problem and presented my\narguments here [1].\n\n[1]: http://article.gmane.org/gmane.comp.version-control.git/177465\n\n-- Ram\n"},{"id":"172148","messageId":"CALkWK0=dFzVdqi3CJMBzkQO4WGe5-U1eQXwpVNZd33nLXD3+Qw@mail.gmail.com","threadId":"27931","inReplyTo":"20110727043908.GD18470@elie","subject":"Re: [PATCH 06/18] revert: Propogate errors upwards from do_pick_commit","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T09:47:03Z","receivedAt":"2011-07-27T09:47:03Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Jonathan,\n\nJonathan Nieder writes:\n> Patch 5 is good.  I still find patch 6 unconvincing, since it makes\n> the behavior inconsistent (there are still many ways for\n> revert_or_cherry_pick to exit() or die()), does not help with anything\n> that comes later, and it is more of a burden than most of the rest of\n> the patches to review (since one has to look at context not contained\n> in the diff to see if it is safe to continue running after an error\n> that previously would exit).\n\n:sigh:\n\n> In the long term, I really do want this\n> change, though.  If you'd like, I can rebase to put it at the end of\n> the series (which shouldn't be hard).\n\nThat would be awesome -- the rebase won't be easy at all though.\n\n-- Ram\n"},{"id":"172149","messageId":"CALkWK0=5drVxLe4SAVLem3cpWCB=Eg3dTFQGhLKFD+Z77RHohA@mail.gmail.com","threadId":"27931","inReplyTo":"20110727050515.GH18470@elie","subject":"Re: [PATCH 12/18] revert: Save command-line options for continuing operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T09:51:43Z","receivedAt":"2011-07-27T09:51:43Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> In the same spirit as \".git/sequencer/head\" and \".git/sequencer/todo\",\n>> introduce \".git/sequencer/opts\" to persist the replay_opts structure\n>> for continuing after a conflict resolution.  Use the gitconfig format\n>> for this file so that it looks like:\n>>\n>> [core]\n>>       signoff = true\n>>       record-origin = true\n>>       mainline = 1\n>>       strategy = recursive\n>>       strategy-option = patience\n>>       strategy-option = ours\n>\n> Maybe \"[options]\" instead of \"[core]\" would be more self-explanatory.\n\nFixed, thanks.\n\n> If this is meant to be closely analagous to the gitconfig file, then\n> variable names should not contain dashes.\n\nHuh?  Quoting Documentation/config.txt:\n\nAll the other lines (and the remainder of the line after the section\nheader) are recognized as setting variables, in the form\n'name = value'.  If there is no equal sign on the line, the entire line\nis taken as 'name' and the variable is recognized as boolean \"true\".\nThe variable names are case-insensitive and only alphanumeric\ncharacters and `-` are allowed.  There can be more than one value\nfor a given variable; we say then that variable is multivalued.\n\nBtw, the multi-value thing is something I wasn't aware about earlier;\nthat's what led to the \" | \" ugliness in my earlier patch.\n\n> It would be nice if some\n> day the config parser could learn to treat dashes as insignificant,\n> just like it already treats case distinctions as insignificant.\n\nIs the documentation out of date? I can't find any special handling\nfor `-` in the code either.  What are you talking about?\n\n-- Ram\n"},{"id":"172151","messageId":"CALkWK0mhAc4TtSzN5DW8OX91QBvosbbKsYfB5QPFy563qg7KRQ@mail.gmail.com","threadId":"27931","inReplyTo":"20110727051947.GL18470@elie","subject":"Re: [PATCH 17/18] revert: Don't implictly stomp pending sequencer operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T09:59:06Z","receivedAt":"2011-07-27T09:59:06Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n> [...]\n>> +             if (create_seq_dir() < 0) {\n>> +                     advise(_(\"A cherry-pick or revert is in progress.\"));\n>> +                     advise(_(\"Use --reset to forget about it\"));\n>> +                     return -1;\n>> +             }\n>\n> The usual formula is:\n>\n>        error(... description of error ...)\n>        if (advice_foo_bar [i.e., if the user is not tired of the advice already]) {\n>                advise(... how to recover from error ...);\n>                advise(... more lines ...);\n>        }\n\nI think you're trying to say two things here:\n1. Put the error() call in the caller.  Why is this a good idea?  The\nerror is very specific to the create_seq_dir functionality, and has\nnothing to do with the caller.  The advice on the other hand, can be\nquite caller-specific, which is why I put it in the caller in the\nfirst place.\n2. Guard the advice using a variable.  I have to invent a new\nconfiguration variable; can't that wait*?\n\nThanks.\n\n* Ideally, I'd do these things immediately if I didn't fear picking a\nstupid variable name, and implementing it in a daft manner the first\nfew times.  More delays will result in me doing less post midterm work\n(the more interesting bits).\n\n-- Ram\n"},{"id":"172153","messageId":"CALkWK0k7SvjJ8duNscnwjn4JOjSDqfHN1qH9rnoz5w8TjHgKgA@mail.gmail.com","threadId":"27931","inReplyTo":"20110727051115.GI18470@elie","subject":"Re: [PATCH 14/18] revert: Introduce --reset to remove sequencer state","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T10:12:24Z","receivedAt":"2011-07-27T10:12:24Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> --- /dev/null\n>> +++ b/Documentation/sequencer.txt\n>> @@ -0,0 +1,4 @@\n>> +--reset::\n>> +     Forget about the current operation in progress.  Can be used\n>> +     to clear the sequencer state after a failed cherry-pick or\n>> +     revert.\n>\n> Probably worth mentioning that the index, HEAD, and worktree are left\n> alone.\n\nFixed, thanks.\n\n>> +++ b/builtin/revert.c\n> [...]\n>> @@ -886,17 +906,22 @@ static int pick_revisions(struct replay_opts *opts)\n> [...]\n>> +     if (opts->subcommand == REPLAY_RESET) {\n>> +             remove_sequencer_state(1);\n>> +             return 0;\n>> +     } else {\n>> +             /* Start a new cherry-pick/ revert sequence */\n>\n> Can un-indent by dropping the \"else\":\n\nActually this was intentional; if we un-indent this now, there'll be a\ndiff indenting it when '--reset' and '--continue' are introduced which\nturns out to be especially ugly :)\n\n>> --- a/t/t3510-cherry-pick-sequence.sh\n>> +++ b/t/t3510-cherry-pick-sequence.sh\n>> @@ -37,7 +37,7 @@ test_expect_success 'cherry-pick persists data on failure' '\n>>       test_path_is_file .git/sequencer/head &&\n>>       test_path_is_file .git/sequencer/todo &&\n>>       test_path_is_file .git/sequencer/opts &&\n>> -     rm -rf .git/sequencer\n>> +     git cherry-pick --reset\n>>  '\n>\n> This is not about this patch, but ideally the cleanup would come at\n> the beginning of the next test, so if one test fails it does not take\n> down all the tests that come after it.\n\nGood point.  Fixed all, thanks.\n\n-- Ram\n"},{"id":"172155","messageId":"CALkWK0=uA1ZRsmiVwmx_3HXL-v+Bi-ONPEk5kMsh1RG0ZeVQJg@mail.gmail.com","threadId":"27931","inReplyTo":"20110727050220.GG18470@elie","subject":"Re: [PATCH 11/18] revert: Save data for continuing after conflict resolution","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T10:19:43Z","receivedAt":"2011-07-27T10:19:43Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> @@ -59,6 +60,11 @@ struct replay_opts {\n>>  };\n>>\n>>  #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n>> +#define MAYBE_UNUSED __attribute__((__unused__))\n> [...]\n>> +}\n>> +\n>> +static void MAYBE_UNUSED read_populate_todo(struct commit_list **todo_list,\n>> +                                     struct replay_opts *opts)\n>\n> This MAYBE_UNUSED with no conditional involved feels ugly.  Why is it\n> needed?  Why not define read_populate_todo in the patch that first\n> uses it, or barring that, tolerate a warning in this step within the\n> patch series?\n\nJunio complained about the warnings here [1], so I added MAYBE_UNUSED\nto suppress them temporarily.  Would you really like to see\nread_populate_todo and read_populate_opts being introduced MUCH later\nin the '--continue' patch?\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/176899\n\nThanks.\n\n-- Ram\n"},{"id":"172157","messageId":"20110727141006.GA24785@elie","threadId":"27931","inReplyTo":"CALkWK0noPtLgr_t=DC_XFdLrWUNCLhUd00Mw1HbmWRJjeT4jew@mail.gmail.com","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T14:10:06Z","receivedAt":"2011-07-27T14:10:06Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Sounds nice in theory, but how do we do it?  Remove the state at \"git\n> commit\" time?  I've already thought about the problem and presented my\n> arguments here [1].\n>\n> [1]: http://article.gmane.org/gmane.comp.version-control.git/177465\n\nFor reference:\n\n> My sequencer state was blown away just because of a stray\n> .git/remove-sequencer-state-after-commit from a previous operation!\n> This is horrible.  One can then argue: the file should only ever abort\n> *that* sequencer operation, and now we run into the problem of\n> assigning a UID for each sequencer operation.  Unnatural and ugly.\n> Conclusion: Making \"git commit\" remove the sequencer state is WRONG.\n\nThat is a compelling argument for not using a\n.git/remove-sequencer-state-after-commit file, but I don't see why one\nwould want such a file anyway.  Why can't \"git commit\" just call a\nfunction or use a command that examines .git/sequencer and looks at\nhow many commits are left to pick?\n\nLooking at it from the other side, \"My sequencer state was blown away\"\nis a bit dramatic.  If it's a problem in \"git commit\", why isn't it a\nproblem in \"git reset\", too?  If I just commited after resolving a\nconflict from applying the last commit in the series, what cherry-pick\nsequence state is going to be useful to me now?\n\nAnd how is this any less unnatural than making the 'abort cherry-pick'\nfacility unusable when and only when cherry-picking the last commit in\na sequence?  I don't get it.\n"},{"id":"172158","messageId":"20110727142116.GB24785@elie","threadId":"27931","inReplyTo":"CALkWK0=5drVxLe4SAVLem3cpWCB=Eg3dTFQGhLKFD+Z77RHohA@mail.gmail.com","subject":"Re: [PATCH 12/18] revert: Save command-line options for continuing operation","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T14:21:16Z","receivedAt":"2011-07-27T14:21:16Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n> Jonathan Nieder writes:\n\n>> It would be nice if some\n>> day the config parser could learn to treat dashes as insignificant,\n>> just like it already treats case distinctions as insignificant.\n>\n> Is the documentation out of date? I can't find any special handling\n> for `-` in the code either.  What are you talking about?\n\n\"It would be nice if some day the config parser could learn\" implies\n\"The config parser does not behave like this\", no?\n\nOne problem with dashes in names of real configuration variables is\nthat most git multi-word configuration variables are already named\nusing InsignificantBumpyCaps, which means the user does not have to\nremember where the word breaks are as language drifts (e.g., is it a\n\"file name\" or a \"filename\"?).  A convention of using dashes to\nseparate words would probably have been about as good, while\ninconsistently sometimes using dashes and sometimes not would be far\nworse.\n\nOf course, the .git/sequencer/args file is not gitconfig, and changes\nin its format are not as hard (since unlike for gitconfig, any\nbackward-compatibility synonyms probably do not need to be mentioned\nin documentation).  So I am not too worried and this was mostly an\naside.\n"},{"id":"172159","messageId":"20110727142815.GC24785@elie","threadId":"27931","inReplyTo":"CALkWK0k7SvjJ8duNscnwjn4JOjSDqfHN1qH9rnoz5w8TjHgKgA@mail.gmail.com","subject":"Re: [PATCH 14/18] revert: Introduce --reset to remove sequencer state","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T14:28:15Z","receivedAt":"2011-07-27T14:28:15Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n> Jonathan Nieder writes:\n>> Ramkumar Ramachandra wrote:\n\n>>> +     if (opts->subcommand == REPLAY_RESET) {\n>>> +             remove_sequencer_state(1);\n>>> +             return 0;\n>>> +     } else {\n>>> +             /* Start a new cherry-pick/ revert sequence */\n>>\n>> Can un-indent by dropping the \"else\":\n>\n> Actually this was intentional; if we un-indent this now, there'll be a\n> diff indenting it when '--reset' and '--continue' are introduced which\n> turns out to be especially ugly :)\n\nWhy couldn't it look like this at the end, for example?  (As always,\nthis is just an example; I am not saying \"please make it look like\nthis\".)\n\n\tif (opts->subcommand == REPLAY_RESET) {\n\t\tremove_sequencer_state(1);\n\t\treturn 0;\n\t}\n\n\tif (opts->subcommand == REPLAY_CONTINUE) {\n\t\t... prepare todo list for continue ...\n\t} else {\n\t\t... prepare todo list for a new cherry-pick ...\n\t}\n\tpick the chosen commits\n\n>> This is not about this patch, but ideally the cleanup would come at\n>> the beginning of the next test, so if one test fails it does not take\n>> down all the tests that come after it.\n>\n> Good point.  Fixed all, thanks.\n\nThanks for looking into it.\n"},{"id":"172160","messageId":"CALkWK0k8Lra7LkGJXoXScnGUjrag-xgNptaB_JCiAsgemTq0eQ@mail.gmail.com","threadId":"27931","inReplyTo":"20110727141006.GA24785@elie","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T14:30:06Z","receivedAt":"2011-07-27T14:30:06Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n> For reference:\n>\n>> My sequencer state was blown away just because of a stray\n>> .git/remove-sequencer-state-after-commit from a previous operation!\n>> This is horrible.  One can then argue: the file should only ever abort\n>> *that* sequencer operation, and now we run into the problem of\n>> assigning a UID for each sequencer operation.  Unnatural and ugly.\n>> Conclusion: Making \"git commit\" remove the sequencer state is WRONG.\n>\n> That is a compelling argument for not using a\n> .git/remove-sequencer-state-after-commit file, but I don't see why one\n> would want such a file anyway.  Why can't \"git commit\" just call a\n> function or use a command that examines .git/sequencer and looks at\n> how many commits are left to pick?\n\nHm, yes.  I'd definitely like to see a tighter coupling between \"git\ncommit\" and the sequencer as it becomes more generalized.\nWould you advocate this specific change now?  If so, I'll write an\nimplementation right away.  I was wondering whether you'd like such a\ntight coupling at this stage.\n\n> Looking at it from the other side, \"My sequencer state was blown away\"\n> is a bit dramatic.  If it's a problem in \"git commit\", why isn't it a\n> problem in \"git reset\", too?  If I just commited after resolving a\n> conflict from applying the last commit in the series, what cherry-pick\n> sequence state is going to be useful to me now?\n\nEr, no.  I said \"stray .git/remove-sequencer-state-after-commit\" --\nsomething that's left over from a long-forgotten sequencer operation*.\n Since \"git reset\" has already been established as a command that\nremoves the branch state, it's not as dramatic when \"git reset\"\nremoves the sequencer state; more so when \"git commit\" does it\naccidentally.\n\n> And how is this any less unnatural than making the 'abort cherry-pick'\n> facility unusable when and only when cherry-picking the last commit in\n> a sequence?  I don't get it.\n\nI don't want to make it unusable! I was asking for suggestions (like\n.git/SEQUENCER_HEAD).\n\n* I realize now that we can remove this file before starting a fresh\nsequencer operation.\n\nThanks.\n\n-- Ram\n"},{"id":"172161","messageId":"20110727143346.GD24785@elie","threadId":"27931","inReplyTo":"CALkWK0mhAc4TtSzN5DW8OX91QBvosbbKsYfB5QPFy563qg7KRQ@mail.gmail.com","subject":"Re: [PATCH 17/18] revert: Don't implictly stomp pending sequencer operation","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T14:33:46Z","receivedAt":"2011-07-27T14:33:46Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n> Jonathan Nieder writes:\n>> Ramkumar Ramachandra wrote:\n\n>>> +             if (create_seq_dir() < 0) {\n>>> +                     advise(_(\"A cherry-pick or revert is in progress.\"));\n>>> +                     advise(_(\"Use --reset to forget about it\"));\n>>> +                     return -1;\n>>> +             }\n>>\n>> The usual formula is:\n>>\n>>        error(... description of error ...)\n>>        if (advice_foo_bar [i.e., if the user is not tired of the advice already]) {\n>>                advise(... how to recover from error ...);\n>>                advise(... more lines ...);\n>>        }\n>\n> I think you're trying to say two things here:\n> 1. Put the error() call in the caller.\n\nNo, I didn't mean anything about the caller.  Here the error is \"a\ncherry-pick or revert is in progress\".  Before the advice mechanism\nexisted, such a line would have been written with error(), not note(),\nright?\n\n[...]\n> 2. Guard the advice using a variable.  I have to invent a new\n> configuration variable; can't that wait*?\n\nSure, if the advice is quiet (as it is in this case), I suppose there\nis no need to guard it until someone using it complains. :)\n\nI mentioned advice configuration to emphasize that output from running\ngit with all \"hint:\" lines stripped out is supposed to be just as\nsensible as with them, if I understand the purpose of the facility\ncorrectly.\n\nThanks for thinking it over.\n"},{"id":"172163","messageId":"CALkWK0nKMMjT1jg8zENmwbxvFU+5A+BFLVkoDRAOtURNcZ4H7A@mail.gmail.com","threadId":"27931","inReplyTo":"20110727142815.GC24785@elie","subject":"Re: [PATCH 14/18] revert: Introduce --reset to remove sequencer state","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T14:35:37Z","receivedAt":"2011-07-27T14:35:37Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> Jonathan Nieder writes:\n>>> Ramkumar Ramachandra wrote:\n>\n>>>> +     if (opts->subcommand == REPLAY_RESET) {\n>>>> +             remove_sequencer_state(1);\n>>>> +             return 0;\n>>>> +     } else {\n>>>> +             /* Start a new cherry-pick/ revert sequence */\n>>>\n>>> Can un-indent by dropping the \"else\":\n>>\n>> Actually this was intentional; if we un-indent this now, there'll be a\n>> diff indenting it when '--reset' and '--continue' are introduced which\n>> turns out to be especially ugly :)\n>\n> Why couldn't it look like this at the end, for example?  (As always,\n> this is just an example; I am not saying \"please make it look like\n> this\".)\n>\n>        if (opts->subcommand == REPLAY_RESET) {\n>                remove_sequencer_state(1);\n>                return 0;\n>        }\n>\n>        if (opts->subcommand == REPLAY_CONTINUE) {\n>                ... prepare todo list for continue ...\n>        } else {\n>                ... prepare todo list for a new cherry-pick ...\n>        }\n>        pick the chosen commits\n\nMainly style.  It looks a little unnatural: when more subcommands come\nup, I'd like a nice switch-case to dispatch :)\n\n-- Ram\n"},{"id":"172167","messageId":"20110727154258.GE24785@elie","threadId":"27931","inReplyTo":"CALkWK0nX5GsfGi9ifxkfvoZWxVzFKBs8X60Svda0rQWKzz0aww@mail.gmail.com","subject":"Re: [PATCH 18/18] revert: Introduce --continue to continue the operation","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T15:42:58Z","receivedAt":"2011-07-27T15:42:58Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n>> Ramkumar Ramachandra wrote:\n\n>>> during commit time.  One glitch to note is that the \"--signoff\" option\n>>> specified at cherry-pick invocation time is not reflected in the\n>>> commit message provided by CHERRY_PICK_HEAD\n[...]\n> The previous discussion thread for your reference [1] -- I thought we\n> agreed that it was a glitch.\n\nOk.  I thought it had come up before and that there was not wide\nagreement but probably I imagined it.  How about the patch below\n(needs commit message, tests)?\n\nAnyway, this is simple program logic that would be easy to change, not\na short-lived fault like the term \"glitch\" usually refers to.\n\n> Neither of us can find any traces of it\n> being intentional, and the commit that introduced this option doesn't\n> say this: v1.5.6-rc0~83^2 (Allow cherry-pick (and revert) to add\n> signoff line, 2008-04-26).\n\nAt the time, -x was not propagated to \"git commit\", either.  I guess\nit was not considered notable that -s worked the same way, as in\n\"Of course 'git commit -c $original_commit' is going to discard\nMERGE_MSG.\"\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/commit.c |   62 +---------------------------------------------\n builtin/revert.c |    5 ++-\n commit.c         |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n commit.h         |    3 ++\n 4 files changed, 79 insertions(+), 62 deletions(-)\n\ndiff --git c/builtin/commit.c i/builtin/commit.c\nindex e1af9b19..55ae8294 100644\n--- c/builtin/commit.c\n+++ i/builtin/commit.c\n@@ -524,8 +524,6 @@ static int is_a_merge(const unsigned char *sha1)\n \treturn !!(commit->parents && commit->parents->next);\n }\n \n-static const char sign_off_header[] = \"Signed-off-by: \";\n-\n static void determine_author_info(struct strbuf *author_ident)\n {\n \tchar *name, *email, *date;\n@@ -574,47 +572,6 @@ static void determine_author_info(struct strbuf *author_ident)\n \t\t\t\t\t      IDENT_ERROR_ON_NO_NAME));\n }\n \n-static int ends_rfc2822_footer(struct strbuf *sb)\n-{\n-\tint ch;\n-\tint hit = 0;\n-\tint i, j, k;\n-\tint len = sb->len;\n-\tint first = 1;\n-\tconst char *buf = sb->buf;\n-\n-\tfor (i = len - 1; i > 0; i--) {\n-\t\tif (hit && buf[i] == '\\n')\n-\t\t\tbreak;\n-\t\thit = (buf[i] == '\\n');\n-\t}\n-\n-\twhile (i < len - 1 && buf[i] == '\\n')\n-\t\ti++;\n-\n-\tfor (; i < len; i = k) {\n-\t\tfor (k = i; k < len && buf[k] != '\\n'; k++)\n-\t\t\t; /* do nothing */\n-\t\tk++;\n-\n-\t\tif ((buf[k] == ' ' || buf[k] == '\\t') && !first)\n-\t\t\tcontinue;\n-\n-\t\tfirst = 0;\n-\n-\t\tfor (j = 0; i + j < len; j++) {\n-\t\t\tch = buf[i + j];\n-\t\t\tif (ch == ':')\n-\t\t\t\tbreak;\n-\t\t\tif (isalnum(ch) ||\n-\t\t\t    (ch == '-'))\n-\t\t\t\tcontinue;\n-\t\t\treturn 0;\n-\t\t}\n-\t}\n-\treturn 1;\n-}\n-\n static char *cut_ident_timestamp_part(char *string)\n {\n \tchar *ket = strrchr(string, '>');\n@@ -734,23 +691,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \tif (clean_message_contents)\n \t\tstripspace(&sb, 0);\n \n-\tif (signoff) {\n-\t\tstruct strbuf sob = STRBUF_INIT;\n-\t\tint i;\n-\n-\t\tstrbuf_addstr(&sob, sign_off_header);\n-\t\tstrbuf_addstr(&sob, fmt_name(getenv(\"GIT_COMMITTER_NAME\"),\n-\t\t\t\t\t     getenv(\"GIT_COMMITTER_EMAIL\")));\n-\t\tstrbuf_addch(&sob, '\\n');\n-\t\tfor (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\\n'; i--)\n-\t\t\t; /* do nothing */\n-\t\tif (prefixcmp(sb.buf + i, sob.buf)) {\n-\t\t\tif (!i || !ends_rfc2822_footer(&sb))\n-\t\t\t\tstrbuf_addch(&sb, '\\n');\n-\t\t\tstrbuf_addbuf(&sb, &sob);\n-\t\t}\n-\t\tstrbuf_release(&sob);\n-\t}\n+\tif (signoff)\n+\t\tadd_signoff(&sb);\n \n \tif (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)\n \t\tdie_errno(_(\"could not write commit template\"));\ndiff --git c/builtin/revert.c i/builtin/revert.c\nindex 1f27c633..79ed9883 100644\n--- c/builtin/revert.c\n+++ i/builtin/revert.c\n@@ -369,8 +369,6 @@ static int run_git_commit(const char *defmsg)\n \n \targs[i++] = \"commit\";\n \targs[i++] = \"-n\";\n-\tif (signoff)\n-\t\targs[i++] = \"-s\";\n \tif (!edit) {\n \t\targs[i++] = \"-F\";\n \t\targs[i++] = defmsg;\n@@ -485,6 +483,9 @@ static int do_pick_commit(void)\n \t\t\twrite_cherry_pick_head();\n \t}\n \n+\tif (signoff)\n+\t\tadd_signoff(&msgbuf);\n+\n \tif (!strategy || !strcmp(strategy, \"recursive\") || action == REVERT) {\n \t\tres = do_recursive_merge(base, next, base_label, next_label,\n \t\t\t\t\t head, &msgbuf);\ndiff --git c/commit.c i/commit.c\nindex ac337c7d..5022db6e 100644\n--- c/commit.c\n+++ i/commit.c\n@@ -10,6 +10,7 @@\n int save_commit_buffer = 1;\n \n const char *commit_type = \"commit\";\n+const char sign_off_header[] = \"Signed-off-by: \";\n \n static struct commit *check_commit(struct object *obj,\n \t\t\t\t   const unsigned char *sha1,\n@@ -348,6 +349,76 @@ int find_commit_subject(const char *commit_buffer, const char **subject)\n \treturn eol - p;\n }\n \n+static int ends_rfc2822_footer(struct strbuf *sb)\n+{\n+\tint ch;\n+\tint hit = 0;\n+\tint i, j, k;\n+\tint len = sb->len;\n+\tint first = 1;\n+\tconst char *buf = sb->buf;\n+\n+\tfor (i = len - 1; i > 0; i--) {\n+\t\tif (hit && buf[i] == '\\n')\n+\t\t\tbreak;\n+\t\thit = (buf[i] == '\\n');\n+\t}\n+\n+\twhile (i < len - 1 && buf[i] == '\\n')\n+\t\ti++;\n+\n+\tfor (; i < len; i = k) {\n+\t\tfor (k = i; k < len && buf[k] != '\\n'; k++)\n+\t\t\t; /* do nothing */\n+\t\tk++;\n+\n+\t\tif ((buf[k] == ' ' || buf[k] == '\\t') && !first)\n+\t\t\tcontinue;\n+\n+\t\tfirst = 0;\n+\n+\t\tfor (j = 0; i + j < len; j++) {\n+\t\t\tch = buf[i + j];\n+\t\t\tif (ch == ':')\n+\t\t\t\tbreak;\n+\t\t\tif (isalnum(ch) ||\n+\t\t\t    (ch == '-'))\n+\t\t\t\tcontinue;\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\treturn 1;\n+}\n+\n+void add_signoff(struct strbuf *sb)\n+{\n+\tstruct strbuf sob = STRBUF_INIT;\n+\tconst char *p;\n+\n+\tstrbuf_addstr(&sob, sign_off_header);\n+\tstrbuf_addstr(&sob, fmt_name(getenv(\"GIT_COMMITTER_NAME\"),\n+\t\t\t\t     getenv(\"GIT_COMMITTER_EMAIL\")));\n+\tstrbuf_addch(&sob, '\\n');\n+\n+\t/* final line */\n+\tp = memrchr(sb->buf, '\\n', sb->len ? sb->len - 1 : 0);\n+\tif (!p)\n+\t\tp = sb->buf;\n+\telse\n+\t\tp++;\n+\n+\t/*\n+\t * If the line does not already contain our sign-off,\n+\t * add it.\n+\t */\n+\tif (prefixcmp(p, sob.buf)) {\n+\t\tif (p == sb->buf || !ends_rfc2822_footer(sb))\n+\t\t\tstrbuf_addch(sb, '\\n');\n+\t\tstrbuf_addbuf(sb, &sob);\n+\t}\n+\tstrbuf_release(&sob);\n+}\n+\n struct commit_list *commit_list_insert(struct commit *item, struct commit_list **list_p)\n {\n \tstruct commit_list *new_list = xmalloc(sizeof(struct commit_list));\ndiff --git c/commit.h i/commit.h\nindex a2d571b9..3d198afb 100644\n--- c/commit.h\n+++ i/commit.h\n@@ -23,6 +23,7 @@ struct commit {\n \n extern int save_commit_buffer;\n extern const char *commit_type;\n+extern const char sign_off_header[];\n \n /* While we can decorate any object with a name, it's only used for commits.. */\n extern struct decoration name_decoration;\n@@ -44,6 +45,8 @@ int parse_commit(struct commit *item);\n /* Find beginning and length of commit subject. */\n int find_commit_subject(const char *commit_buffer, const char **subject);\n \n+void add_signoff(struct strbuf *sb);\n+\n struct commit_list *commit_list_insert(struct commit *item,\n \t\t\t\t\tstruct commit_list **list);\n unsigned commit_list_count(const struct commit_list *l);\n-- \n"},{"id":"172168","messageId":"20110727154830.GA29924@elie","threadId":"27931","inReplyTo":"CALkWK0k8Lra7LkGJXoXScnGUjrag-xgNptaB_JCiAsgemTq0eQ@mail.gmail.com","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T15:48:30Z","receivedAt":"2011-07-27T15:48:30Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Hm, yes.  I'd definitely like to see a tighter coupling between \"git\n> commit\" and the sequencer as it becomes more generalized.\n> Would you advocate this specific change now?  If so, I'll write an\n> implementation right away.  I was wondering whether you'd like such a\n> tight coupling at this stage.\n\nIf \"tight coupling\" means \"builtin/commit.c calls a function declared\nin sequencer.h\", then yes, I think it should be fine.\n\nIn an ideal world it would also be exposed as plumbing (\"git\ncherry-pick --commited\"?), for use by hypothetical porcelains that\nwant to use \"git commit-tree\" et al to simulate what git commit does.\nBut probably best to wait on that part until someone needs it and can\ntell what a good interface would look like.\n\nThanks for explaining.\nJonathan\n"},{"id":"172169","messageId":"CALkWK0=y4qzEOgvn+1WfHuMeCmx8=bgbUKSPQiT7Eram9xiHug@mail.gmail.com","threadId":"27931","inReplyTo":"20110727142116.GB24785@elie","subject":"Re: [PATCH 12/18] revert: Save command-line options for continuing operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T15:49:50Z","receivedAt":"2011-07-27T15:49:50Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> Jonathan Nieder writes:\n>>> It would be nice if some\n>>> day the config parser could learn to treat dashes as insignificant,\n>>> just like it already treats case distinctions as insignificant.\n>>\n>> Is the documentation out of date? I can't find any special handling\n>> for `-` in the code either.  What are you talking about?\n>\n> \"It would be nice if some day the config parser could learn\" implies\n> \"The config parser does not behave like this\", no?\n\nAh, I misread that.  Sorry.\n\n> One problem with dashes in names of real configuration variables is\n> that most git multi-word configuration variables are already named\n> using InsignificantBumpyCaps, which means the user does not have to\n> remember where the word breaks are as language drifts (e.g., is it a\n> \"file name\" or a \"filename\"?).  A convention of using dashes to\n> separate words would probably have been about as good, while\n> inconsistently sometimes using dashes and sometimes not would be far\n> worse.\n\nHm, case insensitivity is nice, but ignoring dashes may not be such a\ngood idea.  I suppose we can use them where it's totally sensible and\nunambiguous like in this case (command-line options).\n\n> Of course, the .git/sequencer/args file is not gitconfig, and changes\n> in its format are not as hard (since unlike for gitconfig, any\n> backward-compatibility synonyms probably do not need to be mentioned\n> in documentation).  So I am not too worried and this was mostly an\n> aside.\n\nCool.  Thanks.\n\n-- Ram\n"},{"id":"172171","messageId":"CALkWK0n3UWYYw5Vyby_1hJfaTTWj1-EZdCv0F2siiB6vLCjK1g@mail.gmail.com","threadId":"27931","inReplyTo":"20110727154830.GA29924@elie","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T15:52:26Z","receivedAt":"2011-07-27T15:52:26Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> Hm, yes.  I'd definitely like to see a tighter coupling between \"git\n>> commit\" and the sequencer as it becomes more generalized.\n>> Would you advocate this specific change now?  If so, I'll write an\n>> implementation right away.  I was wondering whether you'd like such a\n>> tight coupling at this stage.\n>\n> If \"tight coupling\" means \"builtin/commit.c calls a function declared\n> in sequencer.h\", then yes, I think it should be fine.\n\nOkay.  I'll write something now.\n\n> In an ideal world it would also be exposed as plumbing (\"git\n> cherry-pick --commited\"?), for use by hypothetical porcelains that\n> want to use \"git commit-tree\" et al to simulate what git commit does.\n> But probably best to wait on that part until someone needs it and can\n> tell what a good interface would look like.\n\nRight.  We'll refrain from venturing into this part for now.\n\n-- Ram\n"},{"id":"172173","messageId":"CALkWK0k=+d+Nu5BgGhKdg3E13Db9kk-WYUY8dKQN_=QhLZi6GQ@mail.gmail.com","threadId":"27931","inReplyTo":"20110727154258.GE24785@elie","subject":"Re: [PATCH 18/18] revert: Introduce --continue to continue the operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T15:56:51Z","receivedAt":"2011-07-27T15:56:51Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Jonathan,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> The previous discussion thread for your reference [1] -- I thought we\n>> agreed that it was a glitch.\n>\n> Ok.  I thought it had come up before and that there was not wide\n> agreement but probably I imagined it.  How about the patch below\n> (needs commit message, tests)?\n\nLooks good!  Thanks for working on this.  We can include this near the\nbeginning of the series I think.\n\n-- Ram\n"},{"id":"172172","messageId":"20110727155654.GB29924@elie","threadId":"27931","inReplyTo":"CALkWK0=uA1ZRsmiVwmx_3HXL-v+Bi-ONPEk5kMsh1RG0ZeVQJg@mail.gmail.com","subject":"Re: [PATCH 11/18] revert: Save data for continuing after conflict resolution","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T15:56:54Z","receivedAt":"2011-07-27T15:56:54Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Junio complained about the warnings here [1], so I added MAYBE_UNUSED\n> to suppress them temporarily.  Would you really like to see\n> read_populate_todo and read_populate_opts being introduced MUCH later\n> in the '--continue' patch?\n>\n> [1]: http://thread.gmane.org/gmane.comp.version-control.git/176899\n\nHmm.  Yes, I suppose I would.\n\nBut as usual, what is relevant is not what I would like but what leads\nto clear, functional, and maintainable code.  It is from that point of\nview that the MAYBE_UNUSED is most problematic --- it suppresses a\nuseful and true hint when compiling that the codebase implements some\nfunctionality that has no user.  For example, the warning would be\ntriggered if the function gets renamed and added again and this old\nversion is forgotten.\n"},{"id":"172175","messageId":"CALkWK0=5feCeSnxVYb75vp=FNFd1i4-ujFB-2OHegCjN0hAeDw@mail.gmail.com","threadId":"27931","inReplyTo":"20110727143346.GD24785@elie","subject":"Re: [PATCH 17/18] revert: Don't implictly stomp pending sequencer operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T17:06:52Z","receivedAt":"2011-07-27T17:06:52Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Sure, if the advice is quiet (as it is in this case), I suppose there\n> is no need to guard it until someone using it complains. :)\n>\n> I mentioned advice configuration to emphasize that output from running\n> git with all \"hint:\" lines stripped out is supposed to be just as\n> sensible as with them, if I understand the purpose of the facility\n> correctly.\n\nAh, I hadn't thought about this so deeply.  Indeed a standalone\n\"error: Could not create sequencer directory '.git/sequencer'.\" does\nnot make much sense to the end user.  Now fix so that the caller\nreports the error.\nThanks.\n\n-- Ram\n"},{"id":"172177","messageId":"CALkWK0kFngXcyrKeB4HM5GdHebkuXOQ5jBETxWuxZCzYL94tqg@mail.gmail.com","threadId":"27931","inReplyTo":"20110727041809.GB18470@elie","subject":"Re: [PATCH 03/18] revert: Simplify and inline add_message_to_msg","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T17:26:04Z","receivedAt":"2011-07-27T17:26:04Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> [Subject: [PATCH 03/18] revert: Simplify and inline add_message_to_msg]\n>\n> Before, I wrote that it would be better to present this as a bugfix\n> than as a code reorganization, since the former is more likely to\n> affect people upgrading or to be relevant if this later turns out to\n> have a regression and someone wonders why not to just revert it.  Was\n> I wrong?\n\nI like the new commit message: I like to think that the old code was\nmisguided (intent: replace an empty commit message with the commit\nobject name), rather than buggy.  Since it's not possible to reproduce\nthe \"bug\" without constructing a commit object by hand, I don't know\nif we should classify it a \"bug\".\n\n> Testcase below.  It makes a commit like this:\n>\n>        tree f0db5ba931b3f121d2050e23ac3cd47ac2233306\n>        parent 43991719f0536a734e91e94f40361114477b3b5e\n>        author A U Thor <author@example.com> 1112912113 -0700\n>        committer C O Mitter <committer@example.com> 1112912113 -0700\n>\n> with no blank line afterwards.  I think this is relevant and not a\n> \"what if cosmic rays corrupt that pointer\" kind of thing because\n> people use non-git programs or libraries to write to git object stores\n> pretty often.  If this object were invalid, it would still not be a\n> good behavior to segfault (better to die() or give some\n> arbitrary-but-sane result).  Not sure whether the object should be\n> considered invalid (e.g., \"git fsck\" accepts it).\n\nThanks for writing the test.  However, there are probably several\nother edge cases in other parts of Git which accept slightly malformed\ntree/ blob objects.  Including this test is like telling developers:\n\"We have to be prepared for the worst kind of malformed objects in\nevery single Git application, not just objects created by us\", and\nthere is probably no end to this.  In my opinion, it is alright to\nSIGSEGV when a different but incorrect implementation of Git creates a\ncorrupt object store -- we should punish them for the mistake and set\nan example.  Instead of attacking the problem at this level, I think\nwe should get the lower layers like git-fsck to throw out malformed\nobjects.\n\n> Unfortunately it fails for me even after the patch.  If the test looks\n> reasonable to you, it could be worth adding marked with\n> \"test_expect_failure\".\n\nPerhaps as part of a different series which addresses the issue of\nmalformed objects in general.  I don't think it is relevant for this\nseries.  The \"other\" series I'm thinking about should contain:\n1. Documentation about the exact format of commit, tree, blob objects\nthe way the fast-import stream is documented.\n2. Fixes to the lower layers like git fsck/repack/gc: it should throw\nout objects that don't conform to the spec.\n3. A dedicated list of tests that intentionally create malformed\nobjects to verify the spec/ restraining code.\n\n(It should accommodate the major implementations and older versions of C Git)\n\nThanks.\n\n-- Ram\n"},{"id":"172178","messageId":"20110727174234.GC29924@elie","threadId":"27931","inReplyTo":"CALkWK0kFngXcyrKeB4HM5GdHebkuXOQ5jBETxWuxZCzYL94tqg@mail.gmail.com","subject":"Re: [PATCH 03/18] revert: Simplify and inline add_message_to_msg","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T17:42:34Z","receivedAt":"2011-07-27T17:42:34Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n>> Unfortunately it fails for me even after the patch.  If the test looks\n>> reasonable to you, it could be worth adding marked with\n>> \"test_expect_failure\".\n>\n> Perhaps as part of a different series which addresses the issue of\n> malformed objects in general.  I don't think it is relevant for this\n> series.  The \"other\" series I'm thinking about should contain:\n\nI don't want to work on that, personally...\n\nBut git already has a strategy for this.  It is quite simple: git can\ngive insane results when fed malformed objects, but it does not blindly\ntrust it and let scripts segfault, corrupt something else, escalate\nprivileges, etc.  Remember that malformed objects might even have been\nreceived from a remote machine with \"git fetch\" --- one simply cannot\ntrust objects beyond the assertion \"each object is a stream of bytes\".\n\nAnd on the other hand, git maintains sanity by _preserving_ invariants\nand providing good behavior when it deals with valid objects.  To a\nrough approximation, \"valid object\" is a synonym for \"git fsck accepts\nit\" (but that approximation is only modulo bugs --- git fsck has both\nfalse positives and false negatives).  It is perfectly legitimate for\ncommands to get confused and give a wrong result when working with\ninvalid objects, and this ability is a nice thing because it allows\nfor some optimizations.\n\nAs for the example at hand: perhaps we should teach \"git fsck\" to call\ncommit objects without a blank line after the header invalid.  After\nall, historical implementations of commands like \"git cherry-pick\" are\nnot ready to cope with them.  But that is no excuse to pretend they\ndon't exist!  While the best thing about your patch (and the most\ninvasive aspect of it) is that it improves that situation, for some\nreason you don't want to document this important aspect of its impact.\nIt leaves me completely puzzled.\n"},{"id":"172179","messageId":"CALkWK0npk7T+=XArxgft93XAifQvWLpjisg_XhhS-h6EmjS4Hg@mail.gmail.com","threadId":"27931","inReplyTo":"20110727174234.GC29924@elie","subject":"Re: [PATCH 03/18] revert: Simplify and inline add_message_to_msg","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T17:49:38Z","receivedAt":"2011-07-27T17:49:38Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> But git already has a strategy for this.  It is quite simple: git can\n> give insane results when fed malformed objects, but it does not blindly\n> trust it and let scripts segfault, corrupt something else, escalate\n> privileges, etc.  Remember that malformed objects might even have been\n> received from a remote machine with \"git fetch\" --- one simply cannot\n> trust objects beyond the assertion \"each object is a stream of bytes\".\n>\n> And on the other hand, git maintains sanity by _preserving_ invariants\n> and providing good behavior when it deals with valid objects.  To a\n> rough approximation, \"valid object\" is a synonym for \"git fsck accepts\n> it\" (but that approximation is only modulo bugs --- git fsck has both\n> false positives and false negatives).  It is perfectly legitimate for\n> commands to get confused and give a wrong result when working with\n> invalid objects, and this ability is a nice thing because it allows\n> for some optimizations.\n>\n> As for the example at hand: perhaps we should teach \"git fsck\" to call\n> commit objects without a blank line after the header invalid.  After\n> all, historical implementations of commands like \"git cherry-pick\" are\n> not ready to cope with them.  But that is no excuse to pretend they\n> don't exist!  While the best thing about your patch (and the most\n> invasive aspect of it) is that it improves that situation, for some\n> reason you don't want to document this important aspect of its impact.\n> It leaves me completely puzzled.\n\nAh, thanks for the elaborate explanation.  I'll document this aspect\nin my patch accordingly.\n\n-- Ram\n"},{"id":"172180","messageId":"20110727175131.GD29924@elie","threadId":"27931","inReplyTo":"CALkWK0npk7T+=XArxgft93XAifQvWLpjisg_XhhS-h6EmjS4Hg@mail.gmail.com","subject":"Re: [PATCH 03/18] revert: Simplify and inline add_message_to_msg","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-27T17:51:31Z","receivedAt":"2011-07-27T17:51:31Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Ah, thanks for the elaborate explanation.  I'll document this aspect\n> in my patch accordingly.\n\nThanks.  By the way, when an explanation is too elaborate, I'd be glad\nto hear feedback of the form \"You could have just said X\". :)\n"},{"id":"172181","messageId":"CALkWK0nL2Lv8xSBQ0uBM-kuiK-aWDCqPmYUuyn5B7rPZMj5iAQ@mail.gmail.com","threadId":"27931","inReplyTo":"20110727155654.GB29924@elie","subject":"Re: [PATCH 11/18] revert: Save data for continuing after conflict resolution","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-27T18:03:30Z","receivedAt":"2011-07-27T18:03:30Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Jonathan,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> Junio complained about the warnings here [1], so I added MAYBE_UNUSED\n>> to suppress them temporarily.  Would you really like to see\n>> read_populate_todo and read_populate_opts being introduced MUCH later\n>> in the '--continue' patch?\n>>\n>> [1]: http://thread.gmane.org/gmane.comp.version-control.git/176899\n>\n> Hmm.  Yes, I suppose I would.\n\nFixed.\n\n> But as usual, what is relevant is not what I would like but what leads\n> to clear, functional, and maintainable code.  It is from that point of\n> view that the MAYBE_UNUSED is most problematic --- it suppresses a\n> useful and true hint when compiling that the codebase implements some\n> functionality that has no user.  For example, the warning would be\n> triggered if the function gets renamed and added again and this old\n> version is forgotten.\n\nI actually think of it as a trade-off:\nOn one hand, I want to introduce functions to read and write\nconfiguration files in the same patch.\nOn the other hand, I want to introduce functions when they're actually used.\n\n-- Ram\n"},{"id":"172193","messageId":"7vy5zjmj61.fsf@alter.siamese.dyndns.org","threadId":"27931","inReplyTo":"1311736755-24205-12-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 11/18] revert: Save data for continuing after conflict resolution","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-27T22:51:34Z","receivedAt":"2011-07-27T22:51:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> +\tif (!prefixcmp(start, \"pick \")) {\n> +\t\taction = CHERRY_PICK;\n> +\t\tinsn_len = strlen(\"pick\");\n> +\t\tp = start + insn_len + 1;\n> +\t}\n> +\telse if (!prefixcmp(start, \"revert \")) {\n> +\t\taction = REVERT;\n> +\t\tinsn_len = strlen(\"revert\");\n> +\t\tp = start + insn_len + 1;\n> +\t}\n> +\telse\n> +\t\treturn NULL;\n\n(style)\n        if (...) {\n                ...\n        } else if (...) {\n                ...\n        } else {\n                ...\n        }\n"},{"id":"172194","messageId":"7vr55bmj5i.fsf@alter.siamese.dyndns.org","threadId":"27931","inReplyTo":"1311736755-24205-13-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 12/18] revert: Save command-line options for continuing operation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-27T22:51:53Z","receivedAt":"2011-07-27T22:51:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> +\tif (opts->xopts) {\n> +\t\tfor (i = 0; i < opts->xopts_nr; i ++)\n\n(style) s/i ++/i++/;\n"},{"id":"172195","messageId":"7vk4b3mj4r.fsf@alter.siamese.dyndns.org","threadId":"27931","inReplyTo":"1311736755-24205-19-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 18/18] revert: Introduce --continue to continue the operation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-27T22:52:20Z","receivedAt":"2011-07-27T22:52:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> @@ -109,14 +108,40 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)\n>  \tva_end(ap);\n>  }\n>  \n> +static void verify_opt_mutually_compatible(const char *me, ...)\n> +{\n> +       const char *opt1, *opt2;\n> +       va_list ap;\n> +       int set;\n> +\n> +       va_start(ap, me);\n> +       while ((opt1 = va_arg(ap, const char *))) {\n\n(style)\nMany lines indented with SP thoughout the patch.\n\n> +\t       set = va_arg(ap, int);\n> +\t       if (set)\n> +\t\t       break;\n> +       }\n> +       if (!opt1)\n"},{"id":"172196","messageId":"7vfwlrmisu.fsf@alter.siamese.dyndns.org","threadId":"27931","inReplyTo":"1311736755-24205-1-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 00/18] GSoC update: Sequencer for inclusion v3","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-27T22:59:29Z","receivedAt":"2011-07-27T22:59:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As I already said in the earlier \"What's cooking\" message, this series is\ngetting very closer, and the difference between the last round and this\nseems to be just \"allow explicit file to be given to the config writer\"\n(with help from Peff) which is very good, and \"remove 'Please, do this'\".\n\nBoth of which are good. I offhand do not recall if there were other issues\nraised in the previous review round.\n"},{"id":"172259","messageId":"CALkWK0nD+u21Bw9dLm_QJ1r6exw=QW2MYUUxbqrhYgqkp-bEFw@mail.gmail.com","threadId":"27931","inReplyTo":"7vk4b3mj4r.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 18/18] revert: Introduce --continue to continue the operation","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-28T13:16:07Z","receivedAt":"2011-07-28T13:16:07Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJunio C Hamano writes:\n> (style)\n> Many lines indented with SP thoughout the patch.\n\nFixed.  I really should use the kernel's checkpatch.pl before sending\nout patches.\n\n-- Ram\n"},{"id":"172263","messageId":"CALkWK0npPDuovUav-7+ea_P=xXuzBCFv3sgH2GgT4Xu4gORUUQ@mail.gmail.com","threadId":"27931","inReplyTo":"20110727054256.GA28821@sigill.intra.peff.net","subject":"Re: [PATCH 02/18] config: Introduce functions to write non-standard file","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-28T15:40:36Z","receivedAt":"2011-07-28T15:40:36Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJeff King writes:\n> Thanks, this one looks much nicer to me (though I also agree with\n> Jonathan's style micronit).\n\nFixed.  Thanks.\n\n-- Ram\n"},{"id":"172264","messageId":"CALkWK0=eh2MRqc1tW3rcPYAF3YLQnXanTZd9kzGdWBpJVcB01w@mail.gmail.com","threadId":"27931","inReplyTo":"20110727051612.GJ18470@elie","subject":"Re: [PATCH 15/18] reset: Make reset remove the sequencer state","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-28T15:42:33Z","receivedAt":"2011-07-28T15:42:33Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Jonathan,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> [Subject: reset: Make reset remove the sequencer state]\n>\n> The chosen strategy here also affects some other commands, most notably\n> \"git checkout\".\n\nI'm curious: doesn't this also apply to \"rebase -i\" and other scripts\nthat attempt to remove the branch state through \"reset\"?\n\n-- Ram\n"},{"id":"172265","messageId":"CALkWK0nmR1weev=agRiwWyBn=KSRQBg=FxDE0x0mrMNAs9Nq5g@mail.gmail.com","threadId":"27931","inReplyTo":"20110727043205.GC18470@elie","subject":"Re: [PATCH 04/18] revert: Don't check lone argument in get_encoding","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-28T15:43:21Z","receivedAt":"2011-07-28T15:43:21Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nJonathan Nieder writes:\n> The above just doesn't parse for me.  Isn't the truth something like:\n[...]\n\nFixed.  Thanks.\n\n-- Ram\n"},{"id":"172266","messageId":"20110728155929.GD22950@elie.dc0b.debconf.org","threadId":"27931","inReplyTo":"CALkWK0=eh2MRqc1tW3rcPYAF3YLQnXanTZd9kzGdWBpJVcB01w@mail.gmail.com","subject":"Re: [PATCH 15/18] reset: Make reset remove the sequencer state","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-28T15:59:29Z","receivedAt":"2011-07-28T15:59:29Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> I'm curious: doesn't this also apply to \"rebase -i\" and other scripts\n> that attempt to remove the branch state through \"reset\"?\n\nIt starts by detaching HEAD.  So, just like after a conflicted \"git\nmerge\", I think typically it will write\n\n\terror: you need to resolve your current index first\n\nBut that doesn't help when there are no unmerged index entries; good\ncatch.\n\nMaybe merge_working_tree() should ask the sequencer API whether there\nis something untoward in progress so \"git checkout\" without \"-f\" can\nknow to bail out.\n"},{"id":"172268","messageId":"CALkWK0mUGiCRQoW6UM+mF5tsn4DxRuaiXn0TS2CcEsR0OeusKg@mail.gmail.com","threadId":"27931","inReplyTo":"20110727154830.GA29924@elie","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-28T16:16:50Z","receivedAt":"2011-07-28T16:16:50Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nJonathan Nieder writes:\n> If \"tight coupling\" means \"builtin/commit.c calls a function declared\n> in sequencer.h\", then yes, I think it should be fine.\n\nMy bad. I'll first have to figure out a way to expose the todo parsing\nfunctions (and dependent functions) without touching much else.\nThis'll be a huge non-trivial patch, and my post midterm work has to\ninclude this anyway.  So I think it's better to leave it as-it-is for\nnow, and work on this coupling after this series is merged.\n\n-- Ram\n"},{"id":"172269","messageId":"CALkWK0kWtdHD2JF+sP8ox96jPncZagQpHzu3vvggyEFO3D2ryw@mail.gmail.com","threadId":"27931","inReplyTo":"7vfwlrmisu.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 00/18] GSoC update: Sequencer for inclusion v3","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-28T16:26:08Z","receivedAt":"2011-07-28T16:26:08Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Junio,\n\nJunio C Hamano writes:\n> As I already said in the earlier \"What's cooking\" message, this series is\n> getting very closer, and the difference between the last round and this\n> seems to be just \"allow explicit file to be given to the config writer\"\n> (with help from Peff) which is very good, and \"remove 'Please, do this'\".\n\nRight, and some minor commit message improvements.\n\n> Both of which are good. I offhand do not recall if there were other issues\n> raised in the previous review round.\n\nNo other issues were raised.  I've taken care of all the issues that\nwere raised by you and Jonathan this iteration too, with a couple of\nexceptions:\n1. \"revert: Remove sequencer state when no commits are pending\" isn't\nvery elegant.  I've decided that the right way to fix this is to\nincrease the coupling between \"git commit\" and the sequencer -- I\nthink this can wait.\n2. Jonathan suggested some improvements to \"git checkout\" behavior in\n\"reset: Make reset remove the sequencer state\".  I think this can wait\ntoo.\n\nDo you think the series is alright otherwise?  I'll post another\niteration of the sequencer momentarily.\n\nThanks.\n\n-- Ram\n"},{"id":"172270","messageId":"CALkWK0=d_JEy=24Sqg7Np12wsV754kbw_ejpFJsKttDc4t2g1Q@mail.gmail.com","threadId":"27931","inReplyTo":"CALkWK0kWtdHD2JF+sP8ox96jPncZagQpHzu3vvggyEFO3D2ryw@mail.gmail.com","subject":"Re: [PATCH 00/18] GSoC update: Sequencer for inclusion v3","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-28T16:32:01Z","receivedAt":"2011-07-28T16:32:01Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nRamkumar Ramachandra writes:\n> Do you think the series is alright otherwise?  I'll post another\n> iteration of the sequencer momentarily.\n\nUm, one more thing.  I've also decided to let Jonathan's commit\nsignoff-factoring patch [1] wait until the next series.\n\n[1]: https://github.com/artagnon/git/commit/0494a\n\nThanks.\n\n-- Ram\n"},{"id":"172271","messageId":"20110728163919.GA3155@elie.dc0b.debconf.org","threadId":"27931","inReplyTo":"CALkWK0=d_JEy=24Sqg7Np12wsV754kbw_ejpFJsKttDc4t2g1Q@mail.gmail.com","subject":"Re: [PATCH 00/18] GSoC update: Sequencer for inclusion v3","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-28T16:39:20Z","receivedAt":"2011-07-28T16:39:20Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Um, one more thing.  I've also decided to let Jonathan's commit\n> signoff-factoring patch [1] wait until the next series.\n>\n> [1]: https://github.com/artagnon/git/commit/0494a\n\nSure, I don't think it belongs in the series at all fwiw --- it can\nmigrate to master independently.  It was mostly a way to deter a\nnon-sequitor in the commit message. :)\n"},{"id":"172353","messageId":"20110729191654.GA2368@elie.dc0b.debconf.org","threadId":"27931","inReplyTo":"CALkWK0mUGiCRQoW6UM+mF5tsn4DxRuaiXn0TS2CcEsR0OeusKg@mail.gmail.com","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-29T19:16:55Z","receivedAt":"2011-07-29T19:16:55Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n> Jonathan Nieder writes:\n\n>> If \"tight coupling\" means \"builtin/commit.c calls a function declared\n>> in sequencer.h\", then yes, I think it should be fine.\n>\n> My bad. I'll first have to figure out a way to expose the todo parsing\n> functions (and dependent functions) without touching much else.\n\nThat's the wrong way to go.  One right way would be to expose a single\nfunction, representing \"here is what to do after successfully making a\ncommit\".  Think of it as an invisible built-in post-commit hook\n(see githooks(5)).\n"},{"id":"172355","messageId":"CALkWK0=qXBteRjj5vXDEWGVausQ3ssOvy4hyHHz84ORFzDaHaQ@mail.gmail.com","threadId":"27931","inReplyTo":"20110729191654.GA2368@elie.dc0b.debconf.org","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-29T19:56:38Z","receivedAt":"2011-07-29T19:56:38Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Jonathan,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> Jonathan Nieder writes:\n>>> If \"tight coupling\" means \"builtin/commit.c calls a function declared\n>>> in sequencer.h\", then yes, I think it should be fine.\n>>\n>> My bad. I'll first have to figure out a way to expose the todo parsing\n>> functions (and dependent functions) without touching much else.\n>\n> That's the wrong way to go.  One right way would be to expose a single\n> function, representing \"here is what to do after successfully making a\n> commit\".  Think of it as an invisible built-in post-commit hook\n> (see githooks(5)).\n\nOkay, I don't follow.  Wouldn't this function need to parse the todo\nsheet and figure out how many instructions are left?  For that, the\ntodo parsing functions can't be buried in builtin/revert.c, no?  Hence\nI said \"expose\" them -- or move them to sequencer.c.\n\n-- Ram\n"},{"id":"172384","messageId":"20110730131050.GA4848@elie","threadId":"27931","inReplyTo":"CALkWK0=qXBteRjj5vXDEWGVausQ3ssOvy4hyHHz84ORFzDaHaQ@mail.gmail.com","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-30T13:10:50Z","receivedAt":"2011-07-30T13:10:50Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Okay, I don't follow.  Wouldn't this function need to parse the todo\n> sheet and figure out how many instructions are left?  For that, the\n> todo parsing functions can't be buried in builtin/revert.c, no?  Hence\n> I said \"expose\" them -- or move them to sequencer.c.\n\nOh, that makes sense.  Sorry for the nonsense.  If I were in your\nshoes, I'd move everything below pick_commits to sequencer.c.\n"},{"id":"172395","messageId":"CALkWK0=9kwgtZB-BA12tOQrQXS8XRbhTg6K=Ak00o2nurX16Fg@mail.gmail.com","threadId":"27931","inReplyTo":"20110730131050.GA4848@elie","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-07-30T14:43:42Z","receivedAt":"2011-07-30T14:43:42Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi again,\n\nJonathan Nieder writes:\n> Ramkumar Ramachandra wrote:\n>> Okay, I don't follow.  Wouldn't this function need to parse the todo\n>> sheet and figure out how many instructions are left?  For that, the\n>> todo parsing functions can't be buried in builtin/revert.c, no?  Hence\n>> I said \"expose\" them -- or move them to sequencer.c.\n>\n> Oh, that makes sense.  Sorry for the nonsense.  If I were in your\n> shoes, I'd move everything below pick_commits to sequencer.c.\n\n:sigh: I thought it would be easy too, but there are several\ncomplications.  I'll spare you the gory details of the series I'm\npreparing and tell you the main problem briefly:\nNotice how the API of read_populate_todo includes opts.  Arguably, I\ndid this with good reason: I didn't want `git cherry-pick --continue`\nto continue a pending `git revert` operation and viceversa.  However,\nthis means that option parsing and todo parsing are slightly tangled\nup now -- I could always pass a dummy opts structure with only the\naction filled in, but I think that's inelegant.  So, I'm currently\nworking to untangle them by changing the way a todo list is\nrepresented -- just a commit_list won't do.  Once I change this, a\nsimple `git cherry-pick --continue` will be able to continue any\npending sequencer operation, but this is arguably a big patch.  Once\nthat is done, I can move dependent functions to sequencer.c and expose\nan API in sequencer.h for commit.c to use.  Also, I don't want to move\nthings to sequencer.c and change the API until I can imagine other git\nprograms working with the generalized sequencer; I hope it'll be clear\nafter a weekend of work.\n\nLong story short: I'd like it if we could bear with this slight\nannoyance (removal of sequencer state when one commit is pending) and\nget the series merged, so that I can work on a series to improve the\nexperience based on this series.\n\nThanks.\n\n-- Ram\n"},{"id":"172396","messageId":"20110730144817.GC7043@elie","threadId":"27931","inReplyTo":"CALkWK0=9kwgtZB-BA12tOQrQXS8XRbhTg6K=Ak00o2nurX16Fg@mail.gmail.com","subject":"Re: [PATCH 16/18] revert: Remove sequencer state when no commits are pending","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2011-07-30T14:48:17Z","receivedAt":"2011-07-30T14:48:17Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ramkumar Ramachandra wrote:\n\n> Long story short: I'd like it if we could bear with this slight\n> annoyance (removal of sequencer state when one commit is pending) and\n> get the series merged, so that I can work on a series to improve the\n> experience based on this series.\n\nThanks for explaining.  It's not a regression, so fwiw\nAcked-by: Jonathan Nieder <jrnieder@gmail.com>\n\nIf you are preparing a reroll, please do explain this a little in the\nlog message.\n"},{"id":"172440","messageId":"201107311431.26187.chriscool@tuxfamily.org","threadId":"27931","inReplyTo":"1311736755-24205-11-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 10/18] revert: Don't create invalid replay_opts in parse_args","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2011-07-31T12:31:25Z","receivedAt":"2011-07-31T12:31:25Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Wednesday 27 July 2011 05:19:07 Ramkumar Ramachandra wrote:\n>\n> +static void verify_opt_compatible(const char *me, const char *base_opt,\n> ...) +{\n> +\tconst char *this_opt;\n> +\tva_list ap;\n> +\tint set;\n> +\n> +\tva_start(ap, base_opt);\n> +\twhile ((this_opt = va_arg(ap, const char *))) {\n> +\t\tset = va_arg(ap, int);\n> +\t\tif (set)\n> +\t\t\tdie(_(\"%s: %s cannot be used with %s\"),\n> +\t\t\t\tme, this_opt, base_opt);\n> +\t}\n> +\tva_end(ap);\n> +}\n\nQuestion: returning in the middle of va_start() - va_end() may not be ok with \nsome compilers, but I don't know how safe it is to exit()?\n\n> +\t/*\n> +\t * Sequence of picks finished successfully; cleanup by\n> +\t * removing the .git/sequencer directory\n> +\t */\n> +\tstrbuf_reset(&buf);\n> +\tstrbuf_addf(&buf, \"%s\", git_path(SEQ_DIR));\n> +\tremove_dir_recursively(&buf, 0);\n>  \treturn 0;\n>  }\n\nThe \"strbuf_reset(&buf)\" is not needed. But a \"strbuf_release(&buf)\" could be \nadded before the return.\n\nThanks,\nChristian.\n"},{"id":"172548","messageId":"CALkWK0n2j_jFzkwF_QrVUejchnh=zEbUkGxH1_EyhjjZLj3FPA@mail.gmail.com","threadId":"27931","inReplyTo":"201107311431.26187.chriscool@tuxfamily.org","subject":"Re: [PATCH 10/18] revert: Don't create invalid replay_opts in parse_args","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-08-01T17:37:22Z","receivedAt":"2011-08-01T17:37:22Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Christian,\n\nChristian Couder writes:\n> On Wednesday 27 July 2011 05:19:07 Ramkumar Ramachandra wrote:\n>> +static void verify_opt_compatible(const char *me, const char *base_opt,\n>> ...) +{\n>> +     const char *this_opt;\n>> +     va_list ap;\n>> +     int set;\n>> +\n>> +     va_start(ap, base_opt);\n>> +     while ((this_opt = va_arg(ap, const char *))) {\n>> +             set = va_arg(ap, int);\n>> +             if (set)\n>> +                     die(_(\"%s: %s cannot be used with %s\"),\n>> +                             me, this_opt, base_opt);\n>> +     }\n>> +     va_end(ap);\n>> +}\n>\n> Question: returning in the middle of va_start() - va_end() may not be ok with\n> some compilers, but I don't know how safe it is to exit()?\n\nInteresting observation.  Even if it's not a problem, I suppose\nthere's no harm in putting a va_end before the die() statement --\nValgrind will probably be happier anyway.\n\n>> +     /*\n>> +      * Sequence of picks finished successfully; cleanup by\n>> +      * removing the .git/sequencer directory\n>> +      */\n>> +     strbuf_reset(&buf);\n>> +     strbuf_addf(&buf, \"%s\", git_path(SEQ_DIR));\n>> +     remove_dir_recursively(&buf, 0);\n>>       return 0;\n>>  }\n>\n> The \"strbuf_reset(&buf)\" is not needed. But a \"strbuf_release(&buf)\" could be\n> added before the return.\n\nRight, thanks.  Fixed.\n\n-- Ram\n"}]}