shallow.c: extend setup_*_shallow() to accept extra shallow commits

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 Dec 5, 2013 at 20:02 UTC 1a30f5a2f2a3d5d9b3cf6e126ac19deb40324515
4 files changed +24 -11
commit.h
+5 -3
@@ -201,10 +201,12 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
201 int depth, int shallow_flag, int not_shallow_flag);
202 extern void check_shallow_file_for_update(void);
203 extern void set_alternate_shallow_file(const char *path);
204 -extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol);
204 +extern int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
205 + const struct sha1_array *extra);
206 extern void setup_alternate_shallow(struct lock_file *shallow_lock,
206 - const char **alternate_shallow_file);
207 -extern char *setup_temporary_shallow(void);
207 + const char **alternate_shallow_file,
208 + const struct sha1_array *extra);
209 +extern char *setup_temporary_shallow(const struct sha1_array *extra);
210 extern void advertise_shallow_grafts(int);
211
212 int is_descendant_of(struct commit *, struct commit_list *);
fetch-pack.c
+3 -2
@@ -311,7 +311,7 @@ static int find_common(struct fetch_pack_args *args,
311 }
312
313 if (is_repository_shallow())
314 - write_shallow_commits(&req_buf, 1);
314 + write_shallow_commits(&req_buf, 1, NULL);
315 if (args->depth > 0)
316 packet_buf_write(&req_buf, "deepen %d", args->depth);
317 packet_buf_flush(&req_buf);
@@ -850,7 +850,8 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
850 if (args->stateless_rpc)
851 packet_flush(fd[1]);
852 if (args->depth > 0)
853 - setup_alternate_shallow(&shallow_lock, &alternate_shallow_file);
853 + setup_alternate_shallow(&shallow_lock, &alternate_shallow_file,
854 + NULL);
855 else
856 alternate_shallow_file = NULL;
857 if (get_pack(args, fd, pack_lockfile))
shallow.c
+15 -5
@@ -165,22 +165,31 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
165 return 0;
166 }
167
168 -int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
168 +int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
169 + const struct sha1_array *extra)
170 {
171 struct write_shallow_data data;
172 + int i;
173 data.out = out;
174 data.use_pack_protocol = use_pack_protocol;
175 data.count = 0;
176 for_each_commit_graft(write_one_shallow, &data);
177 + if (!extra)
178 + return data.count;
179 + for (i = 0; i < extra->nr; i++) {
180 + strbuf_addstr(out, sha1_to_hex(extra->sha1[i]));
181 + strbuf_addch(out, '\n');
182 + data.count++;
183 + }
184 return data.count;
185 }
186
178 -char *setup_temporary_shallow(void)
187 +char *setup_temporary_shallow(const struct sha1_array *extra)
188 {
189 struct strbuf sb = STRBUF_INIT;
190 int fd;
191
183 - if (write_shallow_commits(&sb, 0)) {
192 + if (write_shallow_commits(&sb, 0, extra)) {
193 struct strbuf path = STRBUF_INIT;
194 strbuf_addstr(&path, git_path("shallow_XXXXXX"));
195 fd = xmkstemp(path.buf);
@@ -199,7 +208,8 @@ char *setup_temporary_shallow(void)
208 }
209
210 void setup_alternate_shallow(struct lock_file *shallow_lock,
202 - const char **alternate_shallow_file)
211 + const char **alternate_shallow_file,
212 + const struct sha1_array *extra)
213 {
214 struct strbuf sb = STRBUF_INIT;
215 int fd;
@@ -207,7 +217,7 @@ void setup_alternate_shallow(struct lock_file *shallow_lock,
217 check_shallow_file_for_update();
218 fd = hold_lock_file_for_update(shallow_lock, git_path("shallow"),
219 LOCK_DIE_ON_ERROR);
210 - if (write_shallow_commits(&sb, 0)) {
220 + if (write_shallow_commits(&sb, 0, extra)) {
221 if (write_in_full(fd, sb.buf, sb.len) != sb.len)
222 die_errno("failed to write to %s",
223 shallow_lock->filename);
upload-pack.c
+1 -1
@@ -84,7 +84,7 @@ static void create_pack_file(void)
84 char *shallow_file = NULL;
85
86 if (shallow_nr) {
87 - shallow_file = setup_temporary_shallow();
87 + shallow_file = setup_temporary_shallow(NULL);
88 argv[arg++] = "--shallow-file";
89 argv[arg++] = shallow_file;
90 }