Code

Merge branch 'jk/format-patch-am'
authorJunio C Hamano <gitster@pobox.com>
Tue, 31 May 2011 19:19:11 +0000 (12:19 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 31 May 2011 19:19:11 +0000 (12:19 -0700)
* jk/format-patch-am:
  format-patch: preserve subject newlines with -k
  clean up calling conventions for pretty.c functions
  pretty: add pp_commit_easy function for simple callers
  mailinfo: always clean up rfc822 header folding
  t: test subject handling in format-patch / am pipeline

Conflicts:
builtin/branch.c
builtin/log.c
commit.h

1  2 
builtin/branch.c
builtin/checkout.c
builtin/log.c
builtin/merge.c
builtin/rev-list.c
builtin/shortlog.c
builtin/show-branch.c
commit.h
log-tree.c
pretty.c
revision.h

index 9cca1b9afc20caf6333d0269386249f41fa8746f,d8f15221ed5b7f67875549685fe7aad92909a1d4..d6ab93bfbb369965e76e384e6984a29b667cdfbe
@@@ -391,30 -390,6 +391,28 @@@ static int matches_merge_filter(struct 
        return (is_merged == (merge_filter == SHOW_MERGED));
  }
  
-               struct pretty_print_context ctx = {0};
-               pretty_print_commit(CMIT_FMT_ONELINE, commit,
-                                   &subject, &ctx);
 +static void add_verbose_info(struct strbuf *out, struct ref_item *item,
 +                           int verbose, int abbrev)
 +{
 +      struct strbuf subject = STRBUF_INIT, stat = STRBUF_INIT;
 +      const char *sub = " **** invalid ref ****";
 +      struct commit *commit = item->commit;
 +
 +      if (commit && !parse_commit(commit)) {
++              pp_commit_easy(CMIT_FMT_ONELINE, commit, &subject);
 +              sub = subject.buf;
 +      }
 +
 +      if (item->kind == REF_LOCAL_BRANCH)
 +              fill_tracking_info(&stat, item->name, verbose > 1);
 +
 +      strbuf_addf(out, " %s %s%s",
 +              find_unique_abbrev(item->commit->object.sha1, abbrev),
 +              stat.buf, sub);
 +      strbuf_release(&stat);
 +      strbuf_release(&subject);
 +}
 +
  static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
                           int abbrev, int current, char *prefix)
  {
index 4761769512a8abcdd5652a93d39be18154e251dd,c1759dc3a44c7d4df4d9bed03f22ab7be8df2257..28cdc51b85e7d433dca085c0080f964d19a391b4
@@@ -303,12 -297,11 +303,11 @@@ static void show_local_changes(struct o
        run_diff_index(&rev, 0);
  }
  
 -static void describe_detached_head(char *msg, struct commit *commit)
 +static void describe_detached_head(const char *msg, struct commit *commit)
  {
        struct strbuf sb = STRBUF_INIT;
-       struct pretty_print_context ctx = {0};
        parse_commit(commit);
-       pretty_print_commit(CMIT_FMT_ONELINE, commit, &sb, &ctx);
+       pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
        fprintf(stderr, "%s %s... %s\n", msg,
                find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
        strbuf_release(&sb);
@@@ -589,128 -577,6 +588,126 @@@ static void update_refs_for_switch(stru
                report_tracking(new);
  }
  
-       struct pretty_print_context ctx = { 0 };
 +struct rev_list_args {
 +      int argc;
 +      int alloc;
 +      const char **argv;
 +};
 +
 +static void add_one_rev_list_arg(struct rev_list_args *args, const char *s)
 +{
 +      ALLOC_GROW(args->argv, args->argc + 1, args->alloc);
 +      args->argv[args->argc++] = s;
 +}
 +
 +static int add_one_ref_to_rev_list_arg(const char *refname,
 +                                     const unsigned char *sha1,
 +                                     int flags,
 +                                     void *cb_data)
 +{
 +      add_one_rev_list_arg(cb_data, refname);
 +      return 0;
 +}
 +
 +static int clear_commit_marks_from_one_ref(const char *refname,
 +                                    const unsigned char *sha1,
 +                                    int flags,
 +                                    void *cb_data)
 +{
 +      struct commit *commit = lookup_commit_reference_gently(sha1, 1);
 +      if (commit)
 +              clear_commit_marks(commit, -1);
 +      return 0;
 +}
 +
 +static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
 +{
-       pretty_print_commit(CMIT_FMT_ONELINE, commit, sb, &ctx);
 +      parse_commit(commit);
 +      strbuf_addstr(sb, "  ");
 +      strbuf_addstr(sb,
 +              find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
 +      strbuf_addch(sb, ' ');
++      pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
 +      strbuf_addch(sb, '\n');
 +}
 +
 +#define ORPHAN_CUTOFF 4
 +static void suggest_reattach(struct commit *commit, struct rev_info *revs)
 +{
 +      struct commit *c, *last = NULL;
 +      struct strbuf sb = STRBUF_INIT;
 +      int lost = 0;
 +      while ((c = get_revision(revs)) != NULL) {
 +              if (lost < ORPHAN_CUTOFF)
 +                      describe_one_orphan(&sb, c);
 +              last = c;
 +              lost++;
 +      }
 +      if (ORPHAN_CUTOFF < lost) {
 +              int more = lost - ORPHAN_CUTOFF;
 +              if (more == 1)
 +                      describe_one_orphan(&sb, last);
 +              else
 +                      strbuf_addf(&sb, _(" ... and %d more.\n"), more);
 +      }
 +
 +      fprintf(stderr,
 +              Q_(
 +              /* The singular version */
 +              "Warning: you are leaving %d commit behind, "
 +              "not connected to\n"
 +              "any of your branches:\n\n"
 +              "%s\n"
 +              "If you want to keep it by creating a new branch, "
 +              "this may be a good time\nto do so with:\n\n"
 +              " git branch new_branch_name %s\n\n",
 +              /* The plural version */
 +              "Warning: you are leaving %d commits behind, "
 +              "not connected to\n"
 +              "any of your branches:\n\n"
 +              "%s\n"
 +              "If you want to keep them by creating a new branch, "
 +              "this may be a good time\nto do so with:\n\n"
 +              " git branch new_branch_name %s\n\n",
 +              /* Give ngettext() the count */
 +              lost),
 +              lost,
 +              sb.buf,
 +              sha1_to_hex(commit->object.sha1));
 +      strbuf_release(&sb);
 +}
 +
 +/*
 + * We are about to leave commit that was at the tip of a detached
 + * HEAD.  If it is not reachable from any ref, this is the last chance
 + * for the user to do so without resorting to reflog.
 + */
 +static void orphaned_commit_warning(struct commit *commit)
 +{
 +      struct rev_list_args args = { 0, 0, NULL };
 +      struct rev_info revs;
 +
 +      add_one_rev_list_arg(&args, "(internal)");
 +      add_one_rev_list_arg(&args, sha1_to_hex(commit->object.sha1));
 +      add_one_rev_list_arg(&args, "--not");
 +      for_each_ref(add_one_ref_to_rev_list_arg, &args);
 +      add_one_rev_list_arg(&args, "--");
 +      add_one_rev_list_arg(&args, NULL);
 +
 +      init_revisions(&revs, NULL);
 +      if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1)
 +              die(_("internal error: only -- alone should have been left"));
 +      if (prepare_revision_walk(&revs))
 +              die(_("internal error in revision walk"));
 +      if (!(commit->object.flags & UNINTERESTING))
 +              suggest_reattach(commit, &revs);
 +      else
 +              describe_detached_head(_("Previous HEAD position was"), commit);
 +
 +      clear_commit_marks(commit, -1);
 +      for_each_ref(clear_commit_marks_from_one_ref, NULL);
 +}
 +
  static int switch_branches(struct checkout_opts *opts, struct branch_info *new)
  {
        int ret = 0;
diff --cc builtin/log.c
index 224b16792042c5633a2f1820082b3ca18d81e5fd,0e46e5ae95a6ebb33d98cfde7505b50ed1a51c4d..5c2af590047d92554d87acc5d7113a2f1f730a96
@@@ -758,14 -714,11 +760,12 @@@ static void print_signature(void
  static void make_cover_letter(struct rev_info *rev, int use_stdout,
                              int numbered, int numbered_files,
                              struct commit *origin,
 -                            int nr, struct commit **list, struct commit *head)
 +                            int nr, struct commit **list, struct commit *head,
 +                            int quiet)
  {
        const char *committer;
-       const char *subject_start = NULL;
        const char *body = "*** SUBJECT HERE ***\n\n*** BLURB HERE ***\n";
        const char *msg;
-       const char *extra_headers = rev->extra_headers;
        struct shortlog log;
        struct strbuf sb = STRBUF_INIT;
        int i;
        struct diff_options opts;
        int need_8bit_cte = 0;
        struct commit *commit = NULL;
+       struct pretty_print_context pp = {0};
  
        if (rev->commit_format != CMIT_FMT_EMAIL)
 -              die("Cover letter needs email format");
 +              die(_("Cover letter needs email format"));
  
        committer = git_committer_info(0);
  
@@@ -1177,9 -1128,10 +1178,10 @@@ int cmd_format_patch(int argc, const ch
                numbered = 0;
  
        if (numbered && keep_subject)
 -              die ("-n and -k are mutually exclusive.");
 +              die (_("-n and -k are mutually exclusive."));
        if (keep_subject && subject_prefix)
 -              die ("--subject-prefix and -k are mutually exclusive.");
 +              die (_("--subject-prefix and -k are mutually exclusive."));
+       rev.preserve_subject = keep_subject;
  
        argc = setup_revisions(argc, argv, &rev, &s_r_opt);
        if (argc > 1)
@@@ -1402,23 -1354,6 +1404,22 @@@ static const char * const cherry_usage[
        NULL
  };
  
-               struct pretty_print_context ctx = {0};
-               pretty_print_commit(CMIT_FMT_ONELINE, commit, &buf, &ctx);
 +static void print_commit(char sign, struct commit *commit, int verbose,
 +                       int abbrev)
 +{
 +      if (!verbose) {
 +              printf("%c %s\n", sign,
 +                     find_unique_abbrev(commit->object.sha1, abbrev));
 +      } else {
 +              struct strbuf buf = STRBUF_INIT;
++              pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
 +              printf("%c %s %s\n", sign,
 +                     find_unique_abbrev(commit->object.sha1, abbrev),
 +                     buf.buf);
 +              strbuf_release(&buf);
 +      }
 +}
 +
  int cmd_cherry(int argc, const char **argv, const char *prefix)
  {
        struct rev_info revs;
diff --cc builtin/merge.c
index 5a2a1eb797c88990337f0b9cbb5dcabc73222a22,c902e81cf189c687652bb7752080438f51e15380..325891edb610945d01899b102993202af279bf3f
@@@ -345,12 -340,12 +346,12 @@@ static void squash_message(void
                strbuf_addch(&out, '\n');
                strbuf_addf(&out, "commit %s\n",
                        sha1_to_hex(commit->object.sha1));
-               pretty_print_commit(rev.commit_format, commit, &out, &ctx);
+               pretty_print_commit(&ctx, commit, &out);
        }
        if (write(fd, out.buf, out.len) < 0)
 -              die_errno("Writing SQUASH_MSG");
 +              die_errno(_("Writing SQUASH_MSG"));
        if (close(fd))
 -              die_errno("Finishing SQUASH_MSG");
 +              die_errno(_("Finishing SQUASH_MSG"));
        strbuf_release(&out);
  }
  
Simple merge
Simple merge
Simple merge
diff --cc commit.h
index 3114bd1781c3c5e735dfc1b1a7b4131270992f14,e985dcc6e5d3d0f19db8bd691d226d00b234ae98..a2d571b97410fa857b4c177325c4556dac50fe3f
+++ b/commit.h
@@@ -68,7 -68,9 +68,8 @@@ enum cmit_fmt 
        CMIT_FMT_UNSPECIFIED
  };
  
 -struct pretty_print_context
 -{
 +struct pretty_print_context {
+       enum cmit_fmt fmt;
        int abbrev;
        const char *subject;
        const char *after_subject;
diff --cc log-tree.c
Simple merge
diff --cc pretty.c
Simple merge
diff --cc revision.h
index 4499cebded6bc4348c0648a77d6e0dae4cf00acf,f8ddd83e79db99bfe93dee96696b6606916bd403..3d64adad18e2c889b7a7b7367f99c239f958dc70
@@@ -91,10 -88,10 +91,11 @@@ struct rev_info 
                        show_notes_given:1,
                        pretty_given:1,
                        abbrev_commit:1,
 +                      abbrev_commit_given:1,
                        use_terminator:1,
                        missing_newline:1,
-                       date_mode_explicit:1;
+                       date_mode_explicit:1,
+                       preserve_subject:1;
        unsigned int    disable_stdin:1;
  
        enum date_mode date_mode;