Merge branch 'lt/logopt' into next
authorJunio C Hamano <junkio@cox.net>
Sun, 16 Apr 2006 07:52:55 +0000 (00:52 -0700)
committerJunio C Hamano <junkio@cox.net>
Sun, 16 Apr 2006 08:02:33 +0000 (01:02 -0700)
* lt/logopt:
Tentative built-in "git show"
Built-in git-whatchanged.
rev-list option parser fix.
Split init_revisions() out of setup_revisions()

1  2 
git.c
rev-list.c
diff --combined git.c
index 2e0ae5e58ebd2f4ae58d934d9098b9de85c31ab1,9e29ade2b4b7b92d6eb6a4ffad56db37642a3620..239b26adfda494e6568d07b22c28d0c2ef4ca78c
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -279,31 -279,28 +279,28 @@@ static int cmd_help(int argc, const cha
  #define LOGSIZE (65536)
  
  static int cmd_log_wc(int argc, const char **argv, char **envp,
-                     struct whatchanged_opt *wcopt)
+                     struct rev_info *rev)
  {
        struct commit *commit;
        char *buf = xmalloc(LOGSIZE);
        const char *commit_prefix = "commit ";
        int shown = 0;
-       struct rev_info *rev = &wcopt->revopt;
-       struct log_tree_opt *opt = &wcopt->logopt;
  
-       opt->commit_format = CMIT_FMT_DEFAULT;
-       wcopt->abbrev = DEFAULT_ABBREV;
-       argc = parse_whatchanged_opt(argc, argv, wcopt);
-       if (opt->commit_format == CMIT_FMT_ONELINE)
+       if (argc > 1)
+               die("unrecognized argument: %s", argv[1]);
+       if (rev->commit_format == CMIT_FMT_ONELINE)
                commit_prefix = "";
  
        prepare_revision_walk(rev);
        setup_pager();
        while ((commit = get_revision(rev)) != NULL) {
-               if (shown && wcopt->do_diff &&
-                   opt->commit_format != CMIT_FMT_ONELINE)
+               if (shown && rev->diff &&
+                   rev->commit_format != CMIT_FMT_ONELINE)
                        putchar('\n');
                fputs(commit_prefix, stdout);
-               if (wcopt->abbrev_commit && wcopt->abbrev)
-                       fputs(find_unique_abbrev(commit->object.sha1, wcopt->abbrev),
+               if (rev->abbrev_commit && rev->abbrev)
+                       fputs(find_unique_abbrev(commit->object.sha1,
+                                                rev->abbrev),
                              stdout);
                else
                        fputs(sha1_to_hex(commit->object.sha1), stdout);
                             parents = parents->next)
                                parents->item->object.flags &= ~TMP_MARK;
                }
-               if (opt->commit_format == CMIT_FMT_ONELINE)
+               if (rev->commit_format == CMIT_FMT_ONELINE)
                        putchar(' ');
                else
                        putchar('\n');
-               pretty_print_commit(opt->commit_format, commit, ~0, buf,
-                                   LOGSIZE, wcopt->abbrev);
+               pretty_print_commit(rev->commit_format, commit, ~0, buf,
+                                   LOGSIZE, rev->abbrev);
                printf("%s\n", buf);
-               if (wcopt->do_diff) {
-                       printf("---\n");
-                       log_tree_commit(opt, commit);
 -              if (rev->diff)
++              if (rev->diff) {
++                      printf("--\n");
+                       log_tree_commit(rev, commit);
 +              }
                shown = 1;
                free(commit->buffer);
                commit->buffer = NULL;
        return 0;
  }
  
- static int cmd_log(int ac, const char **av, char **ep)
+ static int cmd_wc(int argc, const char **argv, char **envp)
  {
-       struct whatchanged_opt wcopt;
-       memset(&wcopt, 0, sizeof(wcopt));
-       init_log_tree_opt(&wcopt.logopt);
-       return cmd_log_wc(ac, av, ep, &wcopt);
+       struct rev_info rev;
+       init_revisions(&rev);
+       rev.abbrev = DEFAULT_ABBREV;
+       rev.no_commit_id = 1;
+       rev.commit_format = CMIT_FMT_DEFAULT;
+       rev.diff = 1;
+       rev.diffopt.recursive = 1;
+       argc = setup_revisions(argc, argv, &rev, "HEAD");
+       return cmd_log_wc(argc, argv, envp, &rev);
  }
  
- static int cmd_whatchanged(int ac, const char **av, char **ep)
+ static int cmd_show(int argc, const char **argv, char **envp)
  {
-       struct whatchanged_opt wcopt;
-       memset(&wcopt, 0, sizeof(wcopt));
-       wcopt.do_diff = 1;
-       init_log_tree_opt(&wcopt.logopt);
-       wcopt.logopt.diffopt.recursive = 1;
-       return cmd_log_wc(ac, av, ep, &wcopt);
+       struct rev_info rev;
+       init_revisions(&rev);
+       rev.diff = 1;
+       rev.ignore_merges = 0;
+       rev.combine_merges = 1;
+       rev.dense_combined_merges = 1;
+       rev.abbrev = DEFAULT_ABBREV;
+       rev.commit_format = CMIT_FMT_DEFAULT;
+       rev.diffopt.recursive = 1;
+       rev.no_walk = 1;
+       argc = setup_revisions(argc, argv, &rev, "HEAD");
+       return cmd_log_wc(argc, argv, envp, &rev);
  }
  
- static int cmd_show(int ac, const char **av, char **ep)
+ static int cmd_log(int argc, const char **argv, char **envp)
  {
-       struct whatchanged_opt wcopt;
-       memset(&wcopt, 0, sizeof(wcopt));
-       wcopt.do_diff = 1;
-       init_log_tree_opt(&wcopt.logopt);
-       wcopt.logopt.ignore_merges = 0;
-       wcopt.logopt.combine_merges = 1;
-       wcopt.logopt.dense_combined_merges = 1;
-       wcopt.logopt.diffopt.recursive = 1;
-       return cmd_log_wc(ac, av, ep, &wcopt);
+       struct rev_info rev;
+       init_revisions(&rev);
+       rev.abbrev = DEFAULT_ABBREV;
+       rev.no_commit_id = 1;
+       rev.commit_format = CMIT_FMT_DEFAULT;
+       argc = setup_revisions(argc, argv, &rev, "HEAD");
+       return cmd_log_wc(argc, argv, envp, &rev);
  }
  
  static void handle_internal_command(int argc, const char **argv, char **envp)
                { "version", cmd_version },
                { "help", cmd_help },
                { "log", cmd_log },
+               { "whatchanged", cmd_wc },
                { "show", cmd_show },
-               { "whatchanged", cmd_whatchanged },
        };
        int i;
  
 +      /* Turn "git cmd --help" into "git help cmd" */
 +      if (argc > 1 && !strcmp(argv[1], "--help")) {
 +              argv[1] = argv[0];
 +              argv[0] = cmd = "help";
 +      }
 +
        for (i = 0; i < ARRAY_SIZE(commands); i++) {
                struct cmd_struct *p = commands+i;
                if (strcmp(p->cmd, cmd))
diff --combined rev-list.c
index cb67b399fc560c17e1611139aeebb0a51553ecfa,000f27a8fedbb1ed981fc7466176c47cf8fee993..33741ebbc4eec2ab7abdd9b5c045c7a6ec3cada6
@@@ -39,24 -39,20 +39,20 @@@ static const char rev_list_usage[] 
  struct rev_info revs;
  
  static int bisect_list = 0;
- static int verbose_header = 0;
- static int abbrev = DEFAULT_ABBREV;
- static int abbrev_commit = 0;
  static int show_timestamp = 0;
  static int hdr_termination = 0;
- static const char *commit_prefix = "";
- static enum cmit_fmt commit_format = CMIT_FMT_RAW;
  
  static void show_commit(struct commit *commit)
  {
        if (show_timestamp)
                printf("%lu ", commit->date);
-       if (commit_prefix[0])
-               fputs(commit_prefix, stdout);
+       if (*revs.header_prefix)
+               fputs(revs.header_prefix, stdout);
        if (commit->object.flags & BOUNDARY)
                putchar('-');
-       if (abbrev_commit && abbrev)
-               fputs(find_unique_abbrev(commit->object.sha1, abbrev), stdout);
+       if (revs.abbrev_commit && revs.abbrev)
+               fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev),
+                     stdout);
        else
                fputs(sha1_to_hex(commit->object.sha1), stdout);
        if (revs.parents) {
                     parents = parents->next)
                        parents->item->object.flags &= ~TMP_MARK;
        }
