diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-07-08 18:55:50 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-07-08 18:55:50 -0700 |
commit | 037c43c68e220739e690540de89a6d5835fefe73 (patch) | |
tree | 3e201f833fc63e48db6983e45ce2425d884408db /builtin/ls-remote.c | |
parent | b1f47514f207b0601de7b0936cf13b3c0ae70081 (diff) | |
parent | 9918285fb10d81af9021dae99c5f4de88ded497c (diff) | |
download | git-037c43c68e220739e690540de89a6d5835fefe73.tar.gz |
Merge remote branch 'ko/master' into jc/read-tree-cache-tree-fix
* ko/master: (2325 commits)
Git 1.7.2-rc2
backmerge a few more fixes to 1.7.1.X series
fix git branch -m in presence of cross devices
t/t0006: specify timezone as EST5 not EST to comply with POSIX
add missing && to submodule-merge testcase
t/README: document more test helpers
test-date: fix sscanf type conversion
xdiff: optimise for no whitespace difference when ignoring whitespace.
gitweb: Move evaluate_gitweb_config out of run_request
parse_date: fix signedness in timezone calculation
t0006: test timezone parsing
rerere.txt: Document forget subcommand
t/README: proposed rewording...
t/README: Document the do's and don'ts of tests
t/README: Add a section about skipping tests
t/README: Document test_expect_code
t/README: Document test_external*
t/README: Document the prereq functions, and 3-arg test_*
t/README: Typo: paralell -> parallel
t/README: The trash is in 't/trash directory.$name'
...
Conflicts:
builtin-read-tree.c
Diffstat (limited to 'builtin/ls-remote.c')
-rw-r--r-- | builtin/ls-remote.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c new file mode 100644 index 0000000000..34480cfad6 --- /dev/null +++ b/builtin/ls-remote.c @@ -0,0 +1,118 @@ +#include "builtin.h" +#include "cache.h" +#include "transport.h" +#include "remote.h" + +static const char ls_remote_usage[] = +"git ls-remote [--heads] [--tags] [-u <exec> | --upload-pack <exec>]\n" +" [-q|--quiet] [<repository> [<refs>...]]"; + +/* + * Is there one among the list of patterns that match the tail part + * of the path? + */ +static int tail_match(const char **pattern, const char *path) +{ + const char *p; + char pathbuf[PATH_MAX]; + + if (!pattern) + return 1; /* no restriction */ + + if (snprintf(pathbuf, sizeof(pathbuf), "/%s", path) > sizeof(pathbuf)) + return error("insanely long ref %.*s...", 20, path); + while ((p = *(pattern++)) != NULL) { + if (!fnmatch(p, pathbuf, 0)) + return 1; + } + return 0; +} + +int cmd_ls_remote(int argc, const char **argv, const char *prefix) +{ + int i; + const char *dest = NULL; + int nongit; + unsigned flags = 0; + int quiet = 0; + const char *uploadpack = NULL; + const char **pattern = NULL; + + struct remote *remote; + struct transport *transport; + const struct ref *ref; + + setup_git_directory_gently(&nongit); + + for (i = 1; i < argc; i++) { + const char *arg = argv[i]; + + if (*arg == '-') { + if (!prefixcmp(arg, "--upload-pack=")) { + uploadpack = arg + 14; + continue; + } + if (!prefixcmp(arg, "--exec=")) { + uploadpack = arg + 7; + continue; + } + if (!strcmp("--tags", arg) || !strcmp("-t", arg)) { + flags |= REF_TAGS; + continue; + } + if (!strcmp("--heads", arg) || !strcmp("-h", arg)) { + flags |= REF_HEADS; + continue; + } + if (!strcmp("--refs", arg)) { + flags |= REF_NORMAL; + continue; + } + if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) { + quiet = 1; + continue; + } + usage(ls_remote_usage); + } + dest = arg; + i++; + break; + } + + if (argv[i]) { + int j; + pattern = xcalloc(sizeof(const char *), argc - i + 1); + for (j = i; j < argc; j++) { + int len = strlen(argv[j]); + char *p = xmalloc(len + 3); + sprintf(p, "*/%s", argv[j]); + pattern[j - i] = p; + } + } + remote = remote_get(dest); + if (!remote) { + if (dest) + die("bad repository '%s'", dest); + die("No remote configured to list refs from."); + } + if (!remote->url_nr) + die("remote %s has no configured URL", dest); + transport = transport_get(remote, NULL); + if (uploadpack != NULL) + transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack); + + ref = transport_get_remote_refs(transport); + if (transport_disconnect(transport)) + return 1; + + if (!dest && !quiet) + fprintf(stderr, "From %s\n", *remote->url); + for ( ; ref; ref = ref->next) { + if (!check_ref_type(ref, flags)) + continue; + if (!tail_match(pattern, ref->name)) + continue; + printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name); + } + return 0; +} |