Skip to content

Commit cd03eeb

Browse files
committed
Merge branch 'db/vcs-helper'
* db/vcs-helper: Makefile: remove remnant of separate http/https/ftp helpers Use a clearer style to issue commands to remote helpers Make the "traditionally-supported" URLs a special case Makefile: install hardlinks for git-remote-<scheme> supported by libcurl if possible Makefile: do not link three copies of git-remote-* programs Makefile: git-http-fetch does not need expat http-fetch: Fix Makefile dependancies Add transport native helper executables to .gitignore git-http-fetch: not a builtin Use an external program to implement fetching with curl Add support for external programs for handling native fetches
2 parents 2b7ca83 + 85cdaa4 commit cd03eeb

File tree

9 files changed

+406
-144
lines changed

9 files changed

+406
-144
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ git-receive-pack
104104
git-reflog
105105
git-relink
106106
git-remote
107+
git-remote-curl
107108
git-repack
108109
git-replace
109110
git-repo-config
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
git-remote-helpers(1)
2+
=====================
3+
4+
NAME
5+
----
6+
git-remote-helpers - Helper programs for interoperation with remote git
7+
8+
SYNOPSIS
9+
--------
10+
'git remote-<transport>' <remote>
11+
12+
DESCRIPTION
13+
-----------
14+
15+
These programs are normally not used directly by end users, but are
16+
invoked by various git programs that interact with remote repositories
17+
when the repository they would operate on will be accessed using
18+
transport code not linked into the main git binary. Various particular
19+
helper programs will behave as documented here.
20+
21+
COMMANDS
22+
--------
23+
24+
Commands are given by the caller on the helper's standard input, one per line.
25+
26+
'capabilities'::
27+
Lists the capabilities of the helper, one per line, ending
28+
with a blank line.
29+
30+
'list'::
31+
Lists the refs, one per line, in the format "<value> <name>
32+
[<attr> ...]". The value may be a hex sha1 hash, "@<dest>" for
33+
a symref, or "?" to indicate that the helper could not get the
34+
value of the ref. A space-separated list of attributes follows
35+
the name; unrecognized attributes are ignored. After the
36+
complete list, outputs a blank line.
37+
38+
'fetch' <sha1> <name>::
39+
Fetches the given object, writing the necessary objects to the
40+
database. Outputs a blank line when the fetch is
41+
complete. Only objects which were reported in the ref list
42+
with a sha1 may be fetched this way.
43+
+
44+
Supported if the helper has the "fetch" capability.
45+
46+
If a fatal error occurs, the program writes the error message to
47+
stderr and exits. The caller should expect that a suitable error
48+
message has been printed if the child closes the connection without
49+
completing a valid response for the current command.
50+
51+
Additional commands may be supported, as may be determined from
52+
capabilities reported by the helper.
53+
54+
CAPABILITIES
55+
------------
56+
57+
'fetch'::
58+
This helper supports the 'fetch' command.
59+
60+
REF LIST ATTRIBUTES
61+
-------------------
62+
63+
None are defined yet, but the caller must accept any which are supplied.
64+
65+
Documentation
66+
-------------
67+
Documentation by Daniel Barkalow.
68+
69+
GIT
70+
---
71+
Part of the linkgit:git[1] suite

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ BUILT_INS += git-stage$X
380380
BUILT_INS += git-status$X
381381
BUILT_INS += git-whatchanged$X
382382

383-
# what 'all' will build and 'install' will install, in gitexecdir
383+
# what 'all' will build and 'install' will install in gitexecdir,
384+
# excluding programs for built-in commands
384385
ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
385386

386387
# what 'all' will build but not install in gitexecdir
@@ -547,6 +548,7 @@ LIB_OBJS += symlinks.o
547548
LIB_OBJS += tag.o
548549
LIB_OBJS += trace.o
549550
LIB_OBJS += transport.o
551+
LIB_OBJS += transport-helper.o
550552
LIB_OBJS += tree-diff.o
551553
LIB_OBJS += tree.o
552554
LIB_OBJS += tree-walk.o
@@ -973,9 +975,7 @@ else
973975
else
974976
CURL_LIBCURL = -lcurl
975977
endif
976-
BUILTIN_OBJS += builtin-http-fetch.o
977-
EXTLIBS += $(CURL_LIBCURL)
978-
LIB_OBJS += http.o http-walker.o
978+
PROGRAMS += git-remote-curl$X git-http-fetch$X
979979
curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p)
980980
ifeq "$(curl_check)" "070908"
981981
ifndef NO_EXPAT
@@ -1249,6 +1249,7 @@ ifndef V
12491249
QUIET_LINK = @echo ' ' LINK $@;
12501250
QUIET_BUILT_IN = @echo ' ' BUILTIN $@;
12511251
QUIET_GEN = @echo ' ' GEN $@;
1252+
QUIET_LNCP = @echo ' ' LN/CP $@;
12521253
QUIET_SUBDIR0 = +@subdir=
12531254
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
12541255
$(MAKE) $(PRINT_DIR) -C $$subdir
@@ -1476,12 +1477,21 @@ git-imap-send$X: imap-send.o $(GITLIBS)
14761477
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
14771478
$(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL)
14781479

1479-
http.o http-walker.o http-push.o transport.o: http.h
1480+
http.o http-walker.o http-push.o: http.h
14801481

1482+
http.o http-walker.o: $(LIB_H)
1483+
1484+
git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS)
1485+
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
1486+
$(LIBS) $(CURL_LIBCURL)
14811487
git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
14821488
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
14831489
$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
14841490

1491+
git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS)
1492+
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
1493+
$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
1494+
14851495
$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
14861496
$(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h)
14871497
builtin-revert.o wt-status.o: wt-status.h

