]> asedeno.scripts.mit.edu Git - git.git/commitdiff
Merge branch 'rr/format-patch-count-without-merges'
authorJunio C Hamano <gitster@pobox.com>
Wed, 29 Sep 2010 20:49:09 +0000 (13:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Sep 2010 20:49:09 +0000 (13:49 -0700)
* rr/format-patch-count-without-merges:
  format-patch: Don't go over merge commits
  t4014-format-patch: Call test_tick before committing

1  2 
Documentation/git-format-patch.txt
builtin/log.c
t/t4014-format-patch.sh

index 4b3f5ba5358da469feff4e861e69717f16e81d21,95b8bcc49ed04f2d8e9eb49c233a81d8407d095a..df77474c2950d2a15145ac2bd086697fe365a192
@@@ -13,7 -13,6 +13,7 @@@ SYNOPSI
                   [--no-thread | --thread[=<style>]]
                   [(--attach|--inline)[=<boundary>] | --no-attach]
                   [-s | --signoff]
 +                 [--signature=<signature> | --no-signature]
                   [-n | --numbered | -N | --no-numbered]
                   [--start-number <n>] [--numbered-files]
                   [--in-reply-to=Message-Id] [--suffix=.<sfx>]
@@@ -39,7 -38,7 +39,7 @@@ There are two ways to specify which com
     that leads to the <since> to be output.
  
  2. Generic <revision range> expression (see "SPECIFYING
 -   REVISIONS" section in linkgit:git-rev-parse[1]) means the
 +   REVISIONS" section in linkgit:gitrevisions[1]) means the
     commits in the specified range.
  
  The first rule takes precedence in the case of a single <commit>.  To
@@@ -74,7 -73,7 +74,7 @@@ OPTION
  include::diff-options.txt[]
  
  -<n>::
-       Limits the number of patches to prepare.
+       Prepare patches from the topmost <n> commits.
  
  -o <dir>::
  --output-directory <dir>::
@@@ -181,12 -180,6 +181,12 @@@ will want to ensure that threading is d
        containing the shortlog and the overall diffstat.  You can
        fill in a description in the file before sending it out.
  
 +--[no]-signature=<signature>::
 +      Add a signature to each message produced. Per RFC 3676 the signature
 +      is separated from the body by a line with '-- ' on it. If the
 +      signature option is omitted the signature defaults to the git version
 +      number.
 +
  --suffix=.<sfx>::
        Instead of using `.patch` as the suffix for generated
        filenames, use specified suffix.  A common alternative is
diff --combined builtin/log.c
index eaa1ee0fa71a344af747dec038c6a5907c8273a5,0093b2d8d8de561512efffe7cc416b1cdfe225dd..22d12903ac06597979f30d0fd94267fc543afa29
@@@ -24,7 -24,6 +24,7 @@@
  static const char *default_date_mode = NULL;
  
  static int default_show_root = 1;
 +static int decoration_style;
  static const char *fmt_patch_subject_prefix = "PATCH";
  static const char *fmt_pretty;
  
@@@ -32,28 -31,11 +32,28 @@@ static const char * const builtin_log_u
        "git log [<options>] [<since>..<until>] [[--] <path>...]\n"
        "   or: git show [options] <object>...";
  
 +static int parse_decoration_style(const char *var, const char *value)
 +{
 +      switch (git_config_maybe_bool(var, value)) {
 +      case 1:
 +              return DECORATE_SHORT_REFS;
 +      case 0:
 +              return 0;
 +      default:
 +              break;
 +      }
 +      if (!strcmp(value, "full"))
 +              return DECORATE_FULL_REFS;
 +      else if (!strcmp(value, "short"))
 +              return DECORATE_SHORT_REFS;
 +      return -1;
 +}
 +
  static void cmd_log_init(int argc, const char **argv, const char *prefix,
                         struct rev_info *rev, struct setup_revision_opt *opt)
  {
        int i;
 -      int decoration_style = 0;
 +      int decoration_given = 0;
        struct userformat_want w;
  
        rev->abbrev = DEFAULT_ABBREV;
                const char *arg = argv[i];
                if (!strcmp(arg, "--decorate")) {
                        decoration_style = DECORATE_SHORT_REFS;
 +                      decoration_given = 1;
                } else if (!prefixcmp(arg, "--decorate=")) {
                        const char *v = skip_prefix(arg, "--decorate=");
 -                      if (!strcmp(v, "full"))
 -                              decoration_style = DECORATE_FULL_REFS;
 -                      else if (!strcmp(v, "short"))
 -                              decoration_style = DECORATE_SHORT_REFS;
 -                      else
 +                      decoration_style = parse_decoration_style(arg, v);
 +                      if (decoration_style < 0)
                                die("invalid --decorate option: %s", arg);
 +                      decoration_given = 1;
 +              } else if (!strcmp(arg, "--no-decorate")) {
 +                      decoration_style = 0;
                } else if (!strcmp(arg, "--source")) {
                        rev->show_source = 1;
                } else if (!strcmp(arg, "-h")) {
                } else
                        die("unrecognized argument: %s", arg);
        }
 +
 +      /*
 +       * defeat log.decorate configuration interacting with --pretty=raw
 +       * from the command line.
 +       */
 +      if (!decoration_given && rev->pretty_given
 +          && rev->commit_format == CMIT_FMT_RAW)
 +              decoration_style = 0;
 +
        if (decoration_style) {
                rev->show_decorations = 1;
                load_ref_decorations(decoration_style);
        }
 +      setup_pager();
  }
  
  /*
@@@ -287,19 -258,10 +287,19 @@@ static int git_log_config(const char *v
                return git_config_string(&fmt_patch_subject_prefix, var, value);
        if (!strcmp(var, "log.date"))
                return git_config_string(&default_date_mode, var, value);
 +      if (!strcmp(var, "log.decorate")) {
 +              decoration_style = parse_decoration_style(var, value);
 +              if (decoration_style < 0)
 +                      decoration_style = 0; /* maybe warn? */
 +              return 0;
 +      }
        if (!strcmp(var, "log.showroot")) {
                default_show_root = git_config_bool(var, value);
                return 0;
        }
 +      if (!prefixcmp(var, "color.decorate."))
 +              return parse_decorate_color_config(var, 15, value);
 +
        return git_diff_ui_config(var, value, cb);
  }
  
