ident.c: add split_ident_line() to parse formatted ident line
[git/gitweb.git] / connected.c
blobd7624230d435ded5ef7ba126ef77ab0e888af19b
1 #include "cache.h"
2 #include "run-command.h"
3 #include "sigchain.h"
4 #include "connected.h"
6 /*
7 * If we feed all the commits we want to verify to this command
9 * $ git rev-list --verify-objects --stdin --not --all
11 * and if it does not error out, that means everything reachable from
12 * these commits locally exists and is connected to some of our
13 * existing refs.
15 * Returns 0 if everything is connected, non-zero otherwise.
17 int check_everything_connected(sha1_iterate_fn fn, int quiet, void *cb_data)
19 struct child_process rev_list;
20 const char *argv[] = {"rev-list", "--verify-objects",
21 "--stdin", "--not", "--all", NULL, NULL};
22 char commit[41];
23 unsigned char sha1[20];
24 int err = 0;
26 if (fn(cb_data, sha1))
27 return err;
29 if (quiet)
30 argv[5] = "--quiet";
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'"));
41 sigchain_push(SIGPIPE, SIG_IGN);
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;
53 } while (!fn(cb_data, sha1));
55 if (close(rev_list.in)) {
56 error(_("failed to close rev-list's stdin: %s"), strerror(errno));
57 err = -1;
60 sigchain_pop(SIGPIPE);
61 return finish_command(&rev_list) || err;