git.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,6 @@ static void handle_internal_command(int argc, const char **argv)
312312
{ "get-tar-commit-id", cmd_get_tar_commit_id },
313313
{ "grep", cmd_grep, RUN_SETUP | USE_PAGER },
314314
{ "help", cmd_help },
315-
#ifndef NO_CURL
316-
{ "http-fetch", cmd_http_fetch, RUN_SETUP },
317-
#endif
318315
{ "init", cmd_init_db },
319316
{ "init-db", cmd_init_db },
320317
{ "log", cmd_log, RUN_SETUP | USE_PAGER },
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "cache.h"
22
#include "walker.h"
33

4-
int cmd_http_fetch(int argc, const char **argv, const char *prefix)
4+
int main(int argc, const char **argv)
55
{
6+
const char *prefix;
67
struct walker *walker;
78
int commits_on_stdin = 0;
89
int commits;
@@ -18,6 +19,8 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
1819
int get_verbosely = 0;
1920
int get_recover = 0;
2021

22+
prefix = setup_git_directory();
23+
2124
git_config(git_default_config, NULL);
2225

2326
while (arg < argc && argv[arg][0] == '-') {

remote-curl.c

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#include "cache.h"
2+
#include "remote.h"
3+
#include "strbuf.h"
4+
#include "walker.h"
5+
#include "http.h"
6+
7+
static struct ref *get_refs(struct walker *walker, const char *url)
8+
{
9+
struct strbuf buffer = STRBUF_INIT;
10+
char *data, *start, *mid;
11+
char *ref_name;
12+
char *refs_url;
13+
int i = 0;
14+
int http_ret;
15+
16+
struct ref *refs = NULL;
17+
struct ref *ref = NULL;
18+
struct ref *last_ref = NULL;
19+
20+
refs_url = xmalloc(strlen(url) + 11);
21+
sprintf(refs_url, "%s/info/refs", url);
22+
23+
http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
24+
switch (http_ret) {
25+
case HTTP_OK:
26+
break;
27+
case HTTP_MISSING_TARGET:
28+
die("%s not found: did you run git update-server-info on the"
29+
" server?", refs_url);
30+
default:
31+
http_error(refs_url, http_ret);
32+
die("HTTP request failed");
33+
}
34+
35+
data = buffer.buf;
36+
start = NULL;
37+
mid = data;
38+
while (i < buffer.len) {
39+
if (!start) {
40+
start = &data[i];
41+
}
42+
if (data[i] == '\t')
43+
mid = &data[i];
44+
if (data[i] == '\n') {
45+
data[i] = 0;
46+
ref_name = mid + 1;
47+
ref = xmalloc(sizeof(struct ref) +
48+
strlen(ref_name) + 1);
49+
memset(ref, 0, sizeof(struct ref));
50+
strcpy(ref->name, ref_name);
51+
get_sha1_hex(start, ref->old_sha1);
52+
if (!refs)
53+
refs = ref;
54+
if (last_ref)
55+
last_ref->next = ref;
56+
last_ref = ref;
57+
start = NULL;
58+
}
59+
i++;
60+
}
61+
62+
strbuf_release(&buffer);
63+
64+
ref = alloc_ref("HEAD");
65+
if (!walker->fetch_ref(walker, ref) &&
66+
!resolve_remote_symref(ref, refs)) {
67+
ref->next = refs;
68+
refs = ref;
69+
} else {
70+
free(ref);
71+
}
72+
73+
strbuf_release(&buffer);
74+
free(refs_url);
75+
return refs;
76+
}
77+
78+
int main(int argc, const char **argv)
79+
{
80+
struct remote *remote;
81+
struct strbuf buf = STRBUF_INIT;
82+
const char *url;
83+
struct walker *walker = NULL;
84+
85+
setup_git_directory();
86+
if (argc < 2) {
87+
fprintf(stderr, "Remote needed\n");
88+
return 1;
89+
}
90+
91+
remote = remote_get(argv[1]);
92+
93+
if (argc > 2) {
94+
url = argv[2];
95+
} else {
96+
url = remote->url[0];
97+
}
98+
99+
do {
100+
if (strbuf_getline(&buf, stdin, '\n') == EOF)
101+
break;
102+
if (!prefixcmp(buf.buf, "fetch ")) {
103+
char *obj = buf.buf + strlen("fetch ");
104+
if (!walker)
105+
walker = get_http_walker(url, remote);
106+
walker->get_all = 1;
107+
walker->get_tree = 1;
108+
walker->get_history = 1;
109+
walker->get_verbosely = 0;
110+
walker->get_recover = 0;
111+
if (walker_fetch(walker, 1, &obj, NULL, NULL))
112+
die("Fetch failed.");
113+
printf("\n");
114+
fflush(stdout);
115+
} else if (!strcmp(buf.buf, "list")) {
116+
struct ref *refs;
117+
struct ref *posn;
118+
if (!walker)
119+
walker = get_http_walker(url, remote);
120+
refs = get_refs(walker, url);
121+
for (posn = refs; posn; posn = posn->next) {
122+
if (posn->symref)
123+
printf("@%s %s\n", posn->symref, posn->name);
124+
else
125+
printf("%s %s\n", sha1_to_hex(posn->old_sha1), posn->name);
126+
}
127+
printf("\n");
128+
fflush(stdout);
129+
} else if (!strcmp(buf.buf, "capabilities")) {
130+
printf("fetch\n");
131+
printf("\n");
132+
fflush(stdout);
133+
} else {
134+
return 1;
135+
}
136+
strbuf_reset(&buf);
137+
} while (1);
138+
return 0;
139+
}

0 commit comments

Comments
 (0)