Code

Simplify common default options setup for built-in log family.
[git.git] / git.c
diff --git a/git.c b/git.c
index 9a89b0afbdb16f0c044741e2772066e73186c5c3..cc43bfcaba827b8e71f266d0698f4e2656ac9c7f 100644 (file)
--- a/git.c
+++ b/git.c
@@ -286,6 +286,11 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
        const char *commit_prefix = "commit ";
        int shown = 0;
 
+       rev->abbrev = DEFAULT_ABBREV;
+       rev->commit_format = CMIT_FMT_DEFAULT;
+       rev->no_commit_id = 1;
+       argc = setup_revisions(argc, argv, rev, "HEAD");
+
        if (argc > 1)
                die("unrecognized argument: %s", argv[1]);
        if (rev->commit_format == CMIT_FMT_ONELINE)
@@ -330,8 +335,10 @@ static int cmd_log_wc(int argc, const char **argv, char **envp,
                pretty_print_commit(rev->commit_format, commit, ~0, buf,
                                    LOGSIZE, rev->abbrev);
                printf("%s\n", buf);
-               if (rev->diff)
+               if (rev->diff) {
+                       printf("---\n");
                        log_tree_commit(rev, commit);
+               }
                shown = 1;
                free(commit->buffer);
                commit->buffer = NULL;
@@ -345,12 +352,22 @@ static int cmd_wc(int argc, const char **argv, char **envp)
        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_show(int argc, const char **argv, char **envp)
+{
+       struct rev_info rev;
+
+       init_revisions(&rev);
+       rev.diff = 1;
+       rev.diffopt.recursive = 1;
+       rev.combine_merges = 1;
+       rev.dense_combined_merges = 1;
+       rev.ignore_merges = 0;
+       rev.no_walk = 1;
        return cmd_log_wc(argc, argv, envp, &rev);
 }
 
@@ -359,10 +376,6 @@ static int cmd_log(int argc, const char **argv, char **envp)
        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);
 }
 
@@ -377,9 +390,16 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                { "help", cmd_help },
                { "log", cmd_log },
                { "whatchanged", cmd_wc },
+               { "show", cmd_show },
        };
        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))