Move write_shallow_commits to fetch-pack.c
This function produces network traffic and should be in fetch-pack. It has been in commit.c because it needs to iterate (private) graft list. It can now do so using for_each_commit_graft(). 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
294e15fc19b5ba370b703d003920d000a4f5547a
3 files changed
+30
-19
builtin/fetch-pack.c
+30
@@ -185,6 +185,36 @@ static void consume_shallow_list(int fd)
185
}
186
}
187
188
+struct write_shallow_data {
189
+ struct strbuf *out;
190
+ int use_pack_protocol;
191
+ int count;
192
+};
193
+
194
+static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
195
+{
196
+ struct write_shallow_data *data = cb_data;
197
+ const char *hex = sha1_to_hex(graft->sha1);
198
+ data->count++;
199
+ if (data->use_pack_protocol)
200
+ packet_buf_write(data->out, "shallow %s", hex);
201
+ else {
202
+ strbuf_addstr(data->out, hex);
203
+ strbuf_addch(data->out, '\n');
204
+ }
205
+ return 0;
206
+}
207
+
208
+static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
209
+{
210
+ struct write_shallow_data data;
211
+ data.out = out;
212
+ data.use_pack_protocol = use_pack_protocol;
213
+ data.count = 0;
214
+ for_each_commit_graft(write_one_shallow, &data);
215
+ return data.count;
216
+}
217
+
218
static enum ack_type get_ack(int fd, unsigned char *result_sha1)
219
{
220
static char line[1000];
commit.c
-18
@@ -222,24 +222,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *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;
228
- for (i = 0; i < commit_graft_nr; i++)
229
- if (commit_graft[i]->nr_parent < 0) {
230
- const char *hex =
231
- sha1_to_hex(commit_graft[i]->sha1);
232
- count++;
233
- if (use_pack_protocol)
234
- packet_buf_write(out, "shallow %s", hex);
235
- else {
236
- strbuf_addstr(out, hex);
237
- strbuf_addch(out, '\n');
238
- }
239
- }
240
- return count;
241
-}
242
-
225
int unregister_shallow(const unsigned char *sha1)
226
{
227
int pos = commit_graft_pos(sha1);
commit.h
-1
@@ -154,7 +154,6 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
154
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);
157
extern int for_each_commit_graft(each_commit_graft_fn, void *);
158
extern int is_repository_shallow(void);
159
extern struct commit_list *get_shallow_commits(struct object_array *heads,