@matheusbsbs / matheus-bagliano / commits / 18f7c51cf9
Fork 0

Build-in peek-remote, using transport infrastructure.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Daniel Barkalow committed Oct 29, 2007 at 21:05 UTC 18f7c51cf921f7db021e012499456120f3f095a9
4 files changed +30 -30
Makefile
+2 -1
@@ -239,7 +239,7 @@ PROGRAMS = \
239 git-fast-import$X \
240 git-daemon$X \
241 git-merge-index$X git-mktag$X git-mktree$X git-patch-id$X \
242 - git-peek-remote$X git-receive-pack$X \
242 + git-receive-pack$X \
243 git-send-pack$X git-shell$X \
244 git-show-index$X \
245 git-unpack-file$X \
@@ -352,6 +352,7 @@ BUILTIN_OBJS = \
352 builtin-mv.o \
353 builtin-name-rev.o \
354 builtin-pack-objects.o \
355 + builtin-peek-remote.o \
356 builtin-prune.o \
357 builtin-prune-packed.o \
358 builtin-push.o \
builtin-peek-remote.c renamed
+26 -29
@@ -1,38 +1,26 @@
1 +#include "builtin.h"
2 #include "cache.h"
2 -#include "refs.h"
3 -#include "pkt-line.h"
3 +#include "transport.h"
4 +#include "remote.h"
5
6 static const char peek_remote_usage[] =
7 "git-peek-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
7 -static const char *uploadpack = "git-upload-pack";
8
9 -static int peek_remote(int fd[2], unsigned flags)
9 +int cmd_peek_remote(int argc, const char **argv, const char *prefix)
10 {
11 - struct ref *ref;
12 -
13 - get_remote_heads(fd[0], &ref, 0, NULL, flags);
14 - packet_flush(fd[1]);
15 -
16 - while (ref) {
17 - printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
18 - ref = ref->next;
19 - }
20 - return 0;
21 -}
22 -
23 -int main(int argc, char **argv)
24 -{
25 - int i, ret;
26 - char *dest = NULL;
27 - int fd[2];
28 - struct child_process *conn;
11 + int i;
12 + const char *dest = NULL;
13 int nongit = 0;
14 unsigned flags = 0;
15 + const char *uploadpack = NULL;
16 +
17 + struct transport *transport;
18 + const struct ref *ref;
19
20 setup_git_directory_gently(&nongit);
21
22 for (i = 1; i < argc; i++) {
35 - char *arg = argv[i];
23 + const char *arg = argv[i];
24
25 if (*arg == '-') {
26 if (!prefixcmp(arg, "--upload-pack=")) {
@@ -64,10 +52,19 @@ int main(int argc, char **argv)
52 if (!dest || i != argc - 1)
53 usage(peek_remote_usage);
54
67 - conn = git_connect(fd, dest, uploadpack, 0);
68 - ret = peek_remote(fd, flags);
69 - close(fd[0]);
70 - close(fd[1]);
71 - ret |= finish_connect(conn);
72 - return !!ret;
55 + transport = transport_get(NULL, dest);
56 + if (uploadpack != NULL)
57 + transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
58 +
59 + ref = transport_get_remote_refs(transport);
60 +
61 + if (!ref)
62 + return 1;
63 +
64 + while (ref) {
65 + if (check_ref_type(ref, flags))
66 + printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
67 + ref = ref->next;
68 + }
69 + return 0;
70 }
builtin.h
+1
@@ -55,6 +55,7 @@ extern int cmd_merge_file(int argc, const char **argv, const char *prefix);
55 extern int cmd_mv(int argc, const char **argv, const char *prefix);
56 extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
57 extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
58 +extern int cmd_peek_remote(int argc, const char **argv, const char *prefix);
59 extern int cmd_pickaxe(int argc, const char **argv, const char *prefix);
60 extern int cmd_prune(int argc, const char **argv, const char *prefix);
61 extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
git.c
+1
@@ -333,6 +333,7 @@ static void handle_internal_command(int argc, const char **argv)
333 { "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE },
334 { "name-rev", cmd_name_rev, RUN_SETUP },
335 { "pack-objects", cmd_pack_objects, RUN_SETUP },
336 + { "peek-remote", cmd_peek_remote },
337 { "pickaxe", cmd_blame, RUN_SETUP },
338 { "prune", cmd_prune, RUN_SETUP },
339 { "prune-packed", cmd_prune_packed, RUN_SETUP },