@@@ -492,6 -454,12 +492,6 @@@ int cmd_log_reflog(int argc, const cha
        rev.use_terminator = 1;
        rev.always_show_header = 1;
  
 -      /*
 -       * We get called through "git reflog", so unlike the other log
 -       * routines, we need to set up our pager manually..
 -       */
 -      setup_pager();
 -
        return cmd_log_walk(&rev);
  }
  
@@@ -533,13 -501,13 +533,13 @@@ static void add_header(const char *valu
                len--;
  
        if (!strncasecmp(value, "to: ", 4)) {
 -              item = string_list_append(value + 4, &extra_to);
 +              item = string_list_append(&extra_to, value + 4);
                len -= 4;
        } else if (!strncasecmp(value, "cc: ", 4)) {
 -              item = string_list_append(value + 4, &extra_cc);
 +              item = string_list_append(&extra_cc, value + 4);
                len -= 4;
        } else {
 -              item = string_list_append(value, &extra_hdr);
 +              item = string_list_append(&extra_hdr, value);
        }
  
        item->string[len] = '\0';
  
  #define THREAD_SHALLOW 1
  #define THREAD_DEEP 2
 -static int thread = 0;
 -static int do_signoff = 0;
 +static int thread;
 +static int do_signoff;
 +static const char *signature = git_version_string;
  
  static int git_format_config(const char *var, const char *value, void *cb)
  {
        if (!strcmp(var, "format.to")) {
                if (!value)
                        return config_error_nonbool(var);
 -              string_list_append(value, &extra_to);
 +              string_list_append(&extra_to, value);
                return 0;
        }
        if (!strcmp(var, "format.cc")) {
                if (!value)
                        return config_error_nonbool(var);
 -              string_list_append(value, &extra_cc);
 +              string_list_append(&extra_cc, value);
                return 0;
        }
        if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
                do_signoff = git_config_bool(var, value);
                return 0;
        }
 +      if (!strcmp(var, "format.signature"))
 +              return git_config_string(&signature, var, value);
  
        return git_log_config(var, value, cb);
  }
@@@ -704,12 -669,6 +704,12 @@@ static void gen_message_id(struct rev_i
        info->message_id = strbuf_detach(&buf, NULL);
  }
  
 +static void print_signature(void)
 +{
 +      if (signature && *signature)
 +              printf("-- \n%s\n\n", signature);
 +}
 +
  static void make_cover_letter(struct rev_info *rev, int use_stdout,
                              int numbered, int numbered_files,
                              struct commit *origin,
        diff_flush(&opts);
  
        printf("\n");
 +      print_signature();
  }
  
  static const char *clean_message_id(const char *msg_id)
@@@ -957,7 -915,7 +957,7 @@@ static int to_callback(const struct opt
        if (unset)
                string_list_clear(&extra_to, 0);
        else
 -              string_list_append(arg, &extra_to);
 +              string_list_append(&extra_to, arg);
        return 0;
  }
  
@@@ -966,7 -924,7 +966,7 @@@ static int cc_callback(const struct opt
        if (unset)
                string_list_clear(&extra_cc, 0);
        else
 -              string_list_append(arg, &extra_cc);
 +              string_list_append(&extra_cc, arg);
        return 0;
  }
  
@@@ -1043,8 -1001,6 +1043,8 @@@ int cmd_format_patch(int argc, const ch
                { OPTION_CALLBACK, 0, "thread", &thread, "style",
                            "enable message threading, styles: shallow, deep",
                            PARSE_OPT_OPTARG, thread_callback },
 +              OPT_STRING(0, "signature", &signature, "signature",
 +                          "add a signature"),
                OPT_END()
        };
  
        rev.commit_format = CMIT_FMT_EMAIL;
        rev.verbose_header = 1;
        rev.diff = 1;
