Skip to content

Commit 1e274ef

Browse files
committed
Merge branch 'jk/send-pack-stdio' into maint
Code clean-up. * jk/send-pack-stdio: write_or_die: remove the unused write_or_whine() function send-pack: use buffered I/O to talk to pack-objects
2 parents a220e2b + b333d0d commit 1e274ef

File tree

3 files changed

+16
-29
lines changed

3 files changed

+16
-29
lines changed

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,6 @@ extern int copy_file(const char *dst, const char *src, int mode);
17211721
extern int copy_file_with_time(const char *dst, const char *src, int mode);
17221722

17231723
extern void write_or_die(int fd, const void *buf, size_t count);
1724-
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
17251724
extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
17261725
extern void fsync_or_die(int fd, const char *);
17271726

send-pack.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@ int option_parse_push_signed(const struct option *opt,
3636
die("bad %s argument: %s", opt->long_name, arg);
3737
}
3838

39-
static int feed_object(const unsigned char *sha1, int fd, int negative)
39+
static void feed_object(const unsigned char *sha1, FILE *fh, int negative)
4040
{
41-
char buf[42];
42-
4341
if (negative && !has_sha1_file(sha1))
44-
return 1;
42+
return;
4543

46-
memcpy(buf + negative, sha1_to_hex(sha1), 40);
4744
if (negative)
48-
buf[0] = '^';
49-
buf[40 + negative] = '\n';
50-
return write_or_whine(fd, buf, 41 + negative, "send-pack: send refs");
45+
putc('^', fh);
46+
fputs(sha1_to_hex(sha1), fh);
47+
putc('\n', fh);
5148
}
5249

5350
/*
@@ -73,6 +70,7 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
7370
NULL,
7471
};
7572
struct child_process po = CHILD_PROCESS_INIT;
73+
FILE *po_in;
7674
int i;
7775

7876
i = 4;
@@ -97,21 +95,22 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
9795
* We feed the pack-objects we just spawned with revision
9896
* parameters by writing to the pipe.
9997
*/
98+
po_in = xfdopen(po.in, "w");
10099
for (i = 0; i < extra->nr; i++)
101-
if (!feed_object(extra->sha1[i], po.in, 1))
102-
break;
100+
feed_object(extra->sha1[i], po_in, 1);
103101

104102
while (refs) {
105-
if (!is_null_oid(&refs->old_oid) &&
106-
!feed_object(refs->old_oid.hash, po.in, 1))
107-
break;
108-
if (!is_null_oid(&refs->new_oid) &&
109-
!feed_object(refs->new_oid.hash, po.in, 0))
110-
break;
103+
if (!is_null_oid(&refs->old_oid))
104+
feed_object(refs->old_oid.hash, po_in, 1);
105+
if (!is_null_oid(&refs->new_oid))
106+
feed_object(refs->new_oid.hash, po_in, 0);
111107
refs = refs->next;
112108
}
113109

114-
close(po.in);
110+
fflush(po_in);
111+
if (ferror(po_in))
112+
die_errno("error writing to pack-objects");
113+
fclose(po_in);
115114

116115
if (args->stateless_rpc) {
117116
char *buf = xmalloc(LARGE_PACKET_MAX);

write_or_die.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,3 @@ int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg)
9494

9595
return 1;
9696
}
97-
98-
int write_or_whine(int fd, const void *buf, size_t count, const char *msg)
99-
{
100-
if (write_in_full(fd, buf, count) < 0) {
101-
fprintf(stderr, "%s: write error (%s)\n",
102-
msg, strerror(errno));
103-
return 0;
104-
}
105-
106-
return 1;
107-
}

0 commit comments

Comments
 (0)