Merge branch 'bm/interpret-trailers-cut-line-is-eom' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 5 Jun 2017 00:03:13 +0000 (09:03 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Jun 2017 00:03:13 +0000 (09:03 +0900)
"git interpret-trailers", when used as GIT_EDITOR for "git commit
-v", looked for and appended to a trailer block at the very end,
i.e. at the end of the "diff" output. The command has been
corrected to pay attention to the cut-mark line "commit -v" adds to
the buffer---the real trailer block should appear just before it.

* bm/interpret-trailers-cut-line-is-eom:
interpret-trailers: honor the cut line

1  2 
wt-status.c
diff --combined wt-status.c
index 117ac8cfb019d7d3b2c2bea056a30fe7ee5dcf4e,f4e198e5ca0c99ab97f859d99bda223ddaab68ba..068de38b510f51ba216e7bfdfe969c526064aef7
@@@ -896,17 -896,18 +896,18 @@@ conclude
        status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
  }
  
void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
size_t wt_status_locate_end(const char *s, size_t len)
  {
        const char *p;
        struct strbuf pattern = STRBUF_INIT;
  
        strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
-       if (starts_with(buf->buf, pattern.buf + 1))
-               strbuf_setlen(buf, 0);
-       else if ((p = strstr(buf->buf, pattern.buf)))
-               strbuf_setlen(buf, p - buf->buf + 1);
+       if (starts_with(s, pattern.buf + 1))
+               len = 0;
+       else if ((p = strstr(s, pattern.buf)))
+               len = p - s + 1;
        strbuf_release(&pattern);
+       return len;
  }
  
  void wt_status_add_cut_line(FILE *fp)
@@@ -1082,29 -1083,29 +1083,29 @@@ static char *read_line_from_git_path(co
  static int split_commit_in_progress(struct wt_status *s)
  {
        int split_in_progress = 0;
 -      char *head = read_line_from_git_path("HEAD");
 -      char *orig_head = read_line_from_git_path("ORIG_HEAD");
 -      char *rebase_amend = read_line_from_git_path("rebase-merge/amend");
 -      char *rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
 +      char *head, *orig_head, *rebase_amend, *rebase_orig_head;
  
 -      if (!head || !orig_head || !rebase_amend || !rebase_orig_head ||
 +      if ((!s->amend && !s->nowarn && !s->workdir_dirty) ||
            !s->branch || strcmp(s->branch, "HEAD"))
 -              return split_in_progress;
 +              return 0;
  
 -      if (!strcmp(rebase_amend, rebase_orig_head)) {
 -              if (strcmp(head, rebase_amend))
 -                      split_in_progress = 1;
 -      } else if (strcmp(orig_head, rebase_orig_head)) {
 -              split_in_progress = 1;
 -      }
 +      head = read_line_from_git_path("HEAD");
 +      orig_head = read_line_from_git_path("ORIG_HEAD");
 +      rebase_amend = read_line_from_git_path("rebase-merge/amend");
 +      rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
  
 -      if (!s->amend && !s->nowarn && !s->workdir_dirty)
 -              split_in_progress = 0;
 +      if (!head || !orig_head || !rebase_amend || !rebase_orig_head)
 +              ; /* fall through, no split in progress */
 +      else if (!strcmp(rebase_amend, rebase_orig_head))
 +              split_in_progress = !!strcmp(head, rebase_amend);
 +      else if (strcmp(orig_head, rebase_orig_head))
 +              split_in_progress = 1;
  
        free(head);
        free(orig_head);
        free(rebase_amend);
        free(rebase_orig_head);
 +
        return split_in_progress;
  }
  
@@@ -1168,7 -1169,6 +1169,7 @@@ static int read_rebase_todolist(const c
                abbrev_sha1_in_line(&line);
                string_list_append(lines, line.buf);
        }
 +      fclose(f);
        return 0;
  }