Add for_each_commit_graft() to iterate all grafts

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 18, 2011 at 19:29 UTC 09d46644b780ede1a6b757db3e1a1ae9c1128a13
2 files changed +10
commit.c
+8
@@ -214,6 +214,14 @@ struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
214 return commit_graft[pos];
215 }
216
217 +int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
218 +{
219 + int i, ret;
220 + for (i = ret = 0; i < commit_graft_nr && !ret; i++)
221 + ret = fn(commit_graft[i], cb_data);
222 + return ret;
223 +}
224 +
225 int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
226 {
227 int i, count = 0;
commit.h
+2
@@ -142,6 +142,7 @@ struct commit_graft {
142 int nr_parent; /* < 0 if shallow commit */
143 unsigned char parent[FLEX_ARRAY][20]; /* more */
144 };
145 +typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
146
147 struct commit_graft *read_graft_line(char *buf, int len);
148 int register_commit_graft(struct commit_graft *, int);
@@ -154,6 +155,7 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
155 extern int register_shallow(const unsigned char *sha1);
156 extern int unregister_shallow(const unsigned char *sha1);
157 extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
158 +extern int for_each_commit_graft(each_commit_graft_fn, void *);
159 extern int is_repository_shallow(void);
160 extern struct commit_list *get_shallow_commits(struct object_array *heads,
161 int depth, int shallow_flag, int not_shallow_flag);