Code

fast-export: Make sure we show actual ref names instead of "(null)"
[git.git] / builtin-rev-list.c
index 193993cf4494aca98d5e57ce80bc2c99b5cba948..4ba1c12e0b6fedb056aebed6ffc8f8bb8d6cfd18 100644 (file)
@@ -156,27 +156,29 @@ static void finish_commit(struct commit *commit, void *data)
        commit->buffer = NULL;
 }
 
-static void finish_object(struct object_array_entry *p, void *data)
+static void finish_object(struct object *obj, const struct name_path *path, const char *name)
 {
-       if (p->item->type == OBJ_BLOB && !has_sha1_file(p->item->sha1))
-               die("missing blob object '%s'", sha1_to_hex(p->item->sha1));
+       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_array_entry *p, void *data)
+static void show_object(struct object *obj, const struct name_path *path, const char *component)
 {
+       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(p->name, '\n');
+       const char *ep = strchr(name, '\n');
 
-       finish_object(p, data);
+       finish_object(obj, path, name);
        if (ep) {
-               printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
-                      (int) (ep - p->name),
-                      p->name);
+               printf("%s %.*s\n", sha1_to_hex(obj->sha1),
+                      (int) (ep - name),
+                      name);
        }
        else
-               printf("%s %s\n", sha1_to_hex(p->item->sha1), p->name);
+               printf("%s %s\n", sha1_to_hex(obj->sha1), name);
+       free(name);
 }
 
 static void show_edge(struct commit *commit)
@@ -209,7 +211,7 @@ static inline int exp2i(int n)
  *
  * and P(2^n + x) < 0.5 means 2^n < 3x
  */
-static int estimate_bisect_steps(int all)
+int estimate_bisect_steps(int all)
 {
        int n, x, e;
 
@@ -223,27 +225,46 @@ static int estimate_bisect_steps(int all)
        return (e < 3 * x) ? n : n - 1;
 }
 
-static void show_tried_revs(struct commit_list *tried, int stringed)
+void print_commit_list(struct commit_list *list,
+                      const char *format_cur,
+                      const char *format_last)
 {
-       printf("bisect_tried='");
-       for (;tried; tried = tried->next) {
-               char *format = tried->next ? "%s|" : "%s";
-               printf(format, sha1_to_hex(tried->item->object.sha1));
+       for ( ; list; list = list->next) {
+               const char *format = list->next ? format_cur : format_last;
+               printf(format, sha1_to_hex(list->item->object.sha1));
        }
-       printf(stringed ? "' &&\n" : "'\n");
+}
+
+static void show_tried_revs(struct commit_list *tried)
+{
+       printf("bisect_tried='");
+       print_commit_list(tried, "%s|", "%s");
+       printf("'\n");
+}
+
+static void print_var_str(const char *var, const char *val)
+{
+       printf("%s='%s'\n", var, val);
+}
+
+static void print_var_int(const char *var, int val)
+{
+       printf("%s=%d\n", var, val);
 }
 
 int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
 {
        int cnt, flags = info->bisect_show_flags;
-       char hex[41] = "", *format;
+       char hex[41] = "";
        struct commit_list *tried;
        struct rev_info *revs = info->revs;
 
        if (!revs->commits && !(flags & BISECT_SHOW_TRIED))
                return 1;
 
-       revs->commits = filter_skipped(revs->commits, &tried, flags & BISECT_SHOW_ALL);
+       revs->commits = filter_skipped(revs->commits, &tried,
+                                      flags & BISECT_SHOW_ALL,
+                                      NULL, NULL);
 
        /*
         * revs->commits can reach "reaches" commits among
@@ -267,28 +288,14 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
        }
 
        if (flags & BISECT_SHOW_TRIED)
-               show_tried_revs(tried, flags & BISECT_SHOW_STRINGED);
-       format = (flags & BISECT_SHOW_STRINGED) ?
-               "bisect_rev=%s &&\n"
-               "bisect_nr=%d &&\n"
-               "bisect_good=%d &&\n"
-               "bisect_bad=%d &&\n"
-               "bisect_all=%d &&\n"
-               "bisect_steps=%d\n"
-               :
-               "bisect_rev=%s\n"
-               "bisect_nr=%d\n"
-               "bisect_good=%d\n"
-               "bisect_bad=%d\n"
-               "bisect_all=%d\n"
-               "bisect_steps=%d\n";
-       printf(format,
-              hex,
-              cnt - 1,
-              all - reaches - 1,
-              reaches - 1,
-              all,
-              estimate_bisect_steps(all));
+               show_tried_revs(tried);
+
+       print_var_str("bisect_rev", hex);
+       print_var_int("bisect_nr", cnt - 1);
+       print_var_int("bisect_good", all - reaches - 1);
+       print_var_int("bisect_bad", reaches - 1);
+       print_var_int("bisect_all", all);
+       print_var_int("bisect_steps", estimate_bisect_steps(all));
 
        return 0;
 }