Skip to content

Commit

Permalink
Merge branch 'db/vcs-helper'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gitster committed Sep 13, 2009
2 parents 2b7ca83 + 85cdaa4 commit cd03eeb
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ git-receive-pack
git-reflog
git-relink
git-remote
git-remote-curl
git-repack
git-replace
git-repo-config
Expand Down
71 changes: 71 additions & 0 deletions Documentation/git-remote-helpers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
git-remote-helpers(1)
=====================

NAME
----
git-remote-helpers - Helper programs for interoperation with remote git

SYNOPSIS
--------
'git remote-<transport>' <remote>

DESCRIPTION
-----------

These programs are normally not used directly by end users, but are
invoked by various git programs that interact with remote repositories
when the repository they would operate on will be accessed using
transport code not linked into the main git binary. Various particular
helper programs will behave as documented here.

COMMANDS
--------

Commands are given by the caller on the helper's standard input, one per line.

'capabilities'::
Lists the capabilities of the helper, one per line, ending
with a blank line.

'list'::
Lists the refs, one per line, in the format "<value> <name>
[<attr> ...]". The value may be a hex sha1 hash, "@<dest>" for
a symref, or "?" to indicate that the helper could not get the
value of the ref. A space-separated list of attributes follows
the name; unrecognized attributes are ignored. After the
complete list, outputs a blank line.

'fetch' <sha1> <name>::
Fetches the given object, writing the necessary objects to the
database. Outputs a blank line when the fetch is
complete. Only objects which were reported in the ref list
with a sha1 may be fetched this way.
+
Supported if the helper has the "fetch" capability.

If a fatal error occurs, the program writes the error message to
stderr and exits. The caller should expect that a suitable error
message has been printed if the child closes the connection without
completing a valid response for the current command.

Additional commands may be supported, as may be determined from
capabilities reported by the helper.

CAPABILITIES
------------

'fetch'::
This helper supports the 'fetch' command.

REF LIST ATTRIBUTES
-------------------

None are defined yet, but the caller must accept any which are supplied.

Documentation
-------------
Documentation by Daniel Barkalow.

GIT
---
Part of the linkgit:git[1] suite
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ BUILT_INS += git-stage$X
BUILT_INS += git-status$X
BUILT_INS += git-whatchanged$X

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

# what 'all' will build but not install in gitexecdir
Expand Down Expand Up @@ -547,6 +548,7 @@ LIB_OBJS += symlinks.o
LIB_OBJS += tag.o
LIB_OBJS += trace.o
LIB_OBJS += transport.o
LIB_OBJS += transport-helper.o
LIB_OBJS += tree-diff.o
LIB_OBJS += tree.o
LIB_OBJS += tree-walk.o
Expand Down Expand Up @@ -973,9 +975,7 @@ else
else
CURL_LIBCURL = -lcurl
endif
BUILTIN_OBJS += builtin-http-fetch.o
EXTLIBS += $(CURL_LIBCURL)
LIB_OBJS += http.o http-walker.o
PROGRAMS += git-remote-curl$X git-http-fetch$X
curl_check := $(shell (echo 070908; curl-config --vernum) | sort -r | sed -ne 2p)
ifeq "$(curl_check)" "070908"
ifndef NO_EXPAT
Expand Down Expand Up @@ -1249,6 +1249,7 @@ ifndef V
QUIET_LINK = @echo ' ' LINK $@;
QUIET_BUILT_IN = @echo ' ' BUILTIN $@;
QUIET_GEN = @echo ' ' GEN $@;
QUIET_LNCP = @echo ' ' LN/CP $@;
QUIET_SUBDIR0 = +@subdir=
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
$(MAKE) $(PRINT_DIR) -C $$subdir
Expand Down Expand Up @@ -1476,12 +1477,21 @@ git-imap-send$X: imap-send.o $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(LIBS) $(OPENSSL_LINK) $(OPENSSL_LIBSSL)

http.o http-walker.o http-push.o transport.o: http.h
http.o http-walker.o http-push.o: http.h

http.o http-walker.o: $(LIB_H)

git-http-fetch$X: revision.o http.o http-walker.o http-fetch.o $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(LIBS) $(CURL_LIBCURL)
git-http-push$X: revision.o http.o http-push.o $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)

git-remote-curl$X: remote-curl.o http.o http-walker.o $(GITLIBS)
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)

