connected.c: add new variant that runs with --shallow-file

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 614db3e2920f4d1c79931833614acf36a00fa88b
2 files changed +36 -8
connected.c
+34 -8
@@ -19,17 +19,17 @@ int check_everything_connected(sha1_iterate_fn fn, int quiet, void *cb_data)
19 *
20 * Returns 0 if everything is connected, non-zero otherwise.
21 */
22 -int check_everything_connected_with_transport(sha1_iterate_fn fn,
23 - int quiet,
24 - void *cb_data,
25 - struct transport *transport)
22 +static int check_everything_connected_real(sha1_iterate_fn fn,
23 + int quiet,
24 + void *cb_data,
25 + struct transport *transport,
26 + const char *shallow_file)
27 {
28 struct child_process rev_list;
28 - const char *argv[] = {"rev-list", "--objects",
29 - "--stdin", "--not", "--all", NULL, NULL};
29 + const char *argv[9];
30 char commit[41];
31 unsigned char sha1[20];
32 - int err = 0;
32 + int err = 0, ac = 0;
33 struct packed_git *new_pack = NULL;
34
35 if (fn(cb_data, sha1))
@@ -47,8 +47,18 @@ int check_everything_connected_with_transport(sha1_iterate_fn fn,
47 strbuf_release(&idx_file);
48 }
49
50 + if (shallow_file) {
51 + argv[ac++] = "--shallow-file";
52 + argv[ac++] = shallow_file;
53 + }
54 + argv[ac++] = "rev-list";
55 + argv[ac++] = "--objects";
56 + argv[ac++] = "--stdin";
57 + argv[ac++] = "--not";
58 + argv[ac++] = "--all";
59 if (quiet)
51 - argv[5] = "--quiet";
60 + argv[ac++] = "--quiet";
61 + argv[ac] = NULL;
62
63 memset(&rev_list, 0, sizeof(rev_list));
64 rev_list.argv = argv;
@@ -92,3 +102,19 @@ int check_everything_connected_with_transport(sha1_iterate_fn fn,
102 sigchain_pop(SIGPIPE);
103 return finish_command(&rev_list) || err;
104 }
105 +
106 +int check_everything_connected_with_transport(sha1_iterate_fn fn,
107 + int quiet,
108 + void *cb_data,
109 + struct transport *transport)
110 +{
111 + return check_everything_connected_real(fn, quiet, cb_data,
112 + transport, NULL);
113 +}
114 +
115 +int check_shallow_connected(sha1_iterate_fn fn, int quiet, void *cb_data,
116 + const char *shallow_file)
117 +{
118 + return check_everything_connected_real(fn, quiet, cb_data,
119 + NULL, shallow_file);
120 +}
connected.h
+2
@@ -18,6 +18,8 @@ typedef int (*sha1_iterate_fn)(void *, unsigned char [20]);
18 * Return 0 if Ok, non zero otherwise (i.e. some missing objects)
19 */
20 extern int check_everything_connected(sha1_iterate_fn, int quiet, void *cb_data);
21 +extern int check_shallow_connected(sha1_iterate_fn, int quiet, void *cb_data,
22 + const char *shallow_file);
23 extern int check_everything_connected_with_transport(sha1_iterate_fn, int quiet,
24 void *cb_data,
25 struct transport *transport);