]> git.ipfire.org Git - thirdparty/git.git/blame - rpush.c
[PATCH] diff: Update -B heuristics.
[thirdparty/git.git] / rpush.c
CommitLineData
6eb7ed54
DB
1#include "cache.h"
2#include "rsh.h"
3#include <sys/socket.h>
4#include <errno.h>
5
e99d59ff 6static void service(int fd_in, int fd_out) {
6eb7ed54
DB
7 ssize_t size;
8 int posn;
bf0f910d 9 char unsigned sha1[20];
6eb7ed54
DB
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) {
667bb59b 17 perror("git-rpush: read ");
6eb7ed54
DB
18 return;
19 }
20 if (!size)
21 return;
22 posn += size;
23 } while (posn < 20);
24
25 /* fprintf(stderr, "Serving %s\n", sha1_to_hex(sha1)); */
26
27 buf = map_sha1_file(sha1, &objsize);
28 if (!buf) {
667bb59b 29 fprintf(stderr, "git-rpush: could not find %s\n",
6eb7ed54
DB
30 sha1_to_hex(sha1));
31 return;
32 }
33 posn = 0;
34 do {
35 size = write(fd_out, buf + posn, objsize - posn);
36 if (size <= 0) {
37 if (!size) {
667bb59b 38 fprintf(stderr, "git-rpush: write closed");
6eb7ed54 39 } else {
667bb59b 40 perror("git-rpush: write ");
6eb7ed54
DB
41 }
42 return;
43 }
44 posn += size;
45 } while (posn < objsize);
46 } while (1);
47}
48
49int main(int argc, char **argv)
50{
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++;
57 }
58 if (argc < arg + 2) {
667bb59b 59 usage("git-rpush [-c] [-t] [-a] commit-id url");
6eb7ed54
DB
60 return 1;
61 }
62 commit_id = argv[arg];
63 url = argv[arg + 1];
5210372f 64 if (setup_connection(&fd_in, &fd_out, "git-rpull", url, arg, argv + 1))
6eb7ed54
DB
65 return 1;
66
67 service(fd_in, fd_out);
68 return 0;
69}