Skip to content

Commit 294e15f

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 09d4664 commit 294e15f

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

builtin/fetch-pack.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,36 @@ static void consume_shallow_list(int fd)
185185
}
186186
}
187187

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+
188218
static enum ack_type get_ack(int fd, unsigned char *result_sha1)
189219
{
190220
static char line[1000];

commit.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
222222
return ret;
223223
}
224224

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-
243225
int unregister_shallow(const unsigned char *sha1)
244226
{
245227
int pos = commit_graft_pos(sha1);

commit.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
154154

155155
extern int register_shallow(const unsigned char *sha1);
156156
extern int unregister_shallow(const unsigned char *sha1);
157-
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
158157
extern int for_each_commit_graft(each_commit_graft_fn, void *);
159158
extern int is_repository_shallow(void);
160159
extern struct commit_list *get_shallow_commits(struct object_array *heads,

0 commit comments

Comments
 (0)