[PATCH] Reactivate show-diff patch generation
[git/gitweb.git] / rpush.c
blob0293a1a46311d7e20b13177143741ab9d6d0d201
1 #include "cache.h"
2 #include "rsh.h"
3 #include <sys/socket.h>
4 #include <errno.h>
6 void service(int fd_in, int fd_out) {
7 ssize_t size;
8 int posn;
9 char sha1[20];
10 unsigned long objsize;
11 void *buf;
12 do {
13 posn = 0;
14 do {
15 size = read(fd_in, sha1 + posn, 20 - posn);
16 if (size < 0) {
17 perror("rpush: read ");
18 return;
20 if (!size)
21 return;
22 posn += size;
23 } while (posn < 20);
25 /* fprintf(stderr, "Serving %s\n", sha1_to_hex(sha1)); */
27 buf = map_sha1_file(sha1, &objsize);
28 if (!buf) {
29 fprintf(stderr, "rpush: could not find %s\n",
30 sha1_to_hex(sha1));
31 return;
33 posn = 0;
34 do {
35 size = write(fd_out, buf + posn, objsize - posn);
36 if (size <= 0) {
37 if (!size) {
38 fprintf(stderr, "rpush: write closed");
39 } else {
40 perror("rpush: write ");
42 return;
44 posn += size;
45 } while (posn < objsize);
46 } while (1);
49 int main(int argc, char **argv)
51 int arg = 1;
52 char *commit_id;
53 char *url;
54 int fd_in, fd_out;
55 while (arg < argc && argv[arg][0] == '-') {
56 arg++;
58 if (argc < arg + 2) {
59 usage("rpush [-c] [-t] [-a] commit-id url");
60 return 1;
62 commit_id = argv[arg];
63 url = argv[arg + 1];
64 if (setup_connection(&fd_in, &fd_out, "rpull", url, arg, argv + 1))
65 return 1;
67 service(fd_in, fd_out);
68 return 0;