]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'rr/revert-cherry-pick'
authorJunio C Hamano <gitster@pobox.com>
Thu, 22 Dec 2011 23:30:22 +0000 (15:30 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Dec 2011 23:30:22 +0000 (15:30 -0800)
* rr/revert-cherry-pick:
  t3502, t3510: clarify cherry-pick -m failure
  t3510 (cherry-pick-sequencer): use exit status
  revert: simplify getting commit subject in format_todo()
  revert: tolerate extra spaces, tabs in insn sheet
  revert: make commit subjects in insn sheet optional
  revert: free msg in format_todo()

1  2 
builtin/revert.c

diff --combined builtin/revert.c
index fce3f929818d6a7faac5933d585a5217e564f6ba,0a86fecbd00d65f1f93c454b854ffd03c051ab3d..0d8020cf640e1abe6898308a1656446b327c83f4
@@@ -700,44 -700,47 +700,47 @@@ static int format_todo(struct strbuf *b
                struct replay_opts *opts)
  {
        struct commit_list *cur = NULL;
-       struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
        const char *sha1_abbrev = NULL;
        const char *action_str = opts->action == REVERT ? "revert" : "pick";
+       const char *subject;
+       int subject_len;
  
        for (cur = todo_list; cur; cur = cur->next) {
                sha1_abbrev = find_unique_abbrev(cur->item->object.sha1, DEFAULT_ABBREV);
-               if (get_message(cur->item, &msg))
-                       return error(_("Cannot get commit message for %s"), sha1_abbrev);
-               strbuf_addf(buf, "%s %s %s\n", action_str, sha1_abbrev, msg.subject);
+               subject_len = find_commit_subject(cur->item->buffer, &subject);
+               strbuf_addf(buf, "%s %s %.*s\n", action_str, sha1_abbrev,
+                       subject_len, subject);
        }
        return 0;
  }
  
- static struct commit *parse_insn_line(char *start, struct replay_opts *opts)
+ static struct commit *parse_insn_line(char *bol, char *eol, struct replay_opts *opts)
  {
        unsigned char commit_sha1[20];
-       char sha1_abbrev[40];
        enum replay_action action;
-       int insn_len = 0;
-       char *p, *q;
+       char *end_of_object_name;
+       int saved, status, padding;
  
-       if (!prefixcmp(start, "pick ")) {
+       if (!prefixcmp(bol, "pick")) {
                action = CHERRY_PICK;
-               insn_len = strlen("pick");
-               p = start + insn_len + 1;
-       } else if (!prefixcmp(start, "revert ")) {
+               bol += strlen("pick");
+       } else if (!prefixcmp(bol, "revert")) {
                action = REVERT;
-               insn_len = strlen("revert");
-               p = start + insn_len + 1;
+               bol += strlen("revert");
        } else
                return NULL;
  
-       q = strchr(p, ' ');
-       if (!q)
+       /* Eat up extra spaces/ tabs before object name */
+       padding = strspn(bol, " \t");
+       if (!padding)
                return NULL;
-       q++;
+       bol += padding;
  
-       strlcpy(sha1_abbrev, p, q - p);
+       end_of_object_name = bol + strcspn(bol, " \t\n");
+       saved = *end_of_object_name;
+       *end_of_object_name = '\0';
+       status = get_sha1(bol, commit_sha1);
+       *end_of_object_name = saved;
  
        /*
         * Verify that the action matches up with the one in
                return NULL;
        }
  
-       if (get_sha1(sha1_abbrev, commit_sha1) < 0)
+       if (status < 0)
                return NULL;
  
        return lookup_commit_reference(commit_sha1);
@@@ -765,13 -768,12 +768,12 @@@ static int parse_insn_buffer(char *buf
        int i;
  
        for (i = 1; *p; i++) {
-               commit = parse_insn_line(p, opts);
+               char *eol = strchrnul(p, '\n');
+               commit = parse_insn_line(p, eol, opts);
                if (!commit)
                        return error(_("Could not parse line %d."), i);
                next = commit_list_append(commit, next);
-               p = strchrnul(p, '\n');
-               if (*p)
-                       p++;
+               p = *eol ? eol + 1 : eol;
        }
        if (!*todo_list)
                return error(_("No commits parsed."));
@@@ -903,7 -905,7 +905,7 @@@ static int rollback_single_pick(void
        if (!file_exists(git_path("CHERRY_PICK_HEAD")) &&
            !file_exists(git_path("REVERT_HEAD")))
                return error(_("no cherry-pick or revert in progress"));
 -      if (!resolve_ref("HEAD", head_sha1, 0, NULL))
 +      if (read_ref_full("HEAD", head_sha1, 0, NULL))
                return error(_("cannot resolve HEAD"));
        if (is_null_sha1(head_sha1))
                return error(_("cannot abort from a branch yet to be born"));