Merge branch 'nd/decorate-grafts'
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Aug 2011 04:22:58 +0000 (21:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Aug 2011 04:22:58 +0000 (21:22 -0700)
* nd/decorate-grafts:
log: Do not decorate replacements with --no-replace-objects
log: decorate "replaced" on to replaced commits
log: decorate grafted commits with "grafted"
Move write_shallow_commits to fetch-pack.c
Add for_each_commit_graft() to iterate all grafts
decoration: do not mis-decorate refs with same prefix

1  2 
builtin/fetch-pack.c
commit.c
log-tree.c
diff --combined builtin/fetch-pack.c
index 3c871c2da893dc9deb3a36bff03a7032ea038f8a,cb5b20ae08e4e30a009146339ec790ef742bf783..412bd327b5b396c159c768b25be189e00531c38e
@@@ -185,6 -185,36 +185,36 @@@ static void consume_shallow_list(int fd
        }
  }
  
+ struct write_shallow_data {
+       struct strbuf *out;
+       int use_pack_protocol;
+       int count;
+ };
+ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
+ {
+       struct write_shallow_data *data = cb_data;
+       const char *hex = sha1_to_hex(graft->sha1);
+       data->count++;
+       if (data->use_pack_protocol)
+               packet_buf_write(data->out, "shallow %s", hex);
+       else {
+               strbuf_addstr(data->out, hex);
+               strbuf_addch(data->out, '\n');
+       }
+       return 0;
+ }
+ static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
+ {
+       struct write_shallow_data data;
+       data.out = out;
+       data.use_pack_protocol = use_pack_protocol;
+       data.count = 0;
+       for_each_commit_graft(write_one_shallow, &data);
+       return data.count;
+ }
  static enum ack_type get_ack(int fd, unsigned char *result_sha1)
  {
        static char line[1000];
@@@ -395,8 -425,6 +425,8 @@@ static int find_common(int fd[2], unsig
                                case ACK_continue: {
                                        struct commit *commit =
                                                lookup_commit(result_sha1);
 +                                      if (!commit)
 +                                              die("invalid commit %s", sha1_to_hex(result_sha1));
                                        if (args.stateless_rpc
                                         && ack == ACK_common
                                         && !(commit->object.flags & COMMON)) {
diff --combined commit.c
index 913dbabd1c12772d574f5814f73a12ed6bd4a9da,f271f590a1b55f51e4de87191dc137e65336d0ea..97b43279cdf46159462d5f56abc20f2161f4c7ea
+++ b/commit.c
@@@ -214,22 -214,12 +214,12 @@@ struct commit_graft *lookup_commit_graf
        return commit_graft[pos];
  }
  
- int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
+ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
  {
-       int i, count = 0;
-       for (i = 0; i < commit_graft_nr; i++)
-               if (commit_graft[i]->nr_parent < 0) {
-                       const char *hex =
-                               sha1_to_hex(commit_graft[i]->sha1);
-                       count++;
-                       if (use_pack_protocol)
-                               packet_buf_write(out, "shallow %s", hex);
-                       else {
-                               strbuf_addstr(out, hex);
-                               strbuf_addch(out, '\n');
-                       }
-               }
-       return count;
+       int i, ret;
+       for (i = ret = 0; i < commit_graft_nr && !ret; i++)
+               ret = fn(commit_graft[i], cb_data);
+       return ret;
  }
  
  int unregister_shallow(const unsigned char *sha1)
@@@ -515,7 -505,7 +505,7 @@@ void sort_in_topological_order(struct c
  
                commit = work_item->item;
                for (parents = commit->parents; parents ; parents = parents->next) {
 -                      struct commit *parent=parents->item;
 +                      struct commit *parent = parents->item;
  
                        if (!parent->indegree)
                                continue;
diff --combined log-tree.c
index 95d6d4080e2eeee6725efc458134ea493ac4c06a,c40fa50c6f8f65f119bc178646f31dace865191a..24c295ea1dc91180b9685299f48812593162bdfe
@@@ -18,6 -18,7 +18,7 @@@ enum decoration_type 
        DECORATION_REF_TAG,
        DECORATION_REF_STASH,
        DECORATION_REF_HEAD,
+       DECORATION_GRAFTED,
  };
  
  static char decoration_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_BOLD_YELLOW,  /* REF_TAG */
        GIT_COLOR_BOLD_MAGENTA, /* REF_STASH */
        GIT_COLOR_BOLD_CYAN,    /* REF_HEAD */
+       GIT_COLOR_BOLD_BLUE,    /* GRAFTED */
  };
  
  static const char *decorate_get_color(int decorate_use_color, enum decoration_type ix)
  {
 -      if (decorate_use_color)
 +      if (want_color(decorate_use_color))
                return decoration_colors[ix];
        return "";
  }
@@@ -77,7 -79,7 +79,7 @@@ int parse_decorate_color_config(const c
   * for showing the commit sha1, use the same check for --decorate
   */
  #define decorate_get_color_opt(o, ix) \
 -      decorate_get_color(DIFF_OPT_TST((o), COLOR_DIFF), ix)
 +      decorate_get_color((o)->use_color, ix)
  
  static void add_name_decoration(enum decoration_type type, const char *name, struct object *obj)
  {
  
  static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
  {
-       struct object *obj = parse_object(sha1);
+       struct object *obj;
        enum decoration_type type = DECORATION_NONE;
+       if (!prefixcmp(refname, "refs/replace/")) {
+               unsigned char original_sha1[20];
+               if (!read_replace_refs)
+                       return 0;
+               if (get_sha1_hex(refname + 13, original_sha1)) {
+                       warning("invalid replace ref %s", refname);
+                       return 0;
+               }
+               obj = parse_object(original_sha1);
+               if (obj)
+                       add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
+               return 0;
+       }
+       obj = parse_object(sha1);
        if (!obj)
                return 0;
  
-       if (!prefixcmp(refname, "refs/heads"))
+       if (!prefixcmp(refname, "refs/heads/"))
                type = DECORATION_REF_LOCAL;
-       else if (!prefixcmp(refname, "refs/remotes"))
+       else if (!prefixcmp(refname, "refs/remotes/"))
                type = DECORATION_REF_REMOTE;
-       else if (!prefixcmp(refname, "refs/tags"))
+       else if (!prefixcmp(refname, "refs/tags/"))
                type = DECORATION_REF_TAG;
        else if (!prefixcmp(refname, "refs/stash"))
                type = DECORATION_REF_STASH;
        return 0;
  }
  
+ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)
+ {
+       struct commit *commit = lookup_commit(graft->sha1);
+       if (!commit)
+               return 0;
+       add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object);
+       return 0;
+ }
  void load_ref_decorations(int flags)
  {
        static int loaded;
                loaded = 1;
                for_each_ref(add_ref_decoration, &flags);
                head_ref(add_ref_decoration, &flags);
+               for_each_commit_graft(add_graft_decoration, NULL);
        }
  }