Code

git rev-list: fix invalid typecast
[git.git] / builtin / rev-list.c
index c924b3a2c76c1f9a7f5531504825ed1b5456d41a..264e3ae9d840c342499634e21b21c274ebcebacf 100644 (file)
 static const char rev_list_usage[] =
 "git rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
 "  limiting output:\n"
-"    --max-count=nr\n"
-"    --max-age=epoch\n"
-"    --min-age=epoch\n"
+"    --max-count=<n>\n"
+"    --max-age=<epoch>\n"
+"    --min-age=<epoch>\n"
 "    --sparse\n"
 "    --no-merges\n"
+"    --min-parents=<n>\n"
+"    --no-min-parents\n"
+"    --max-parents=<n>\n"
+"    --no-max-parents\n"
 "    --remove-empty\n"
 "    --all\n"
 "    --branches\n"
@@ -33,7 +37,7 @@ static const char rev_list_usage[] =
 "    --objects | --objects-edge\n"
 "    --unpacked\n"
 "    --header | --pretty\n"
-"    --abbrev=nr | --no-abbrev\n"
+"    --abbrev=<n> | --no-abbrev\n"
 "    --abbrev-commit\n"
 "    --left-right\n"
 "  special purpose:\n"
@@ -50,23 +54,24 @@ static void show_commit(struct commit *commit, void *data)
 
        graph_show_commit(revs->graph);
 
+       if (revs->count) {
+               if (commit->object.flags & PATCHSAME)
+                       revs->count_same++;
+               else if (commit->object.flags & SYMMETRIC_LEFT)
+                       revs->count_left++;
+               else
+                       revs->count_right++;
+               finish_commit(commit, data);
+               return;
+       }
+
        if (info->show_timestamp)
                printf("%lu ", commit->date);
        if (info->header_prefix)
                fputs(info->header_prefix, stdout);
 
-       if (!revs->graph) {
-               if (commit->object.flags & BOUNDARY)
-                       putchar('-');
-               else if (commit->object.flags & UNINTERESTING)
-                       putchar('^');
-               else if (revs->left_right) {
-                       if (commit->object.flags & SYMMETRIC_LEFT)
-                               putchar('<');
-                       else
-                               putchar('>');
-               }
-       }
+       if (!revs->graph)
+               fputs(get_revision_mark(revs, commit), stdout);
        if (revs->abbrev_commit && revs->abbrev)
                fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
                      stdout);
@@ -99,7 +104,8 @@ static void show_commit(struct commit *commit, void *data)
                struct pretty_print_context ctx = {0};
                ctx.abbrev = revs->abbrev;
                ctx.date_mode = revs->date_mode;
-               pretty_print_commit(revs->commit_format, commit, &buf, &ctx);
+               ctx.fmt = revs->commit_format;
+               pretty_print_commit(&ctx, commit, &buf);
                if (revs->graph) {
                        if (buf.len) {
                                if (revs->commit_format != CMIT_FMT_ONELINE)
@@ -133,10 +139,15 @@ static void show_commit(struct commit *commit, void *data)
                                 */
                                if (graph_show_remainder(revs->graph))
                                        putchar('\n');
+                               if (revs->commit_format == CMIT_FMT_ONELINE)
+                                       putchar('\n');
                        }
                } else {
-                       if (buf.len)
-                               printf("%s%c", buf.buf, info->hdr_termination);
+                       if (revs->commit_format != CMIT_FMT_USERFORMAT ||
+                           buf.len) {
+                               fwrite(buf.buf, 1, buf.len, stdout);
+                               putchar(info->hdr_termination);
+                       }
                }
                strbuf_release(&buf);
        } else {
@@ -157,29 +168,24 @@ static void finish_commit(struct commit *commit, void *data)
        commit->buffer = NULL;
 }
 
-static void finish_object(struct object *obj, const struct name_path *path, const char *name)
+static void finish_object(struct object *obj,
+                         const struct name_path *path, const char *name,
+                         void *cb_data)
 {
        if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
                die("missing blob object '%s'", sha1_to_hex(obj->sha1));
 }
 
-static void show_object(struct object *obj, const struct name_path *path, const char *component)
+static void show_object(struct object *obj,
+                       const struct name_path *path, const char *component,
+                       void *cb_data)
 {
-       char *name = path_name(path, component);
-       /* An object with name "foo\n0000000..." can be used to
-        * confuse downstream "git pack-objects" very badly.
-        */
-       const char *ep = strchr(name, '\n');
+       struct rev_list_info *info = cb_data;
 
-       finish_object(obj, path, name);
-       if (ep) {
-               printf("%s %.*s\n", sha1_to_hex(obj->sha1),
-                      (int) (ep - name),
-                      name);
-       }
-       else
-               printf("%s %s\n", sha1_to_hex(obj->sha1), name);
-       free(name);
+       finish_object(obj, path, component, cb_data);
+       if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
+               parse_object(obj->sha1);
+       show_object_with_name(stdout, obj, path, component);
 }
 
 static void show_edge(struct commit *commit)
@@ -313,7 +319,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 
        git_config(git_default_config, NULL);
        init_revisions(&revs, prefix);
-       revs.abbrev = 0;
+       revs.abbrev = DEFAULT_ABBREV;
        revs.commit_format = CMIT_FMT_UNSPECIFIED;
        argc = setup_revisions(argc, argv, &revs, NULL);
 
@@ -371,8 +377,9 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
            revs.diff)
                usage(rev_list_usage);
 
-       save_commit_buffer = revs.verbose_header ||
-               revs.grep_filter.pattern_list;
+       save_commit_buffer = (revs.verbose_header ||
+                             revs.grep_filter.pattern_list ||
+                             revs.grep_filter.header_list);
        if (bisect_list)
                revs.limited = 1;
 
@@ -396,5 +403,16 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
                             quiet ? finish_object : show_object,
                             &info);
 
+       if (revs.count) {
+               if (revs.left_right && revs.cherry_mark)
+                       printf("%d\t%d\t%d\n", revs.count_left, revs.count_right, revs.count_same);
+               else if (revs.left_right)
+                       printf("%d\t%d\n", revs.count_left, revs.count_right);
+               else if (revs.cherry_mark)
+                       printf("%d\t%d\n", revs.count_left + revs.count_right, revs.count_same);
+               else
+                       printf("%d\n", revs.count_left + revs.count_right);
+       }
+
        return 0;
 }