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>
This commit is contained in:
parent
09d46644b7
commit
294e15fc19
@ -185,6 +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 enum ack_type get_ack(int fd, unsigned char *result_sha1)
|
||||||
{
|
{
|
||||||
static char line[1000];
|
static char line[1000];
|
||||||
|
18
commit.c
18
commit.c
@ -222,24 +222,6 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
|
|
||||||
{
|
|
||||||
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 unregister_shallow(const unsigned char *sha1)
|
int unregister_shallow(const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
int pos = commit_graft_pos(sha1);
|
int pos = commit_graft_pos(sha1);
|
||||||
|
1
commit.h
1
commit.h
@ -154,7 +154,6 @@ extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
|
|||||||
|
|
||||||
extern int register_shallow(const unsigned char *sha1);
|
extern int register_shallow(const unsigned char *sha1);
|
||||||
extern int unregister_shallow(const unsigned char *sha1);
|
extern int unregister_shallow(const unsigned char *sha1);
|
||||||
extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
|
|
||||||
extern int for_each_commit_graft(each_commit_graft_fn, void *);
|
extern int for_each_commit_graft(each_commit_graft_fn, void *);
|
||||||
extern int is_repository_shallow(void);
|
extern int is_repository_shallow(void);
|
||||||
extern struct commit_list *get_shallow_commits(struct object_array *heads,
|
extern struct commit_list *get_shallow_commits(struct object_array *heads,
|
||||||
|
Loading…
Reference in New Issue
Block a user