return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
}
-static void check_non_tip(void)
+static int has_unreachable(struct object_array *src)
{
static const char *argv[] = {
"rev-list", "--stdin", NULL,
char namebuf[42]; /* ^ + SHA-1 + LF */
int i;
- /*
- * In the normal in-process case without
- * uploadpack.allowReachableSHA1InWant,
- * non-tip requests can never happen.
- */
- if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
- goto error;
-
cmd.argv = argv;
cmd.git_cmd = 1;
cmd.no_stderr = 1;
cmd.in = -1;
cmd.out = -1;
- if (start_command(&cmd))
- goto error;
-
/*
- * If rev-list --stdin encounters an unknown commit, it
- * terminates, which will cause SIGPIPE in the write loop
+ * If the next rev-list --stdin encounters an unknown commit,
+ * it terminates, which will cause SIGPIPE in the write loop
* below.
*/
sigchain_push(SIGPIPE, SIG_IGN);
+ if (start_command(&cmd))
+ goto error;
+
namebuf[0] = '^';
namebuf[41] = '\n';
for (i = get_max_object_index(); 0 < i; ) {
goto error;
}
namebuf[40] = '\n';
- for (i = 0; i < want_obj.nr; i++) {
- o = want_obj.objects[i].item;
+ for (i = 0; i < src->nr; i++) {
+ o = src->objects[i].item;
if (is_our_ref(o))
continue;
memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
goto error;
}
close(cmd.in);
-
- sigchain_pop(SIGPIPE);
+ cmd.in = -1;
/*
* The commits out of the rev-list are not ancestors of
if (i)
goto error;
close(cmd.out);
+ cmd.out = -1;
/*
* rev-list may have died by encountering a bad commit
if (finish_command(&cmd))
goto error;
+ sigchain_pop(SIGPIPE);
+
/* All the non-tip ones are ancestors of what we advertised */
- return;
+ return 0;
+
+error:
+ sigchain_pop(SIGPIPE);
+
+ if (cmd.in >= 0)
+ close(cmd.in);
+ if (cmd.out >= 0)
+ close(cmd.out);
+ return 1;
+}
+
+static void check_non_tip(void)
+{
+ int i;
+
+ /*
+ * In the normal in-process case without
+ * uploadpack.allowReachableSHA1InWant,
+ * non-tip requests can never happen.
+ */
+ if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
+ goto error;
+ if (!has_unreachable(&want_obj))
+ /* All the non-tip ones are ancestors of what we advertised */
+ return;
error:
/* Pick one of them (we know there at least is one) */
for (i = 0; i < want_obj.nr; i++) {
- o = want_obj.objects[i].item;
+ struct object *o = want_obj.objects[i].item;
if (!is_our_ref(o))
die("git upload-pack: not our ref %s",
oid_to_hex(&o->oid));
continue;
}
if (skip_prefix(line, "deepen ", &arg)) {
- char *end;
+ char *end = NULL;
depth = strtol(arg, &end, 0);
- if (end == arg || depth <= 0)
+ if (!end || *end || depth <= 0)
die("Invalid deepen: %s", line);
continue;
}