Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (54 sloc) 1.577 kb
f96400c @gitster check_everything_connected(): libify
gitster authored
1 #include "cache.h"
2 #include "run-command.h"
3 #include "sigchain.h"
4 #include "connected.h"
5
6 /*
7 * If we feed all the commits we want to verify to this command
8 *
d21c463 @gitster fetch/receive: remove over-pessimistic connectivity check
gitster authored
9 * $ git rev-list --objects --stdin --not --all
f96400c @gitster check_everything_connected(): libify
gitster authored
10 *
11 * and if it does not error out, that means everything reachable from
d21c463 @gitster fetch/receive: remove over-pessimistic connectivity check
gitster authored
12 * these commits locally exists and is connected to our existing refs.
13 * Note that this does _not_ validate the individual objects.
f96400c @gitster check_everything_connected(): libify
gitster authored
14 *
15 * Returns 0 if everything is connected, non-zero otherwise.
16 */
17 int check_everything_connected(sha1_iterate_fn fn, int quiet, void *cb_data)
18 {
19 struct child_process rev_list;
d21c463 @gitster fetch/receive: remove over-pessimistic connectivity check
gitster authored
20 const char *argv[] = {"rev-list", "--objects",
f96400c @gitster check_everything_connected(): libify
gitster authored
21 "--stdin", "--not", "--all", NULL, NULL};
22 char commit[41];
23 unsigned char sha1[20];
24 int err = 0;
25
26 if (fn(cb_data, sha1))
27 return err;
28
29 if (quiet)
30 argv[5] = "--quiet";
31
32 memset(&rev_list, 0, sizeof(rev_list));
33 rev_list.argv = argv;
34 rev_list.git_cmd = 1;
35 rev_list.in = -1;
36 rev_list.no_stdout = 1;
37 rev_list.no_stderr = quiet;
38 if (start_command(&rev_list))
39 return error(_("Could not run 'git rev-list'"));
40
41 sigchain_push(SIGPIPE, SIG_IGN);
42
43 commit[40] = '\n';
44 do {
45 memcpy(commit, sha1_to_hex(sha1), 40);
46 if (write_in_full(rev_list.in, commit, 41) < 0) {
47 if (errno != EPIPE && errno != EINVAL)
48 error(_("failed write to rev-list: %s"),
49 strerror(errno));
50 err = -1;
51 break;
52 }
53 } while (!fn(cb_data, sha1));
54
55 if (close(rev_list.in)) {
56 error(_("failed to close rev-list's stdin: %s"), strerror(errno));
57 err = -1;
58 }
59
60 sigchain_pop(SIGPIPE);
61 return finish_command(&rev_list) || err;
62 }
Something went wrong with that request. Please try again.