2007-10-30 09:05:43 +08:00
|
|
|
#include "builtin.h"
|
2005-07-24 08:54:03 +08:00
|
|
|
#include "cache.h"
|
2007-10-30 09:05:43 +08:00
|
|
|
#include "transport.h"
|
|
|
|
#include "remote.h"
|
2005-07-24 08:54:03 +08:00
|
|
|
|
2007-11-05 04:51:17 +08:00
|
|
|
static const char ls_remote_usage[] =
|
2008-07-13 21:36:15 +08:00
|
|
|
"git ls-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
|
2005-07-24 08:54:03 +08:00
|
|
|
|
2007-12-09 14:52:59 +08:00
|
|
|
/*
|
2007-12-10 04:16:55 +08:00
|
|
|
* Is there one among the list of patterns that match the tail part
|
|
|
|
* of the path?
|
2007-12-09 14:52:59 +08:00
|
|
|
*/
|
|
|
|
static int tail_match(const char **pattern, const char *path)
|
|
|
|
{
|
|
|
|
const char *p;
|
2007-12-10 04:16:55 +08:00
|
|
|
char pathbuf[PATH_MAX];
|
2007-12-09 14:52:59 +08:00
|
|
|
|
2007-12-10 04:16:55 +08:00
|
|
|
if (!pattern)
|
2007-12-09 14:52:59 +08:00
|
|
|
return 1; /* no restriction */
|
|
|
|
|
2007-12-10 04:16:55 +08:00
|
|
|
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;
|
2007-12-09 14:52:59 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-05 04:51:17 +08:00
|
|
|
int cmd_ls_remote(int argc, const char **argv, const char *prefix)
|
2005-07-24 08:54:03 +08:00
|
|
|
{
|
2007-10-30 09:05:43 +08:00
|
|
|
int i;
|
|
|
|
const char *dest = NULL;
|
2008-03-26 05:06:26 +08:00
|
|
|
int nongit;
|
Improve git-peek-remote
This makes git-peek-remote able to basically do everything that
git-ls-remote does (but obviously just for the native protocol, so no
http[s]: or rsync: support).
The default behaviour is the same, but you can now give a mixture of
"--refs", "--tags" and "--heads" flags, where "--refs" forces
git-peek-remote to only show real refs (ie none of the fakey tag lookups,
but also not the special pseudo-refs like HEAD and MERGE_HEAD).
The "--tags" and "--heads" flags respectively limit the output to just
regular tags and heads, of course.
You can still also ask to limit them by name too.
You can combine the flags, so
git peek-remote --refs --tags .
will show all local _true_ tags, without the generated tag lookups
(compare the output without the "--refs" flag).
And "--tags --heads" will show both tags and heads, but will avoid (for
example) any special refs outside of the standard locations.
I'm also planning on adding a "--ignore-local" flag that allows us to ask
it to ignore any refs that we already have in the local tree, but that's
an independent thing.
All this is obviously gearing up to making "git fetch" cheaper.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-05 03:29:10 +08:00
|
|
|
unsigned flags = 0;
|
2007-10-30 09:05:43 +08:00
|
|
|
const char *uploadpack = NULL;
|
2007-12-09 14:52:59 +08:00
|
|
|
const char **pattern = NULL;
|
2007-10-30 09:05:43 +08:00
|
|
|
|
2007-11-07 09:29:20 +08:00
|
|
|
struct remote *remote;
|
2007-10-30 09:05:43 +08:00
|
|
|
struct transport *transport;
|
|
|
|
const struct ref *ref;
|
2005-11-26 15:50:21 +08:00
|
|
|
|
|
|
|
setup_git_directory_gently(&nongit);
|
2005-07-24 08:54:03 +08:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2007-10-30 09:05:43 +08:00
|
|
|
const char *arg = argv[i];
|
2005-07-24 08:54:03 +08:00
|
|
|
|
|
|
|
if (*arg == '-') {
|
2007-02-20 17:54:00 +08:00
|
|
|
if (!prefixcmp(arg, "--upload-pack=")) {
|
2007-01-23 16:20:17 +08:00
|
|
|
uploadpack = arg + 14;
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-20 17:54:00 +08:00
|
|
|
if (!prefixcmp(arg, "--exec=")) {
|
2007-01-23 16:20:17 +08:00
|
|
|
uploadpack = arg + 7;
|
Improve git-peek-remote
This makes git-peek-remote able to basically do everything that
git-ls-remote does (but obviously just for the native protocol, so no
http[s]: or rsync: support).
The default behaviour is the same, but you can now give a mixture of
"--refs", "--tags" and "--heads" flags, where "--refs" forces
git-peek-remote to only show real refs (ie none of the fakey tag lookups,
but also not the special pseudo-refs like HEAD and MERGE_HEAD).
The "--tags" and "--heads" flags respectively limit the output to just
regular tags and heads, of course.
You can still also ask to limit them by name too.
You can combine the flags, so
git peek-remote --refs --tags .
will show all local _true_ tags, without the generated tag lookups
(compare the output without the "--refs" flag).
And "--tags --heads" will show both tags and heads, but will avoid (for
example) any special refs outside of the standard locations.
I'm also planning on adding a "--ignore-local" flag that allows us to ask
it to ignore any refs that we already have in the local tree, but that's
an independent thing.
All this is obviously gearing up to making "git fetch" cheaper.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-05 03:29:10 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-01-16 04:34:54 +08:00
|
|
|
if (!strcmp("--tags", arg) || !strcmp("-t", arg)) {
|
Improve git-peek-remote
This makes git-peek-remote able to basically do everything that
git-ls-remote does (but obviously just for the native protocol, so no
http[s]: or rsync: support).
The default behaviour is the same, but you can now give a mixture of
"--refs", "--tags" and "--heads" flags, where "--refs" forces
git-peek-remote to only show real refs (ie none of the fakey tag lookups,
but also not the special pseudo-refs like HEAD and MERGE_HEAD).
The "--tags" and "--heads" flags respectively limit the output to just
regular tags and heads, of course.
You can still also ask to limit them by name too.
You can combine the flags, so
git peek-remote --refs --tags .
will show all local _true_ tags, without the generated tag lookups
(compare the output without the "--refs" flag).
And "--tags --heads" will show both tags and heads, but will avoid (for
example) any special refs outside of the standard locations.
I'm also planning on adding a "--ignore-local" flag that allows us to ask
it to ignore any refs that we already have in the local tree, but that's
an independent thing.
All this is obviously gearing up to making "git fetch" cheaper.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-05 03:29:10 +08:00
|
|
|
flags |= REF_TAGS;
|
|
|
|
continue;
|
|
|
|
}
|
2008-01-16 04:34:54 +08:00
|
|
|
if (!strcmp("--heads", arg) || !strcmp("-h", arg)) {
|
Improve git-peek-remote
This makes git-peek-remote able to basically do everything that
git-ls-remote does (but obviously just for the native protocol, so no
http[s]: or rsync: support).
The default behaviour is the same, but you can now give a mixture of
"--refs", "--tags" and "--heads" flags, where "--refs" forces
git-peek-remote to only show real refs (ie none of the fakey tag lookups,
but also not the special pseudo-refs like HEAD and MERGE_HEAD).
The "--tags" and "--heads" flags respectively limit the output to just
regular tags and heads, of course.
You can still also ask to limit them by name too.
You can combine the flags, so
git peek-remote --refs --tags .
will show all local _true_ tags, without the generated tag lookups
(compare the output without the "--refs" flag).
And "--tags --heads" will show both tags and heads, but will avoid (for
example) any special refs outside of the standard locations.
I'm also planning on adding a "--ignore-local" flag that allows us to ask
it to ignore any refs that we already have in the local tree, but that's
an independent thing.
All this is obviously gearing up to making "git fetch" cheaper.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-05 03:29:10 +08:00
|
|
|
flags |= REF_HEADS;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp("--refs", arg)) {
|
|
|
|
flags |= REF_NORMAL;
|
|
|
|
continue;
|
|
|
|
}
|
2007-11-05 04:51:17 +08:00
|
|
|
usage(ls_remote_usage);
|
2005-07-24 08:54:03 +08:00
|
|
|
}
|
|
|
|
dest = arg;
|
2007-12-10 04:16:55 +08:00
|
|
|
i++;
|
2005-07-24 08:54:03 +08:00
|
|
|
break;
|
|
|
|
}
|
Improve git-peek-remote
This makes git-peek-remote able to basically do everything that
git-ls-remote does (but obviously just for the native protocol, so no
http[s]: or rsync: support).
The default behaviour is the same, but you can now give a mixture of
"--refs", "--tags" and "--heads" flags, where "--refs" forces
git-peek-remote to only show real refs (ie none of the fakey tag lookups,
but also not the special pseudo-refs like HEAD and MERGE_HEAD).
The "--tags" and "--heads" flags respectively limit the output to just
regular tags and heads, of course.
You can still also ask to limit them by name too.
You can combine the flags, so
git peek-remote --refs --tags .
will show all local _true_ tags, without the generated tag lookups
(compare the output without the "--refs" flag).
And "--tags --heads" will show both tags and heads, but will avoid (for
example) any special refs outside of the standard locations.
I'm also planning on adding a "--ignore-local" flag that allows us to ask
it to ignore any refs that we already have in the local tree, but that's
an independent thing.
All this is obviously gearing up to making "git fetch" cheaper.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-07-05 03:29:10 +08:00
|
|
|
|
2007-12-09 14:52:59 +08:00
|
|
|
if (!dest)
|
2007-11-05 04:51:17 +08:00
|
|
|
usage(ls_remote_usage);
|
2007-12-10 04:16:55 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2007-11-07 09:29:20 +08:00
|
|
|
remote = nongit ? NULL : remote_get(dest);
|
|
|
|
if (remote && !remote->url_nr)
|
|
|
|
die("remote %s has no configured URL", dest);
|
|
|
|
transport = transport_get(remote, remote ? remote->url[0] : dest);
|
2007-10-30 09:05:43 +08:00
|
|
|
if (uploadpack != NULL)
|
|
|
|
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
|
|
|
|
|
|
|
|
ref = transport_get_remote_refs(transport);
|
2008-03-04 16:34:39 +08:00
|
|
|
if (transport_disconnect(transport))
|
2007-10-30 09:05:43 +08:00
|
|
|
return 1;
|
2007-12-09 14:52:59 +08:00
|
|
|
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);
|
2007-10-30 09:05:43 +08:00
|
|
|
}
|
|
|
|
return 0;
|
2005-07-24 08:54:03 +08:00
|
|
|
}
|