2007-10-30 02:05:43 +01:00
|
|
|
#include "builtin.h"
|
2005-07-24 02:54:03 +02:00
|
|
|
#include "cache.h"
|
2007-10-30 02:05:43 +01:00
|
|
|
#include "transport.h"
|
|
|
|
#include "remote.h"
|
2005-07-24 02:54:03 +02:00
|
|
|
|
2007-11-04 21:51:17 +01:00
|
|
|
static const char ls_remote_usage[] =
|
2008-11-11 16:52:31 +01:00
|
|
|
"git ls-remote [--heads] [--tags] [-u <exec> | --upload-pack <exec>] <repository> <refs>...";
|
2005-07-24 02:54:03 +02:00
|
|
|
|
2007-12-09 07:52:59 +01:00
|
|
|
/*
|
2007-12-09 21:16:55 +01:00
|
|
|
* Is there one among the list of patterns that match the tail part
|
|
|
|
* of the path?
|
2007-12-09 07:52:59 +01:00
|
|
|
*/
|
|
|
|
static int tail_match(const char **pattern, const char *path)
|
|
|
|
{
|
|
|
|
const char *p;
|
2007-12-09 21:16:55 +01:00
|
|
|
char pathbuf[PATH_MAX];
|
2007-12-09 07:52:59 +01:00
|
|
|
|
2007-12-09 21:16:55 +01:00
|
|
|
if (!pattern)
|
2007-12-09 07:52:59 +01:00
|
|
|
return 1; /* no restriction */
|
|
|
|
|
2007-12-09 21:16:55 +01: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 07:52:59 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-04 21:51:17 +01:00
|
|
|
int cmd_ls_remote(int argc, const char **argv, const char *prefix)
|
2005-07-24 02:54:03 +02:00
|
|
|
{
|
2007-10-30 02:05:43 +01:00
|
|
|
int i;
|
|
|
|
const char *dest = NULL;
|
2008-03-25 22:06:26 +01: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-04 21:29:10 +02:00
|
|
|
unsigned flags = 0;
|
2007-10-30 02:05:43 +01:00
|
|
|
const char *uploadpack = NULL;
|
2007-12-09 07:52:59 +01:00
|
|
|
const char **pattern = NULL;
|
2007-10-30 02:05:43 +01:00
|
|
|
|
2007-11-07 02:29:20 +01:00
|
|
|
struct remote *remote;
|
2007-10-30 02:05:43 +01:00
|
|
|
struct transport *transport;
|
|
|
|
const struct ref *ref;
|
2005-11-26 08:50:21 +01:00
|
|
|
|
|
|
|
setup_git_directory_gently(&nongit);
|
2005-07-24 02:54:03 +02:00
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2007-10-30 02:05:43 +01:00
|
|
|
const char *arg = argv[i];
|
2005-07-24 02:54:03 +02:00
|
|
|
|
|
|
|
if (*arg == '-') {
|
2007-02-20 10:54:00 +01:00
|
|
|
if (!prefixcmp(arg, "--upload-pack=")) {
|
2007-01-23 09:20:17 +01:00
|
|
|
uploadpack = arg + 14;
|
|
|
|
continue;
|
|
|
|
}
|
2007-02-20 10:54:00 +01:00
|
|
|
if (!prefixcmp(arg, "--exec=")) {
|
2007-01-23 09:20:17 +01: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-04 21:29:10 +02:00
|
|
|
continue;
|
|
|
|
}
|
2008-01-15 21:34:54 +01: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-04 21:29:10 +02:00
|
|
|
flags |= REF_TAGS;
|
|
|
|
continue;
|
|
|
|
}
|
2008-01-15 21:34:54 +01: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-04 21:29:10 +02:00
|
|
|
flags |= REF_HEADS;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!strcmp("--refs", arg)) {
|
|
|
|
flags |= REF_NORMAL;
|
|
|
|
continue;
|
|
|
|
}
|
2007-11-04 21:51:17 +01:00
|
|
|
usage(ls_remote_usage);
|
2005-07-24 02:54:03 +02:00
|
|
|
}
|
|
|
|
dest = arg;
|
2007-12-09 21:16:55 +01:00
|
|
|
i++;
|
2005-07-24 02:54:03 +02: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-04 21:29:10 +02:00
|
|
|
|
2007-12-09 07:52:59 +01:00
|
|
|
if (!dest)
|
2007-11-04 21:51:17 +01:00
|
|
|
usage(ls_remote_usage);
|
2007-12-09 21:16:55 +01: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 02:29:20 +01:00
|
|
|
remote = nongit ? NULL : remote_get(dest);
|
|
|
|
if (remote && !remote->url_nr)
|
|
|
|
die("remote %s has no configured URL", dest);
|
2009-11-18 02:42:22 +01:00
|
|
|
transport = transport_get(remote, NULL);
|
2007-10-30 02:05:43 +01:00
|
|
|
if (uploadpack != NULL)
|
|
|
|
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
|
|
|
|
|
|
|
|
ref = transport_get_remote_refs(transport);
|
2008-03-04 09:34:39 +01:00
|
|
|
if (transport_disconnect(transport))
|
2007-10-30 02:05:43 +01:00
|
|
|
return 1;
|
2007-12-09 07:52:59 +01: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 02:05:43 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2005-07-24 02:54:03 +02:00
|
|
|
}
|