Merge branch 'ef/cherry-abbrev'
authorJunio C Hamano <gitster@pobox.com>
Sat, 3 Apr 2010 19:28:40 +0000 (12:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 3 Apr 2010 19:28:40 +0000 (12:28 -0700)
* ef/cherry-abbrev:
ls: remove redundant logic
cherry: support --abbrev option

1  2 
builtin/log.c
diff --combined builtin/log.c
index 542ecc708bdb830bcdbbd48e3fb3d21021119630,87c1eb4869e17ccde525cb1132e5b3e4023d73b6..b706a5ff88ec185e63c0aacd109bb16cc54027e3
@@@ -32,7 -32,7 +32,7 @@@ static const char * const builtin_log_u
        "   or: git show [options] <object>...";
  
  static void cmd_log_init(int argc, const char **argv, const char *prefix,
 -                    struct rev_info *rev)
 +                       struct rev_info *rev, struct setup_revision_opt *opt)
  {
        int i;
        int decoration_style = 0;
         */
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage(builtin_log_usage);
 -      argc = setup_revisions(argc, argv, rev, "HEAD");
 +      argc = setup_revisions(argc, argv, rev, opt);
  
        if (!rev->show_notes_given && !rev->pretty_given)
                rev->show_notes = 1;
 +      if (rev->show_notes)
 +              init_display_notes(&rev->notes_opt);
  
        if (rev->diffopt.pickaxe || rev->diffopt.filter)
                rev->always_show_header = 0;
@@@ -264,7 -262,6 +264,7 @@@ static int git_log_config(const char *v
  int cmd_whatchanged(int argc, const char **argv, const char *prefix)
  {
        struct rev_info rev;
 +      struct setup_revision_opt opt;
  
        git_config(git_log_config, NULL);
  
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.simplify_history = 0;
 -      cmd_log_init(argc, argv, prefix, &rev);
 +      memset(&opt, 0, sizeof(opt));
 +      opt.def = "HEAD";
 +      cmd_log_init(argc, argv, prefix, &rev, &opt);
        if (!rev.diffopt.output_format)
                rev.diffopt.output_format = DIFF_FORMAT_RAW;
        return cmd_log_walk(&rev);
@@@ -329,26 -324,10 +329,26 @@@ static int show_tree_object(const unsig
        return 0;
  }
  
 +static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
 +{
 +      if (rev->ignore_merges) {
 +              /* There was no "-m" on the command line */
 +              rev->ignore_merges = 0;
 +              if (!rev->first_parent_only && !rev->combine_merges) {
 +                      /* No "--first-parent", "-c", nor "--cc" */
 +                      rev->combine_merges = 1;
 +                      rev->dense_combined_merges = 1;
 +              }
 +      }
 +      if (!rev->diffopt.output_format)
 +              rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 +}
 +
  int cmd_show(int argc, const char **argv, const char *prefix)
  {
        struct rev_info rev;
        struct object_array_entry *objects;
 +      struct setup_revision_opt opt;
        int i, count, ret = 0;
  
        git_config(git_log_config, NULL);
  
        init_revisions(&rev, prefix);
        rev.diff = 1;
 -      rev.combine_merges = 1;
 -      rev.dense_combined_merges = 1;
        rev.always_show_header = 1;
 -      rev.ignore_merges = 0;
        rev.no_walk = 1;
 -      cmd_log_init(argc, argv, prefix, &rev);
 +      memset(&opt, 0, sizeof(opt));
 +      opt.def = "HEAD";
 +      opt.tweak = show_rev_tweak_rev;
 +      cmd_log_init(argc, argv, prefix, &rev, &opt);
  
        count = rev.pending.nr;
        objects = rev.pending.objects;
  int cmd_log_reflog(int argc, const char **argv, const char *prefix)
  {
        struct rev_info rev;
 +      struct setup_revision_opt opt;
  
        git_config(git_log_config, NULL);
  
        init_reflog_walk(&rev.reflog_info);
        rev.abbrev_commit = 1;
        rev.verbose_header = 1;
 -      cmd_log_init(argc, argv, prefix, &rev);
 +      memset(&opt, 0, sizeof(opt));
 +      opt.def = "HEAD";
 +      cmd_log_init(argc, argv, prefix, &rev, &opt);
  
        /*
         * This means that we override whatever commit format the user gave
  int cmd_log(int argc, const char **argv, const char *prefix)
  {
        struct rev_info rev;
 +      struct setup_revision_opt opt;
  
        git_config(git_log_config, NULL);
  
  
        init_revisions(&rev, prefix);
        rev.always_show_header = 1;
 -      cmd_log_init(argc, argv, prefix, &rev);
 +      memset(&opt, 0, sizeof(opt));
 +      opt.def = "HEAD";
 +      cmd_log_init(argc, argv, prefix, &rev, &opt);
        return cmd_log_walk(&rev);
  }
  
@@@ -929,7 -902,6 +929,7 @@@ int cmd_format_patch(int argc, const ch
        struct commit *commit;
        struct commit **list = NULL;
        struct rev_info rev;
 +      struct setup_revision_opt s_r_opt;
        int nr = 0, total, i;
        int use_stdout = 0;
        int start_number = -1;
        rev.combine_merges = 0;
        rev.ignore_merges = 1;
        DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
 -
        rev.subject_prefix = fmt_patch_subject_prefix;
 +      memset(&s_r_opt, 0, sizeof(s_r_opt));
 +      s_r_opt.def = "HEAD";
  
        if (default_attach) {
                rev.mime_boundary = default_attach;
        if (keep_subject && subject_prefix)
                die ("--subject-prefix and -k are mutually exclusive.");
  
 -      argc = setup_revisions(argc, argv, &rev, "HEAD");
 +      argc = setup_revisions(argc, argv, &rev, &s_r_opt);
        if (argc > 1)
                die ("unrecognized argument: %s", argv[1]);
  
        if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
                DIFF_OPT_SET(&rev.diffopt, BINARY);
  
 +      if (rev.show_notes)
 +              init_display_notes(&rev.notes_opt);
 +
        if (!use_stdout)
                output_directory = set_outdir(prefix, output_directory);
  
                        return 0;
        }
  
 -      if (ignore_if_in_upstream)
 +      if (ignore_if_in_upstream) {
 +              /* Don't say anything if head and upstream are the same. */
 +              if (rev.pending.nr == 2) {
 +                      struct object_array_entry *o = rev.pending.objects;
 +                      if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0)
 +                              return 0;
 +              }
                get_patch_ids(&rev, &ids, prefix);
 +      }
  
        if (!use_stdout)
                realstdout = xfdopen(xdup(1), "w");
@@@ -1303,8 -1264,11 +1303,11 @@@ static int add_pending_commit(const cha
        return -1;
  }
  
- static const char cherry_usage[] =
- "git cherry [-v] [<upstream> [<head> [<limit>]]]";
+ static const char * const cherry_usage[] = {
+       "git cherry [-v] [<upstream> [<head> [<limit>]]]",
+       NULL
+ };
  int cmd_cherry(int argc, const char **argv, const char *prefix)
  {
        struct rev_info revs;
        const char *upstream;
        const char *head = "HEAD";
        const char *limit = NULL;
-       int verbose = 0;
+       int verbose = 0, abbrev = 0;
  
-       if (argc > 1 && !strcmp(argv[1], "-v")) {
-               verbose = 1;
-               argc--;
-               argv++;
-       }
+       struct option options[] = {
+               OPT__ABBREV(&abbrev),
+               OPT__VERBOSE(&verbose),
+               OPT_END()
+       };
  
-       if (argc > 1 && !strcmp(argv[1], "-h"))
-               usage(cherry_usage);
+       argc = parse_options(argc, argv, prefix, options, cherry_usage, 0);
  
        switch (argc) {
-       case 4:
-               limit = argv[3];
-               /* FALLTHROUGH */
        case 3:
-               head = argv[2];
+               limit = argv[2];
                /* FALLTHROUGH */
        case 2:
-               upstream = argv[1];
+               head = argv[1];
+               /* FALLTHROUGH */
+       case 1:
+               upstream = argv[0];
                break;
        default:
                current_branch = branch_get(NULL);
                        fprintf(stderr, "Could not find a tracked"
                                        " remote branch, please"
                                        " specify <upstream> manually.\n");
-                       usage(cherry_usage);
+                       usage_with_options(cherry_usage, options);
                }
  
                upstream = current_branch->merge[0]->dst;
                        pretty_print_commit(CMIT_FMT_ONELINE, commit,
                                            &buf, &ctx);
                        printf("%c %s %s\n", sign,
-                              sha1_to_hex(commit->object.sha1), buf.buf);
+                              find_unique_abbrev(commit->object.sha1, abbrev),
+                              buf.buf);
                        strbuf_release(&buf);
                }
                else {
                        printf("%c %s\n", sign,
-                              sha1_to_hex(commit->object.sha1));
+                              find_unique_abbrev(commit->object.sha1, abbrev));
                }
  
                list = list->next;