Browse Source
* db/remote-builtin: Reteach builtin-ls-remote to understand remotes Build in ls-remote Use built-in send-pack. Build-in send-pack, with an API for other programs to call. Build-in peek-remote, using transport infrastructure. Miscellaneous const changes and utilities Conflicts: transport.cmaint
Junio C Hamano
17 years ago
17 changed files with 261 additions and 187 deletions
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
#include "builtin.h" |
||||
#include "cache.h" |
||||
#include "transport.h" |
||||
#include "remote.h" |
||||
|
||||
static const char ls_remote_usage[] = |
||||
"git-ls-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>"; |
||||
|
||||
int cmd_ls_remote(int argc, const char **argv, const char *prefix) |
||||
{ |
||||
int i; |
||||
const char *dest = NULL; |
||||
int nongit = 0; |
||||
unsigned flags = 0; |
||||
const char *uploadpack = 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)) { |
||||
flags |= REF_TAGS; |
||||
continue; |
||||
} |
||||
if (!strcmp("--heads", arg)) { |
||||
flags |= REF_HEADS; |
||||
continue; |
||||
} |
||||
if (!strcmp("--refs", arg)) { |
||||
flags |= REF_NORMAL; |
||||
continue; |
||||
} |
||||
usage(ls_remote_usage); |
||||
} |
||||
dest = arg; |
||||
break; |
||||
} |
||||
|
||||
if (!dest || i != argc - 1) |
||||
usage(ls_remote_usage); |
||||
|
||||
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); |
||||
if (uploadpack != NULL) |
||||
transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack); |
||||
|
||||
ref = transport_get_remote_refs(transport); |
||||
|
||||
if (!ref) |
||||
return 1; |
||||
|
||||
while (ref) { |
||||
if (check_ref_type(ref, flags)) |
||||
printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name); |
||||
ref = ref->next; |
||||
} |
||||
return 0; |
||||
} |
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
#include "cache.h" |
||||
#include "refs.h" |
||||
#include "pkt-line.h" |
||||
|
||||
static const char peek_remote_usage[] = |
||||
"git-peek-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>"; |
||||
static const char *uploadpack = "git-upload-pack"; |
||||
|
||||
static int peek_remote(int fd[2], unsigned flags) |
||||
{ |
||||
struct ref *ref; |
||||
|
||||
get_remote_heads(fd[0], &ref, 0, NULL, flags); |
||||
packet_flush(fd[1]); |
||||
|
||||
while (ref) { |
||||
printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name); |
||||
ref = ref->next; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
int i, ret; |
||||
char *dest = NULL; |
||||
int fd[2]; |
||||
struct child_process *conn; |
||||
int nongit = 0; |
||||
unsigned flags = 0; |
||||
|
||||
setup_git_directory_gently(&nongit); |
||||
|
||||
for (i = 1; i < argc; i++) { |
||||
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)) { |
||||
flags |= REF_TAGS; |
||||
continue; |
||||
} |
||||
if (!strcmp("--heads", arg)) { |
||||
flags |= REF_HEADS; |
||||
continue; |
||||
} |
||||
if (!strcmp("--refs", arg)) { |
||||
flags |= REF_NORMAL; |
||||
continue; |
||||
} |
||||
usage(peek_remote_usage); |
||||
} |
||||
dest = arg; |
||||
break; |
||||
} |
||||
|
||||
if (!dest || i != argc - 1) |
||||
usage(peek_remote_usage); |
||||
|
||||
conn = git_connect(fd, dest, uploadpack, 0); |
||||
ret = peek_remote(fd, flags); |
||||
close(fd[0]); |
||||
close(fd[1]); |
||||
ret |= finish_connect(conn); |
||||
return !!ret; |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
#ifndef SEND_PACK_H |
||||
#define SEND_PACK_H |
||||
|
||||
struct send_pack_args { |
||||
const char *receivepack; |
||||
unsigned verbose:1, |
||||
send_all:1, |
||||
force_update:1, |
||||
use_thin_pack:1, |
||||
dry_run:1; |
||||
}; |
||||
|
||||
int send_pack(struct send_pack_args *args, |
||||
const char *dest, struct remote *remote, |
||||
int nr_heads, const char **heads); |
||||
|
||||
#endif |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh |
||||
|
||||
test_description='git ls-remote' |
||||
|
||||
. ./test-lib.sh |
||||
|
||||
test_expect_success setup ' |
||||
|
||||
>file && |
||||
git add file && |
||||
test_tick && |
||||
git commit -m initial && |
||||
git tag mark && |
||||
git show-ref --tags -d | sed -e "s/ / /" >expected.tag && |
||||
( |
||||
echo "$(git rev-parse HEAD) HEAD" |
||||
git show-ref -d | sed -e "s/ / /" |
||||
) >expected.all && |
||||
|
||||
git remote add self $(pwd)/.git |
||||
|
||||
' |
||||
|
||||
test_expect_success 'ls-remote --tags .git' ' |
||||
|
||||
git ls-remote --tags .git >actual && |
||||
diff -u expected.tag actual |
||||
|
||||
' |
||||
|
||||
test_expect_success 'ls-remote .git' ' |
||||
|
||||
git ls-remote .git >actual && |
||||
diff -u expected.all actual |
||||
|
||||
' |
||||
|
||||
test_expect_success 'ls-remote --tags self' ' |
||||
|
||||
git ls-remote --tags self >actual && |
||||
diff -u expected.tag actual |
||||
|
||||
' |
||||
|
||||
test_expect_success 'ls-remote self' ' |
||||
|
||||
git ls-remote self >actual && |
||||
diff -u expected.all actual |
||||
|
||||
' |
||||
|
||||
test_done |
Loading…
Reference in new issue