3 #include <sys/socket.h>
6 unsigned char local_version
= 1;
7 unsigned char remote_version
= 0;
9 int serve_object(int fd_in
, int fd_out
) {
13 unsigned long objsize
;
17 size
= read(fd_in
, sha1
+ posn
, 20 - posn
);
19 perror("git-rpush: read ");
27 /* fprintf(stderr, "Serving %s\n", sha1_to_hex(sha1)); */
30 buf
= map_sha1_file(sha1
, &objsize
);
33 fprintf(stderr
, "git-rpush: could not find %s\n",
38 write(fd_out
, &remote
, 1);
45 size
= write(fd_out
, buf
+ posn
, objsize
- posn
);
48 fprintf(stderr
, "git-rpush: write closed");
50 perror("git-rpush: write ");
55 } while (posn
< objsize
);
59 int serve_version(int fd_in
, int fd_out
)
61 if (read(fd_in
, &remote_version
, 1) < 1)
63 write(fd_out
, &local_version
, 1);
67 void service(int fd_in
, int fd_out
) {
71 retval
= read(fd_in
, &type
, 1);
74 perror("rpush: read ");
77 if (type
== 'v' && serve_version(fd_in
, fd_out
))
79 if (type
== 'o' && serve_object(fd_in
, fd_out
))
84 int main(int argc
, char **argv
)
90 while (arg
< argc
&& argv
[arg
][0] == '-') {
94 usage("git-rpush [-c] [-t] [-a] commit-id url");
97 commit_id
= argv
[arg
];
99 if (setup_connection(&fd_in
, &fd_out
, "git-rpull", url
, arg
, argv
+ 1))
102 service(fd_in
, fd_out
);