-       rev.combine_merges = 0;
-       rev.ignore_merges = 1;
+       rev.no_merges = 1;
        DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
        rev.subject_prefix = fmt_patch_subject_prefix;
        memset(&s_r_opt, 0, sizeof(s_r_opt));
                        continue;
                }
  
-               /* ignore merges */
-               if (commit->parents && commit->parents->next)
-                       continue;
                if (ignore_if_in_upstream &&
                                has_commit_patch_id(commit, &ids))
                        continue;
                rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
        if (in_reply_to) {
                const char *msgid = clean_message_id(in_reply_to);
 -              string_list_append(msgid, rev.ref_message_ids);
 +              string_list_append(rev.ref_message_ids, msgid);
        }
        rev.numbered_files = numbered_files;
        rev.patch_suffix = fmt_patch_suffix;
                                    && (!cover_letter || rev.nr > 1))
                                        free(rev.message_id);
                                else
 -                                      string_list_append(rev.message_id,
 -                                                         rev.ref_message_ids);
 +                                      string_list_append(rev.ref_message_ids,
 +                                                         rev.message_id);
                        }
                        gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
                }
                                       mime_boundary_leader,
                                       rev.mime_boundary);
                        else
 -                              printf("-- \n%s\n\n", git_version_string);
 +                              print_signature();
                }
                if (!use_stdout)
                        fclose(stdout);
diff --combined t/t4014-format-patch.sh
index f87434b9f8e0d520813389e6ea7c94f74222767b,2e78c9e662e8a506802665b97e6b07c22a1b134e..07bf6eb49dd2879758f64a8c09a0ae8d7e54dd45
@@@ -12,24 -12,29 +12,29 @@@ test_expect_success setup 
        for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
        cat file >elif &&
        git add file elif &&
+       test_tick &&
        git commit -m Initial &&
        git checkout -b side &&
  
        for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
        test_chmod +x elif &&
+       test_tick &&
        git commit -m "Side changes #1" &&
  
        for i in D E F; do echo "$i"; done >>file &&
        git update-index file &&
+       test_tick &&
        git commit -m "Side changes #2" &&
        git tag C2 &&
  
        for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
        git update-index file &&
+       test_tick &&
        git commit -m "Side changes #3 with \\n backslash-n in it." &&
  
        git checkout master &&
        git diff-tree -p C2 | git apply --index &&
+       test_tick &&
        git commit -m "Master accepts moral equivalent of #2"
  
  '
@@@ -51,6 -56,22 +56,22 @@@ test_expect_success "format-patch --ign
  
  '
  
+ test_expect_success "format-patch doesn't consider merge commits" '
+       git checkout -b slave master &&
+       echo "Another line" >>file &&
+       test_tick &&
+       git commit -am "Slave change #1" &&
+       echo "Yet another line" >>file &&
+       test_tick &&
+       git commit -am "Slave change #2" &&
+       git checkout -b merger master &&
+       test_tick &&
+       git merge --no-ff slave &&
+       cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` &&
+       test $cnt = 3
+ '
  test_expect_success "format-patch result applies" '
  
        git checkout -b rebuild-0 master &&
@@@ -613,56 -634,4 +634,56 @@@ test_expect_success 'format-patch --ign
        git format-patch --ignore-if-in-upstream HEAD
  '
  
 +test_expect_success 'format-patch --signature' '
 +      git format-patch --stdout --signature="my sig" -1 >output &&
 +      grep "my sig" output
 +'
 +
 +test_expect_success 'format-patch with format.signature config' '
 +      git config format.signature "config sig" &&
 +      git format-patch --stdout -1 >output &&
 +      grep "config sig" output
 +'
 +
 +test_expect_success 'format-patch --signature overrides format.signature' '
 +      git config format.signature "config sig" &&
 +      git format-patch --stdout --signature="overrides" -1 >output &&
 +      ! grep "config sig" output &&
 +      grep "overrides" output
 +'
 +
 +test_expect_success 'format-patch --no-signature ignores format.signature' '
 +      git config format.signature "config sig" &&
 +      git format-patch --stdout --signature="my sig" --no-signature \
 +              -1 >output &&
 +      ! grep "config sig" output &&
 +      ! grep "my sig" output &&
 +      ! grep "^-- \$" output
 +'
 +
 +test_expect_success 'format-patch --signature --cover-letter' '
 +      git config --unset-all format.signature &&
 +      git format-patch --stdout --signature="my sig" --cover-letter \
 +              -1 >output &&
 +      grep "my sig" output &&
 +      test 2 = $(grep "my sig" output | wc -l)
 +'
 +
 +test_expect_success 'format.signature="" supresses signatures' '
 +      git config format.signature "" &&
 +      git format-patch --stdout -1 >output &&
 +      ! grep "^-- \$" output
 +'
 +
 +test_expect_success 'format-patch --no-signature supresses signatures' '
 +      git config --unset-all format.signature &&
 +      git format-patch --stdout --no-signature -1 >output &&
 +      ! grep "^-- \$" output
 +'
 +
 +test_expect_success 'format-patch --signature="" supresses signatures' '
 +      git format-patch --signature="" -1 >output &&
 +      ! grep "^-- \$" output
 +'
 +
  test_done