-       if (commit_format == CMIT_FMT_ONELINE)
+       if (revs.commit_format == CMIT_FMT_ONELINE)
                putchar(' ');
        else
                putchar('\n');
  
-       if (verbose_header) {
+       if (revs.verbose_header) {
                static char pretty_header[16384];
-               pretty_print_commit(commit_format, commit, ~0, pretty_header, sizeof(pretty_header), abbrev);
+               pretty_print_commit(revs.commit_format, commit, ~0,
+                                   pretty_header, sizeof(pretty_header),
+                                   revs.abbrev);
                printf("%s%c", pretty_header, hdr_termination);
        }
        fflush(stdout);
@@@ -297,58 -295,16 +295,16 @@@ int main(int argc, const char **argv
        struct commit_list *list;
        int i;
  
+       init_revisions(&revs);
+       revs.abbrev = 0;
+       revs.commit_format = CMIT_FMT_UNSPECIFIED;
        argc = setup_revisions(argc, argv, &revs, NULL);
  
        for (i = 1 ; i < argc; i++) {
                const char *arg = argv[i];
  
-               /* accept -<digit>, like traditilnal "head" */
-               if ((*arg == '-') && isdigit(arg[1])) {
-                       revs.max_count = atoi(arg + 1);
-                       continue;
-               }
-               if (!strcmp(arg, "-n")) {
-                       if (++i >= argc)
-                               die("-n requires an argument");
-                       revs.max_count = atoi(argv[i]);
-                       continue;
-               }
-               if (!strncmp(arg,"-n",2)) {
-                       revs.max_count = atoi(arg + 2);
-                       continue;
-               }
                if (!strcmp(arg, "--header")) {
-                       verbose_header = 1;
-                       continue;
-               }
-               if (!strcmp(arg, "--no-abbrev")) {
-                       abbrev = 0;
-                       continue;
-               }
-               if (!strcmp(arg, "--abbrev")) {
-                       abbrev = DEFAULT_ABBREV;
-                       continue;
-               }
-               if (!strcmp(arg, "--abbrev-commit")) {
-                       abbrev_commit = 1;
-                       continue;
-               }
-               if (!strncmp(arg, "--abbrev=", 9)) {
-                       abbrev = strtoul(arg + 9, NULL, 10);
-                       if (abbrev && abbrev < MINIMUM_ABBREV)
-                               abbrev = MINIMUM_ABBREV;
-                       else if (40 < abbrev)
-                               abbrev = 40;
-                       continue;
-               }
-               if (!strncmp(arg, "--pretty", 8)) {
-                       commit_format = get_commit_format(arg+8);
-                       verbose_header = 1;
-                       hdr_termination = '\n';
-                       if (commit_format == CMIT_FMT_ONELINE)
-                               commit_prefix = "";
-                       else
-                               commit_prefix = "commit ";
+                       revs.verbose_header = 1;
                        continue;
                }
                if (!strcmp(arg, "--timestamp")) {
                usage(rev_list_usage);
  
        }
+       if (revs.commit_format != CMIT_FMT_UNSPECIFIED) {
+               /* The command line has a --pretty  */
+               hdr_termination = '\n';
+               if (revs.commit_format == CMIT_FMT_ONELINE)
+                       revs.header_prefix = "";
+               else
+                       revs.header_prefix = "commit ";
+       }
  
        list = revs.commits;
  
-       if (!list &&
-           (!(revs.tag_objects||revs.tree_objects||revs.blob_objects) && !revs.pending_objects))
+       if ((!list &&
+            (!(revs.tag_objects||revs.tree_objects||revs.blob_objects) &&
+             !revs.pending_objects)) ||
+           revs.diff)
                usage(rev_list_usage);
  
-       save_commit_buffer = verbose_header;
+       save_commit_buffer = revs.verbose_header;
        track_object_refs = 0;
 +      if (bisect_list)
 +              revs.limited = 1;
  
        prepare_revision_walk(&revs);
        if (revs.tree_objects)