5 unsigned char local_version
= 1;
6 unsigned char remote_version
= 0;
8 int serve_object(int fd_in
, int fd_out
) {
12 unsigned long objsize
;
16 size
= read(fd_in
, sha1
+ posn
, 20 - posn
);
18 perror("git-ssh-push: read ");
26 /* fprintf(stderr, "Serving %s\n", sha1_to_hex(sha1)); */
29 buf
= map_sha1_file(sha1
, &objsize
);
32 fprintf(stderr
, "git-ssh-push: could not find %s\n",
37 write(fd_out
, &remote
, 1);
44 size
= write(fd_out
, buf
+ posn
, objsize
- posn
);
47 fprintf(stderr
, "git-ssh-push: write closed");
49 perror("git-ssh-push: write ");
54 } while (posn
< objsize
);
58 int serve_version(int fd_in
, int fd_out
)
60 if (read(fd_in
, &remote_version
, 1) < 1)
62 write(fd_out
, &local_version
, 1);
66 int serve_ref(int fd_in
, int fd_out
)
69 unsigned char sha1
[20];
71 signed char remote
= 0;
73 if (read(fd_in
, ref
+ posn
, 1) < 1)
76 } while (ref
[posn
- 1]);
77 if (get_ref_sha1(ref
, sha1
))
79 write(fd_out
, &remote
, 1);
82 write(fd_out
, sha1
, 20);
87 void service(int fd_in
, int fd_out
) {
91 retval
= read(fd_in
, &type
, 1);
94 perror("git-ssh-push: read ");
97 if (type
== 'v' && serve_version(fd_in
, fd_out
))
99 if (type
== 'o' && serve_object(fd_in
, fd_out
))
101 if (type
== 'r' && serve_ref(fd_in
, fd_out
))
106 int main(int argc
, char **argv
)
112 while (arg
< argc
&& argv
[arg
][0] == '-') {
113 if (argv
[arg
][1] == 'w')
117 if (argc
< arg
+ 2) {
118 usage("git-ssh-push [-c] [-t] [-a] [-w ref] commit-id url");
121 commit_id
= argv
[arg
];
123 if (setup_connection(&fd_in
, &fd_out
, "git-ssh-pull", url
, arg
, argv
+ 1))
126 service(fd_in
, fd_out
);