Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connected.c21
-rw-r--r--midx.c8
-rw-r--r--upload-pack.c22
3 files changed, 26 insertions, 25 deletions
diff --git a/connected.c b/connected.c
index 21c1ebe9fb..b18299fdf0 100644
--- a/connected.c
+++ b/connected.c
@@ -22,14 +22,13 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
struct check_connected_options *opt)
{
struct child_process rev_list = CHILD_PROCESS_INIT;
+ FILE *rev_list_in;
struct check_connected_options defaults = CHECK_CONNECTED_INIT;
- char commit[GIT_MAX_HEXSZ + 1];
struct object_id oid;
int err = 0;
struct packed_git *new_pack = NULL;
struct transport *transport;
size_t base_len;
- const unsigned hexsz = the_hash_algo->hexsz;
if (!opt)
opt = &defaults;
@@ -122,7 +121,8 @@ no_promisor_pack_found:
sigchain_push(SIGPIPE, SIG_IGN);
- commit[hexsz] = '\n';
+ rev_list_in = xfdopen(rev_list.in, "w");
+
do {
/*
* If index-pack already checked that:
@@ -135,16 +135,17 @@ no_promisor_pack_found:
if (new_pack && find_pack_entry_one(oid.hash, new_pack))
continue;
- memcpy(commit, oid_to_hex(&oid), hexsz);
- if (write_in_full(rev_list.in, commit, hexsz + 1) < 0) {
- if (errno != EPIPE && errno != EINVAL)
- error_errno(_("failed write to rev-list"));
- err = -1;
+ if (fprintf(rev_list_in, "%s\n", oid_to_hex(&oid)) < 0)
break;
- }
} while (!fn(cb_data, &oid));
- if (close(rev_list.in))
+ if (ferror(rev_list_in) || fflush(rev_list_in)) {
+ if (errno != EPIPE && errno != EINVAL)
+ error_errno(_("failed write to rev-list"));
+ err = -1;
+ }
+
+ if (fclose(rev_list_in))
err = error_errno(_("failed to close rev-list's stdin"));
sigchain_pop(SIGPIPE);
diff --git a/midx.c b/midx.c
index e046d03578..e9b2e1253a 100644
--- a/midx.c
+++ b/midx.c
@@ -1402,6 +1402,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
uint32_t i;
unsigned char *include_pack;
struct child_process cmd = CHILD_PROCESS_INIT;
+ FILE *cmd_in;
struct strbuf base_name = STRBUF_INIT;
struct multi_pack_index *m = load_multi_pack_index(object_dir, 1);
@@ -1454,6 +1455,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
goto cleanup;
}
+ cmd_in = xfdopen(cmd.in, "w");
+
for (i = 0; i < m->num_objects; i++) {
struct object_id oid;
uint32_t pack_int_id = nth_midxed_pack_int_id(m, i);
@@ -1462,10 +1465,9 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
continue;
nth_midxed_object_oid(&oid, m, i);
- xwrite(cmd.in, oid_to_hex(&oid), the_hash_algo->hexsz);
- xwrite(cmd.in, "\n", 1);
+ fprintf(cmd_in, "%s\n", oid_to_hex(&oid));
}
- close(cmd.in);
+ fclose(cmd_in);
if (finish_command(&cmd)) {
error(_("could not finish pack-objects"));
diff --git a/upload-pack.c b/upload-pack.c
index 46a5cac0a9..3b858eb457 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -603,9 +603,8 @@ static int do_reachable_revlist(struct child_process *cmd,
"rev-list", "--stdin", NULL,
};
struct object *o;
- char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
+ FILE *cmd_in = NULL;
int i;
- const unsigned hexsz = the_hash_algo->hexsz;
cmd->argv = argv;
cmd->git_cmd = 1;
@@ -623,8 +622,8 @@ static int do_reachable_revlist(struct child_process *cmd,
if (start_command(cmd))
goto error;
- namebuf[0] = '^';
- namebuf[hexsz + 1] = '\n';
+ cmd_in = xfdopen(cmd->in, "w");
+
for (i = get_max_object_index(); 0 < i; ) {
o = get_indexed_object(--i);
if (!o)
@@ -633,11 +632,9 @@ static int do_reachable_revlist(struct child_process *cmd,
o->flags &= ~TMP_MARK;
if (!is_our_ref(o, allow_uor))
continue;
- memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
- if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
+ if (fprintf(cmd_in, "^%s\n", oid_to_hex(&o->oid)) < 0)
goto error;
}
- namebuf[hexsz] = '\n';
for (i = 0; i < src->nr; i++) {
o = src->objects[i].item;
if (is_our_ref(o, allow_uor)) {
@@ -647,11 +644,12 @@ static int do_reachable_revlist(struct child_process *cmd,
}
if (reachable && o->type == OBJ_COMMIT)
o->flags |= TMP_MARK;
- memcpy(namebuf, oid_to_hex(&o->oid), hexsz);
- if (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)
+ if (fprintf(cmd_in, "%s\n", oid_to_hex(&o->oid)) < 0)
goto error;
}
- close(cmd->in);
+ if (ferror(cmd_in) || fflush(cmd_in))
+ goto error;
+ fclose(cmd_in);
cmd->in = -1;
sigchain_pop(SIGPIPE);
@@ -660,8 +658,8 @@ static int do_reachable_revlist(struct child_process *cmd,
error:
sigchain_pop(SIGPIPE);
- if (cmd->in >= 0)
- close(cmd->in);
+ if (cmd_in)
+ fclose(cmd_in);
if (cmd->out >= 0)
close(cmd->out);
return -1;