$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
$(patsubst git-%$X,%.o,$(PROGRAMS)) git.o: $(LIB_H) $(wildcard */*.h)
builtin-revert.o wt-status.o: wt-status.h
Expand Down
3 changes: 0 additions & 3 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ static void handle_internal_command(int argc, const char **argv)
{ "get-tar-commit-id", cmd_get_tar_commit_id },
{ "grep", cmd_grep, RUN_SETUP | USE_PAGER },
{ "help", cmd_help },
#ifndef NO_CURL
{ "http-fetch", cmd_http_fetch, RUN_SETUP },
#endif
{ "init", cmd_init_db },
{ "init-db", cmd_init_db },
{ "log", cmd_log, RUN_SETUP | USE_PAGER },
Expand Down
5 changes: 4 additions & 1 deletion builtin-http-fetch.c → http-fetch.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "cache.h"
#include "walker.h"

int cmd_http_fetch(int argc, const char **argv, const char *prefix)
int main(int argc, const char **argv)
{
const char *prefix;
struct walker *walker;
int commits_on_stdin = 0;
int commits;
Expand All @@ -18,6 +19,8 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
int get_verbosely = 0;
int get_recover = 0;

prefix = setup_git_directory();

git_config(git_default_config, NULL);

while (arg < argc && argv[arg][0] == '-') {
Expand Down
139 changes: 139 additions & 0 deletions remote-curl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "cache.h"
#include "remote.h"
#include "strbuf.h"
#include "walker.h"
#include "http.h"

static struct ref *get_refs(struct walker *walker, const char *url)
{
struct strbuf buffer = STRBUF_INIT;
char *data, *start, *mid;
char *ref_name;
char *refs_url;
int i = 0;
int http_ret;

struct ref *refs = NULL;
struct ref *ref = NULL;
struct ref *last_ref = NULL;

refs_url = xmalloc(strlen(url) + 11);
sprintf(refs_url, "%s/info/refs", url);

http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
switch (http_ret) {
case HTTP_OK:
break;
case HTTP_MISSING_TARGET:
die("%s not found: did you run git update-server-info on the"
" server?", refs_url);
default:
http_error(refs_url, http_ret);
die("HTTP request failed");
}

data = buffer.buf;
start = NULL;
mid = data;
while (i < buffer.len) {
if (!start) {
start = &data[i];
}
if (data[i] == '\t')
mid = &data[i];
if (data[i] == '\n') {
data[i] = 0;
ref_name = mid + 1;
ref = xmalloc(sizeof(struct ref) +
strlen(ref_name) + 1);
memset(ref, 0, sizeof(struct ref));
strcpy(ref->name, ref_name);
get_sha1_hex(start, ref->old_sha1);
if (!refs)
refs = ref;
if (last_ref)
last_ref->next = ref;
last_ref = ref;
start = NULL;
}
i++;
}

strbuf_release(&buffer);

ref = alloc_ref("HEAD");
if (!walker->fetch_ref(walker, ref) &&
!resolve_remote_symref(ref, refs)) {
ref->next = refs;
refs = ref;
} else {
free(ref);
}

strbuf_release(&buffer);
free(refs_url);
return refs;
}

int main(int argc, const char **argv)
{
struct remote *remote;
struct strbuf buf = STRBUF_INIT;
const char *url;
struct walker *walker = NULL;

setup_git_directory();
if (argc < 2) {
fprintf(stderr, "Remote needed\n");
return 1;
}

remote = remote_get(argv[1]);

if (argc > 2) {
url = argv[2];
} else {
url = remote->url[0];
}

do {
if (strbuf_getline(&buf, stdin, '\n') == EOF)
break;
if (!prefixcmp(buf.buf, "fetch ")) {
char *obj = buf.buf + strlen("fetch ");
if (!walker)
walker = get_http_walker(url, remote);
walker->get_all = 1;
walker->get_tree = 1;
walker->get_history = 1;
walker->get_verbosely = 0;
walker->get_recover = 0;
if (walker_fetch(walker, 1, &obj, NULL, NULL))
die("Fetch failed.");
printf("\n");
fflush(stdout);
} else if (!strcmp(buf.buf, "list")) {
struct ref *refs;
struct ref *posn;
if (!walker)
walker = get_http_walker(url, remote);
refs = get_refs(walker, url);
for (posn = refs; posn; posn = posn->next) {
if (posn->symref)
printf("@%s %s\n", posn->symref, posn->name);
else
printf("%s %s\n", sha1_to_hex(posn->old_sha1), posn->name);
}
printf("\n");
fflush(stdout);
} else if (!strcmp(buf.buf, "capabilities")) {
printf("fetch\n");
printf("\n");
fflush(stdout);
} else {
return 1;
}
strbuf_reset(&buf);
} while (1);
return 0;
}
Loading

0 comments on commit cd03eeb

Please sign in to comment.