Skip to contentSkip to conversation

Reroll of the remote-vcs-helper series

PATCH Superseded Sverre Rabbelier 4 participants 36 messages Jun 15, 2016

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Reroll of the remote-vcs-helper series

Major changes include removal of the cvs specific code as well incorperation of most of Daniel's comments. For details see the post-triple-dash of the individual patches.

Daniel, I haven't yet had time to write the 'refspec' part, but that is something that can definitely go on top of the current series.

Daniel Barkalow (7):
Fix memory leak in helper method for disconnect
Allow programs to not depend on remotes having urls
Use a function to determine whether a remote is valid Allow fetch to modify refs
Add a config option for remotes to specify a foreign vcs Add support for "import" helper command
Allow helpers to report in "list" command that the ref is unchanged

Johan Herland (1):
Basic build infrastructure for Python scripts

Johannes Schindelin (1):
Allow specifying the remote helper in the url

Sverre Rabbelier (4):
Write local refs written by the "import" helper command only once Honour the refspec when updating refs after import Allow helpers to request the path to the .git directory Add Python support library for remote helpers

 Documentation/config.txt             |    4 +
 Documentation/git-remote-helpers.txt |   14 +-
 Makefile                             |   51 +++
 builtin-clone.c                      |    8 +-
 builtin-fetch.c                      |    7 +-
 builtin-ls-remote.c                  |    4 +-
 builtin-push.c                       |   68 ++--
 configure.ac                         |    3 +
 git_remote_helpers/.gitignore        |    2 +
 git_remote_helpers/Makefile          |   35 ++
 git_remote_helpers/__init__.py       |   16 +
 git_remote_helpers/git/git.py        |  678 ++++++++++++++++++++++++++++++++++
 git_remote_helpers/setup.py          |   17 +
 git_remote_helpers/util.py           |  194 ++++++++++
 remote.c                             |   15 +-
 remote.h                             |    2 +
 t/test-lib.sh                        |   10 +
 transport-helper.c                   |   99 +++++-
 transport.c                          |   31 ++-
 transport.h                          |   43 ++-
 20 files changed, 1253 insertions(+), 48 deletions(-)
#1 lore raw

PATCH v2 1/13 Fix memory leak in helper method for disconnect

From: Daniel Barkalow <[email protected]>

Since some cases may need to disconnect from the helper and reconnect, wrap the function that just disconnects in a function that also frees transport->data.

---

Moved to the beginning of the series as it is most important.

 transport-helper.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
transport-helper.c +8 -1
index f57e84c..e24fcbb 100644
@@ -67,6 +67,13 @@ static int disconnect_helper(struct transport *transport)
 	return 0;
 }
 
+static int release_helper(struct transport *transport)
+{
+	disconnect_helper(transport);
+	free(transport->data);
+	return 0;
+}
+
 static int fetch_with_fetch(struct transport *transport,
 			    int nr_heads, const struct ref **to_fetch)
 {
@@ -163,6 +170,6 @@ int transport_helper_init(struct transport *transport, const char *name)
 	transport->data = data;
 	transport->get_refs_list = get_refs_list;
 	transport->fetch = fetch;
-	transport->disconnect = disconnect_helper;
+	transport->disconnect = release_helper;
 	return 0;
 }
Signature · 1 line
1.6.5.2.295.g0d105
#2 lore raw

PATCH v2 2/13 Allow programs to not depend on remotes having urls

In reply to Sverre Rabbelier

From: Daniel Barkalow <[email protected]>

For fetch and ls-remote, which use the first url of a remote, have transport_get() determine this by passing a remote and passing NULL for the url. For push, which uses every url of a remote, use each url in turn if there are any, and use NULL if there are none.

This will allow the transport code to do something different if the location is not specified with a url.

Also, have the message for a fetch say "foreign" if there is no url.

---

Unchanged.

 builtin-fetch.c     |    7 +++-
 builtin-ls-remote.c |    4 +-
 builtin-push.c      |   68 +++++++++++++++++++++++++++++++-------------------
 transport.c         |    3 ++
 4 files changed, 52 insertions(+), 30 deletions(-)
builtin-fetch.c +5 -2
index a35a6f8..013a6ba 100644
@@ -309,7 +309,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 	if (!fp)
 		return error("cannot open %s: %s\n", filename, strerror(errno));
 
-	url = transport_anonymize_url(raw_url);
+	if (raw_url)
+		url = transport_anonymize_url(raw_url);
+	else
+		url = xstrdup("foreign");
 	for (rm = ref_map; rm; rm = rm->next) {
 		struct ref *ref = NULL;
 
@@ -704,7 +707,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 	if (!remote)
 		die("Where do you want to fetch from today?");
 
-	transport = transport_get(remote, remote->url[0]);
+	transport = transport_get(remote, NULL);
 	if (verbosity >= 2)
 		transport->verbose = 1;
 	if (verbosity < 0)
builtin-ls-remote.c +2 -2
index 78a88f7..4c6fc58 100644
@@ -87,9 +87,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 		}
 	}
 	remote = nongit ? NULL : remote_get(dest);
-	if (remote && !remote->url_nr)
+	if (!nongit && !remote)
 		die("remote %s has no configured URL", dest);
-	transport = transport_get(remote, remote ? remote->url[0] : dest);
+	transport = transport_get(remote, remote ? NULL : dest);
 	if (uploadpack != NULL)
 		transport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);
 
builtin-push.c +42 -26

81 lines not on this page · raw message

transport.c +3 -0
index 644a30a..9daa686 100644
@@ -813,6 +813,9 @@ struct transport *transport_get(struct remote *remote, const char *url)
 	struct transport *ret = xcalloc(1, sizeof(*ret));
 
 	ret->remote = remote;
+
+	if (!url && remote && remote->url)
+		url = remote->url[0];
 	ret->url = url;
 
 	if (!prefixcmp(url, "rsync:")) {
Signature · 1 line
1.6.5.2.295.g0d105
#3 lore raw

PATCH v2 3/13 Use a function to determine whether a remote is valid

In reply to Sverre Rabbelier

From: Daniel Barkalow <[email protected]>

Currently, it only checks url, but it will allow other things in the future.

---

Unchanged.

 remote.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
remote.c +9 -4
index 73d33f2..15c9cec 100644
@@ -52,6 +52,11 @@ static struct rewrites rewrites_push;
 #define BUF_SIZE (2048)
 static char buffer[BUF_SIZE];
 
+static int valid_remote(const struct remote *remote)
+{
+	return !!remote->url;
+}
+
 static const char *alias_url(const char *url, struct rewrites *r)
 {
 	int i, j;
@@ -688,14 +693,14 @@ struct remote *remote_get(const char *name)
 
 	ret = make_remote(name, 0);
 	if (valid_remote_nick(name)) {
-		if (!ret->url)
+		if (!valid_remote(ret))
 			read_remotes_file(ret);
-		if (!ret->url)
+		if (!valid_remote(ret))
 			read_branches_file(ret);
 	}
-	if (name_given && !ret->url)
+	if (name_given && !valid_remote(ret))
 		add_url_alias(ret, name);
-	if (!ret->url)
+	if (!valid_remote(ret))
 		return NULL;
 	ret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec);
 	ret->push = parse_push_refspec(ret->push_refspec_nr, ret->push_refspec);
Signature · 1 line
1.6.5.2.295.g0d105
#4 lore raw

PATCH v2 4/13 Allow fetch to modify refs

In reply to Sverre Rabbelier

From: Daniel Barkalow <[email protected]>

This allows the transport to use the null sha1 for a ref reported to be present in the remote repository to indicate that a ref exists but its actual value is presently unknown and will be set if the objects are fetched.

Also adds documentation to the API to specify exactly what the methods should do and how they should interpret arguments.

---

Now only changes constness (changes to line 526-257 removed).

 builtin-clone.c    |    3 ++-
 transport-helper.c |    4 ++--
 transport.c        |   13 +++++++------
 transport.h        |   41 +++++++++++++++++++++++++++++++++++++++--
 4 files changed, 50 insertions(+), 11 deletions(-)
builtin-clone.c +2 -1
index caf3025..5df8b0f 100644
@@ -362,9 +362,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	const char *repo_name, *repo, *work_tree, *git_dir;
 	char *path, *dir;
 	int dest_exists;
-	const struct ref *refs, *remote_head, *mapped_refs;
+	const struct ref *refs, *remote_head;
 	const struct ref *remote_head_points_at;
 	const struct ref *our_head_points_at;
+	struct ref *mapped_refs;
 	struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
 	struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
 	struct transport *transport = NULL;
transport-helper.c +2 -2
index e24fcbb..53d8f08 100644
@@ -75,7 +75,7 @@ static int release_helper(struct transport *transport)
 }
 
 static int fetch_with_fetch(struct transport *transport,
-			    int nr_heads, const struct ref **to_fetch)
+			    int nr_heads, struct ref **to_fetch)
 {
 	struct child_process *helper = get_helper(transport);
 	FILE *file = xfdopen(helper->out, "r");
@@ -99,7 +99,7 @@ static int fetch_with_fetch(struct transport *transport,
 }
 
 static int fetch(struct transport *transport,
-		 int nr_heads, const struct ref **to_fetch)
+		 int nr_heads, struct ref **to_fetch)
 {
 	struct helper_data *data = transport->data;
 	int i, count;
transport.c +7 -6
index 9daa686..5ae8db6 100644
@@ -204,7 +204,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
 }
 
 static int fetch_objs_via_rsync(struct transport *transport,
-				int nr_objs, const struct ref **to_fetch)
+				int nr_objs, struct ref **to_fetch)
 {
 	struct strbuf buf = STRBUF_INIT;
 	struct child_process rsync;
@@ -408,7 +408,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus
 }
 
 static int fetch_refs_from_bundle(struct transport *transport,
-			       int nr_heads, const struct ref **to_fetch)
+			       int nr_heads, struct ref **to_fetch)
 {
 	struct bundle_transport_data *data = transport->data;
 	return unbundle(&data->header, data->fd);
@@ -486,7 +486,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
 }
 
 static int fetch_refs_via_pack(struct transport *transport,
-			       int nr_heads, const struct ref **to_fetch)
+			       int nr_heads, struct ref **to_fetch)
 {
 	struct git_transport_data *data = transport->data;
 	char **heads = xmalloc(nr_heads * sizeof(*heads));
@@ -926,16 +926,17 @@ const struct ref *transport_get_remote_refs(struct transport *transport)
 	return transport->remote_refs;
 }
 
-int transport_fetch_refs(struct transport *transport, const struct ref *refs)
+int transport_fetch_refs(struct transport *transport, struct ref *refs)
 {
 	int rc;
 	int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
-	const struct ref **heads = NULL;
-	const struct ref *rm;
+	struct ref **heads = NULL;
+	struct ref *rm;
 
 	for (rm = refs; rm; rm = rm->next) {
 		nr_refs++;
 		if (rm->peer_ref &&
+		    !is_null_sha1(rm->old_sha1) &&
 		    !hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))
 			continue;
 		ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
transport.h +39 -2

57 lines not on this page · raw message

Signature · 1 line
1.6.5.2.295.g0d105
#5 lore raw

PATCH v2 5/13 Add a config option for remotes to specify a foreign vcs

In reply to Sverre Rabbelier

From: Daniel Barkalow <[email protected]>

If this is set, the url is not required, and the transport always uses a helper named "git-remote-<value>".

It is a separate configuration option in order to allow a sensible configuration for foreign systems which either have no meaningful urls for repositories or which require urls that do not specify the system used by the repository at that location. However, this only affects how the name of the helper is determined, not anything about the interaction with the helper, and the contruction is such that, if the foreign scm does happen to use a co-named url method, a url with that method may be used directly.

---

Unchanged.

 Documentation/config.txt |    4 ++++
 remote.c                 |    4 +++-
 remote.h                 |    2 ++
 transport.c              |    5 +++++
 4 files changed, 14 insertions(+), 1 deletions(-)
Documentation/config.txt +4 -0
index d1e2120..0d9d369 100644
@@ -1408,6 +1408,10 @@ remote.<name>.tagopt::
 	Setting this value to \--no-tags disables automatic tag following when
 	fetching from remote <name>
 
+remote.<name>.vcs::
+	Setting this to a value <vcs> will cause git to interact with
+	the remote with the git-remote-<vcs> helper.
+
 remotes.<group>::
 	The list of remotes which are fetched by "git remote update
 	<group>".  See linkgit:git-remote[1].
remote.c +3 -1
index 15c9cec..09bb79c 100644
@@ -54,7 +54,7 @@ static char buffer[BUF_SIZE];
 
 static int valid_remote(const struct remote *remote)
 {
-	return !!remote->url;
+	return (!!remote->url) || (!!remote->foreign_vcs);
 }
 
 static const char *alias_url(const char *url, struct rewrites *r)
@@ -444,6 +444,8 @@ static int handle_config(const char *key, const char *value, void *cb)
 	} else if (!strcmp(subkey, ".proxy")) {
 		return git_config_string((const char **)&remote->http_proxy,
 					 key, value);
+	} else if (!strcmp(subkey, ".vcs")) {
+		return git_config_string(&remote->foreign_vcs, key, value);
 	}
 	return 0;
 }
remote.h +2 -0
index 5db8420..ac0ce2f 100644
@@ -11,6 +11,8 @@ struct remote {
 	const char *name;
 	int origin;
 
+	const char *foreign_vcs;
+
 	const char **url;
 	int url_nr;
 	int url_alloc;
transport.c +5 -0
index 5ae8db6..13bab4e 100644
@@ -818,6 +818,11 @@ struct transport *transport_get(struct remote *remote, const char *url)
 		url = remote->url[0];
 	ret->url = url;
 
+	if (remote && remote->foreign_vcs) {
+		transport_helper_init(ret, remote->foreign_vcs);
+		return ret;
+	}
+
 	if (!prefixcmp(url, "rsync:")) {
 		ret->get_refs_list = get_refs_via_rsync;
 		ret->fetch = fetch_objs_via_rsync;
Signature · 1 line
1.6.5.2.295.g0d105
#6 lore raw

PATCH v2 6/13 Allow specifying the remote helper in the url

In reply to Sverre Rabbelier

From: Johannes Schindelin <[email protected]>

The common case for remote helpers will be to import some repository which can be specified by a single URL. Support this use case by allowing users to say:

git clone hg::https://soc.googlecode.com/hg/ soc

---

Reworded commit message to be more neutral.

 transport.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
transport.c +10 -0
index 13bab4e..5d814b5 100644
@@ -818,6 +818,16 @@ struct transport *transport_get(struct remote *remote, const char *url)
 		url = remote->url[0];
 	ret->url = url;
 
+	/* maybe it is a foreign URL? */
+	if (url) {
+		const char *p = url;
+
+		while (isalnum(*p))
+			p++;
+		if (!prefixcmp(p, "::"))
+			remote->foreign_vcs = xstrndup(url, p - url);
+	}
+
 	if (remote && remote->foreign_vcs) {
 		transport_helper_init(ret, remote->foreign_vcs);
 		return ret;
Signature · 1 line
1.6.5.2.295.g0d105
#7 lore raw

PATCH v2 7/13 Add support for "import" helper command

In reply to Sverre Rabbelier

From: Daniel Barkalow <[email protected]>

This command, supported if the "import" capability is advertized, allows a helper to support fetching by outputting a git-fast-import stream.

If both "fetch" and "import" are advertized, git itself will use "fetch" (although other users may use "import" in this case).

---

Undid the change to the read_ref line, see patch 0009 for a suggested proper fix.

 Documentation/git-remote-helpers.txt |   10 ++++++
 transport-helper.c                   |   52 ++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)
Documentation/git-remote-helpers.txt +10 -0
index 173ee23..e9aa67e 100644
@@ -43,6 +43,13 @@ Commands are given by the caller on the helper's standard input, one per line.
 +
 Supported if the helper has the "fetch" capability.
 
+'import' <name>::
+	Produces a fast-import stream which imports the current value
+	of the named ref. It may additionally import other refs as
+	needed to construct the history efficiently.
++
+Supported if the helper has the "import" 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
@@ -57,6 +64,9 @@ CAPABILITIES
 'fetch'::
 	This helper supports the 'fetch' command.
 
+'import'::
+	This helper supports the 'import' command.
+
 REF LIST ATTRIBUTES
 -------------------
 
transport-helper.c +52 -0

76 lines not on this page · raw message

Signature · 1 line
1.6.5.2.295.g0d105
#8 lore raw

PATCH v2 8/13 Write local refs written by the "import" helper command only once

In reply to Sverre Rabbelier

At clone time the "import" helper command has already written a packfile with all refs, so write_remote_refs will create a duplicate entry for each ref returned by wanted_peer_refs. Prevent this duplication by setting fetched_refs_written in the transport when executing the "import" helper command and only adding the extra refs if it is not set.

---

I am not 100% sure this is the proper fix, but I do know that without this I get a .git/packed-refs file that has duplicate entries in it.

 builtin-clone.c    |    5 ++++-
 transport-helper.c |    3 +++
 transport.h        |    2 ++
 3 files changed, 9 insertions(+), 1 deletions(-)
builtin-clone.c +4 -1
index 5df8b0f..e44347e 100644
@@ -542,7 +542,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	if (refs) {
 		clear_extra_refs();
 
-		write_remote_refs(mapped_refs);
+		if(transport->fetched_refs_written)
+			pack_refs(PACK_REFS_ALL);
+		else
+			write_remote_refs(mapped_refs);
 
 		remote_head = find_ref_by_name(refs, "HEAD");
 		remote_head_points_at =
transport-helper.c +3 -0
index 82caaae..148496c 100644
@@ -165,7 +165,10 @@ static int fetch(struct transport *transport,
 		return fetch_with_fetch(transport, nr_heads, to_fetch);
 
 	if (data->import)
+	{
+		transport->fetched_refs_written = 1;
 		return fetch_with_import(transport, nr_heads, to_fetch);
+	}
 
 	return -1;
 }
transport.h +2 -0
index 503db11..7458b9e 100644
@@ -65,6 +65,8 @@ struct transport {
 	signed verbose : 2;
 	/* Force progress even if the output is not a tty */
 	unsigned progress : 1;
+	/* Refs fetched by transport_get_remote_refs are already written */
+	unsigned fetched_refs_written : 1;
 };
 
 #define TRANSPORT_PUSH_ALL 1
Signature · 1 line
1.6.5.2.295.g0d105
#9 lore raw

PATCH v2 9/13 Honour the refspec when updating refs after import

In reply to Sverre Rabbelier

This way the helper can write to 'refs/remotes/origin/*' instead of writing to 'refs/heads/*'.

---

Daniel, does this look good to you?

Let's assume the following:
* list: only HEAD is a symref (to refs/heads/<branch>), all other refs are '? refs/heads/<branch>'.
* import: the helper creates branches under refs/remotes/<alias>/* (since the refspec code is not yet in that would allow it to create them under refs/<vcs>/<alias>/*)

Now when updating the refs we do the following:
transport-helper.c:145 "read_ref(posn->name, posn->old_sha1);"

The value of posn->name looks like "refs/heads/<branch>". So what does this lookup do? It tries to lookup the new value of the ref _where it will be created_, this fails of course, since the ref currently only exists as "refs/remotes/origin/<branch>". So, we should instead be doing a lookup using posn->peer_ref->name, and not do a lookup at all if it posn->peer_ref is not set (which should not occur as we are passed only wanted peer refs).

Please let me know if this makes sense and both this and 0008 can be squashed with 0007.

 transport-helper.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
transport-helper.c +4 -1
index 148496c..72ed95b 100644
@@ -142,7 +142,10 @@ static int fetch_with_import(struct transport *transport,
 		posn = to_fetch[i];
 		if (posn->status & REF_STATUS_UPTODATE)
 			continue;
-		read_ref(posn->name, posn->old_sha1);
+		if(posn->peer_ref) {
+			read_ref(posn->peer_ref->name, posn->peer_ref->old_sha1);
+			hashcpy(posn->old_sha1, posn->peer_ref->old_sha1);
+		}
 	}
 	return 0;
 }
Signature · 1 line
1.6.5.2.295.g0d105
#10 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Quoted 18 lines · Sverre Rabbelier

This way the helper can write to 'refs/remotes/origin/*' instead of writing to 'refs/heads/*'.

---

Daniel, does this look good to you?

Let's assume the following:
* list: only HEAD is a symref (to refs/heads/<branch>), all other refs are '? refs/heads/<branch>'.
* import: the helper creates branches under refs/remotes/<alias>/* (since the refspec code is not yet in that would allow it to create them under refs/<vcs>/<alias>/*)

Now when updating the refs we do the following:
transport-helper.c:145 "read_ref(posn->name, posn->old_sha1);"

Quoted 7 lines

The value of posn->name looks like "refs/heads/<branch>". So what does this lookup do? It tries to lookup the new value of the ref _where it will be created_, this fails of course, since the ref currently only exists as "refs/remotes/origin/<branch>". So, we should instead be doing a lookup using posn->peer_ref->name, and not do a lookup at all if it posn->peer_ref is not set (which should not occur as we are passed only wanted peer refs).

That's not true for "git pull <url> <branch>"; we do want the remote ref, but it doesn't have a local peer. I think going straight to the refspec command is the right answer.

-Daniel
*This .sig left intentionally blank*

#11 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Heya,

Quoted 3 lines · Daniel Barkalow

That's not true for "git pull <url> <branch>"; we do want the remote ref, but it doesn't have a local peer. I think going straight to the refspec command is the right answer.

Can you clarity what you mean with "the refspec command"?

Signature · 3 lines
Cheers,

Sverre Rabbelier
#12 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Quoted 8 lines · Sverre Rabbelier

Heya,

Quoted 3 lines · Daniel Barkalow

That's not true for "git pull <url> <branch>"; we do want the remote ref, but it doesn't have a local peer. I think going straight to the refspec command is the right answer.

Can you clarity what you mean with "the refspec command"?

Whatever it is that lets the helper tell the transport code where in the helper's private namespace to look for refs. I'd been thinking the helper would advertize the "refspec" capability, and the transport code would call the "refspec" command in order to get the helper to report that; but then I actually only said that the helper reports refspec, and not proposed a name for the command.

-Daniel
*This .sig left intentionally blank*

#13 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Heya,

Quoted 4 lines · Daniel Barkalow
Quoted 3 lines · Sverre Rabbelier
Quoted 2 lines · Daniel Barkalow

That's not true for "git pull <url> <branch>"; we do want the remote ref, but it doesn't have a local peer.

No, I don't think that's right, when doing a fetch we want to store the refs somewhere, sure, but not under 'refs/heads/<branch>', perhaps 'refs/hg/fetch/<branch>', either way, the current code does not work.

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

I think going straight to the refspec
command is the right answer.

Can you clarity what you mean with "the refspec command"?

Whatever it is that lets the helper tell the transport code where in the helper's private namespace to look for refs. I'd been thinking the helper would advertize the "refspec" capability, and the transport code would call the "refspec" command in order to get the helper to report that; but then I actually only said that the helper reports refspec, and not proposed a name for the command.

Currently I'm implementing so that it would work like this for the svn helper:

$ echo capabilities | git remote-svn origin /path/to/hg/repo
import
refspec +refs/trunk:refs/svn/origin/trunk
refspec +refs/branches/*:refs/svn/origin/*

That way we can put the refspec in the config file at clone time.

Now I've been browsing through the builtin-fetch code, and it looks like the main problem is going to be to apply this refspec at all. I'll have a more extensive look tomorrow.

Signature · 3 lines
Cheers,

Sverre Rabbelier
#14 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Quoted 11 lines · Sverre Rabbelier

Heya,

Quoted 4 lines · Daniel Barkalow
Quoted 3 lines · Sverre Rabbelier
Quoted 2 lines · Daniel Barkalow

That's not true for "git pull <url> <branch>"; we do want the remote ref, but it doesn't have a local peer.

No, I don't think that's right, when doing a fetch we want to store the refs somewhere, sure, but not under 'refs/heads/<branch>', perhaps 'refs/hg/fetch/<branch>', either way, the current code does not work.

I think you've still got things backwards. From the point of view of transport.c, refs/<vcs> is entirely opaque, and we never look at it. Those aren't local peers. They're a way for the helper to communicate to transport-helper.c. The user says: pull refs/heads/master of this hg repo. Transport.c tries to fetch refs/heads/master and get the sha1 to write into FETCH_HEAD or wherever. Transport-helper.c says "import refs/heads/master", and git-fast-import reads the resulting script and writes some ref that the helper tells it to write. Then transport-helper.c figures out where the ref was written, reads it, and updates the struct ref representing the remote info. Then builtin-fetch looks at the struct ref and writes it to the local repositories ref namespace or FETCH_HEAD.

Quoted 19 lines
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

I think going straight to the refspec
command is the right answer.

Can you clarity what you mean with "the refspec command"?

Whatever it is that lets the helper tell the transport code where in the helper's private namespace to look for refs. I'd been thinking the helper would advertize the "refspec" capability, and the transport code would call the "refspec" command in order to get the helper to report that; but then I actually only said that the helper reports refspec, and not proposed a name for the command.

Currently I'm implementing so that it would work like this for the svn helper:

$ echo capabilities | git remote-svn origin /path/to/hg/repo
import
refspec +refs/trunk:refs/svn/origin/trunk
refspec +refs/branches/*:refs/svn/origin/*
Quoted 5 lines

That way we can put the refspec in the config file at clone time.

Now I've been browsing through the builtin-fetch code, and it looks like the main problem is going to be to apply this refspec at all. I'll have a more extensive look tomorrow.

This is entirely not what I think we should have. The config file should say refs/heads/*:refs/remotes/origin/* like it always does, because the transport will list the refs like refs/heads/* and refs/tags/* and return them like that.

I'll see if I can write up an untested patch that does what I'm thinking of.

-Daniel
*This .sig left intentionally blank*

#15 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Quoted 51 lines · Daniel Barkalow
Quoted 11 lines · Sverre Rabbelier

Heya,

Quoted 4 lines · Daniel Barkalow
Quoted 3 lines · Sverre Rabbelier
Quoted 2 lines · Daniel Barkalow

That's not true for "git pull <url> <branch>"; we do want the remote ref, but it doesn't have a local peer.

No, I don't think that's right, when doing a fetch we want to store the refs somewhere, sure, but not under 'refs/heads/<branch>', perhaps 'refs/hg/fetch/<branch>', either way, the current code does not work.

I think you've still got things backwards. From the point of view of transport.c, refs/<vcs> is entirely opaque, and we never look at it. Those aren't local peers. They're a way for the helper to communicate to transport-helper.c. The user says: pull refs/heads/master of this hg repo. Transport.c tries to fetch refs/heads/master and get the sha1 to write into FETCH_HEAD or wherever. Transport-helper.c says "import refs/heads/master", and git-fast-import reads the resulting script and writes some ref that the helper tells it to write. Then transport-helper.c figures out where the ref was written, reads it, and updates the struct ref representing the remote info. Then builtin-fetch looks at the struct ref and writes it to the local repositories ref namespace or FETCH_HEAD.

Quoted 19 lines
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

I think going straight to the refspec
command is the right answer.

Can you clarity what you mean with "the refspec command"?

Whatever it is that lets the helper tell the transport code where in the helper's private namespace to look for refs. I'd been thinking the helper would advertize the "refspec" capability, and the transport code would call the "refspec" command in order to get the helper to report that; but then I actually only said that the helper reports refspec, and not proposed a name for the command.

Currently I'm implementing so that it would work like this for the svn helper:

$ echo capabilities | git remote-svn origin /path/to/hg/repo
import
refspec +refs/trunk:refs/svn/origin/trunk
refspec +refs/branches/*:refs/svn/origin/*
Quoted 5 lines

That way we can put the refspec in the config file at clone time.

Now I've been browsing through the builtin-fetch code, and it looks like the main problem is going to be to apply this refspec at all. I'll have a more extensive look tomorrow.

Quoted 7 lines

This is entirely not what I think we should have. The config file should say refs/heads/*:refs/remotes/origin/* like it always does, because the transport will list the refs like refs/heads/* and refs/tags/* and return them like that.

I'll see if I can write up an untested patch that does what I'm thinking of.

Here's a patch (on my original series, which doesn't seem to be in pu any more, but should be floating around somewhere). Completely untested, except that it compiles. The idea is that the helper will say something like:

refspec refs/heads/master:refs/svn/origin/trunk
refspec refs/heads/*:refs/svn/origin/branches/*
refspec refs/tags/*:refs/svn/origin/tags/*

and transport-helper will use these patterns to figure out where to find the correct value from the helper's private namespace when asked to fetch refs/heads/topic.

-Daniel

commit 483836f6411d2317f24c7594c557fb01133508b6

Author: Daniel Barkalow <[email protected]>
Date:   Thu Nov 5 01:39:02 2009 -0500

Allow helper to map private ref names into normal names

This allows a helper to say that, when it handles "import refs/heads/topic", the script it outputs will actually write to refs/svn/origin/branches/topic; therefore, transport-helper should read it from the latter location after git-fast-import completes.

remote.c +18 -0
index f0441c4..58d1a61 100644
@@ -790,6 +790,24 @@ static int match_name_with_pattern(const char *key, const char *name,
 	return ret;
 }
 
+char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
+		     const char *name)
+{
+	int i;
+	char *ret = NULL;
+	for (i = 0; i < nr_refspec; i++) {
+		struct refspec *refspec = refspecs + i;
+		if (refspec->pattern) {
+			if (match_name_with_pattern(refspec->src, name,
+						    refspec->dst, &ret))
+				return ret;
+		} else if (!strcmp(refspec->src, name))
+			return strdup(refspec->dst);
+	}
+	return NULL;
+	
+}
+
 int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 {
 	int find_src = refspec->src == NULL;
remote.h +3 -0
index ac0ce2f..c2f920b 100644
@@ -91,6 +91,9 @@ void ref_remove_duplicates(struct ref *ref_map);
 int valid_fetch_refspec(const char *refspec);
 struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
 
+char *apply_refspecs(struct refspec *refspecs, int nr_refspec,
+		     const char *name);
+
 int match_refs(struct ref *src, struct ref **dst,
 	       int nr_refspec, const char **refspec, int all);
 
transport-helper.c +25 -1
index aa5ad3c..88573e7 100644
@@ -5,6 +5,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
+#include "remote.h"
 
 struct helper_data
 {
@@ -12,6 +13,9 @@ struct helper_data
 	struct child_process *helper;
 	unsigned fetch : 1;
 	unsigned import : 1;
+	/* These go from remote name (as in "list") to private name */
+	struct refspec *refspecs;
+	int refspec_nr;
 };
 
 static struct child_process *get_helper(struct transport *transport)
@@ -20,6 +24,9 @@ static struct child_process *get_helper(struct transport *transport)
 	struct strbuf buf = STRBUF_INIT;
 	struct child_process *helper;
 	FILE *file;
+	const char **refspecs = NULL;
+	int refspec_nr = 0;
+	int refspec_alloc = 0;
 
 	if (data->helper)
 		return data->helper;
@@ -53,6 +60,16 @@ static struct child_process *get_helper(struct transport *transport)
 			data->fetch = 1;
 		if (!strcmp(buf.buf, "import"))
 			data->import = 1;
+		if (!prefixcmp(buf.buf, "refspec ")) {
+			ALLOC_GROW(refspecs,
+				   refspec_nr + 1,
+				   refspec_alloc);
+			refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
+		}
+	}
+	if (refspecs) {
+		data->refspec_nr = refspec_nr;
+		data->refspecs = parse_fetch_refspec(refspec_nr, refspecs);
 	}
 	return data->helper;
 }
@@ -121,6 +138,7 @@ static int fetch_with_import(struct transport *transport,
 {
 	struct child_process fastimport;
 	struct child_process *helper = get_helper(transport);
+	struct helper_data *data = transport->data;
 	int i;
 	struct ref *posn;
 	struct strbuf buf = STRBUF_INIT;
@@ -141,10 +159,16 @@ static int fetch_with_import(struct transport *transport,
 	finish_command(&fastimport);
 
 	for (i = 0; i < nr_heads; i++) {
+		char *private;
 		posn = to_fetch[i];
 		if (posn->status & REF_STATUS_UPTODATE)
 			continue;
-		read_ref(posn->name, posn->old_sha1);
+		if (data->refspecs)
+			private = apply_refspecs(data->refspecs, data->refspec_nr, posn->name);
+		else
+			private = strdup(posn->name);
+		read_ref(private, posn->old_sha1);
+		free(private);
 	}
 	return 0;
 }
#16 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Heya,

Quoted 2 lines · Daniel Barkalow

Here's a patch (on my original series, which doesn't seem to be in pu any more, but should be floating around somewhere).

Why didn't you just base it against sr/vcs-helper which is currently in pu, now I have to try to find where your original series was, and rebase this patch against it. Assuming your main goal was to illustrate the direction you think we should go it would have been a lot easier that way.

Signature · 3 lines
Cheers,

Sverre Rabbelier
#17 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Quoted 11 lines · Sverre Rabbelier

Heya,

Quoted 2 lines · Daniel Barkalow

Here's a patch (on my original series, which doesn't seem to be in pu any more, but should be floating around somewhere).

Why didn't you just base it against sr/vcs-helper which is currently in pu, now I have to try to find where your original series was, and rebase this patch against it. Assuming your main goal was to illustrate the direction you think we should go it would have been a lot easier that way.

I didn't understand the version of my patch that contains your changes, and I didn't know what was in it. I don't know why Junio squashed your changes into my patch, particularly when I disagreed with those changes.

-Daniel
*This .sig left intentionally blank*

#18 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Heya,

Quoted 2 lines · Daniel Barkalow

I didn't understand the version of my patch that contains your changes, and I didn't know what was in it.

Either way, I managed to apply your patch, will send a new version of the series tomorrow.

Quoted 2 lines

I don't know why Junio squashed your
changes into my patch, particularly when I disagreed with those changes.

Junio didn't squash anything, it's just that pu still contains v4 of the series, in which I had squashed my changes in.

Signature · 3 lines
Cheers,

Sverre Rabbelier
#19 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Quoted 8 lines · Sverre Rabbelier

Heya,

Quoted 2 lines · Daniel Barkalow

I didn't understand the version of my patch that contains your changes, and I didn't know what was in it.

Either way, I managed to apply your patch, will send a new version of the series tomorrow.

Does it make sense now in what it's trying to do? (And does it turn out to work?) I'm fairly certain it's the easiest way to make the remote appear most natural to the rest of git, but I don't actually have code that wants to use it, so I wouldn't know if this just wouldn't work for hg or something.

Quoted 5 lines
Quoted 2 lines

I don't know why Junio squashed your
changes into my patch, particularly when I disagreed with those changes.

Junio didn't squash anything, it's just that pu still contains v4 of the series, in which I had squashed my changes in.

Oh, okay. You probably shouldn't squash un-acked changes into other people's patches when taking over their series.

-Daniel
*This .sig left intentionally blank*

#20 lore raw

Re: [PATCH v2 09/13] Honour the refspec when updating refs after import

Quoted 10 lines · Daniel Barkalow
Quoted 5 lines · Sverre Rabbelier
Quoted 2 lines

I don't know why Junio squashed your
changes into my patch, particularly when I disagreed with those changes.

Junio didn't squash anything, it's just that pu still contains v4 of the series, in which I had squashed my changes in.

Oh, okay. You probably shouldn't squash un-acked changes into other people's patches when taking over their series.

Thanks for having this exchange. You are right, and I should have more explicitly explained what I was doing when I replaced two series (yours and Johan's cvs series) with Sverre's consolidated re-roll.

#21 lore raw

PATCH v2 10/13 Allow helpers to report in "list" command that the ref is unchanged

In reply to Sverre Rabbelier

From: Daniel Barkalow <[email protected]>

Helpers may use a line like "? name unchanged" to specify that there is nothing new at that name, without any git-specific code to determine the correct response.

---

Unchanged.

 Documentation/git-remote-helpers.txt |    4 +++-
 transport-helper.c                   |   22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletions(-)
Documentation/git-remote-helpers.txt +3 -1
index e9aa67e..2c5130f 100644
@@ -70,7 +70,9 @@ CAPABILITIES
 REF LIST ATTRIBUTES
 -------------------
 
-None are defined yet, but the caller must accept any which are supplied.
+'unchanged'::
+	This ref is unchanged since the last import or fetch, although
+	the helper cannot necessarily determine what value that produced.
 
 Documentation
 -------------
transport-helper.c +22 -0
index 72ed95b..a80d803 100644
@@ -176,6 +176,22 @@ static int fetch(struct transport *transport,
 	return -1;
 }
 
+static int has_attribute(const char *attrs, const char *attr) {
+	int len;
+	if (!attrs)
+		return 0;
+
+	len = strlen(attr);
+	for (;;) {
+		const char *space = strchrnul(attrs, ' ');
+		if (len == space - attrs && !strncmp(attrs, attr, len))
+			return 1;
+		if (!*space)
+			return 0;
+		attrs = space + 1;
+	}
+}
+
 static struct ref *get_refs_list(struct transport *transport, int for_push)
 {
 	struct child_process *helper;
@@ -210,6 +226,12 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
 			(*tail)->symref = xstrdup(buf.buf + 1);
 		else if (buf.buf[0] != '?')
 			get_sha1_hex(buf.buf, (*tail)->old_sha1);
+		if (eon) {
+			if (has_attribute(eon + 1, "unchanged")) {
+				(*tail)->status |= REF_STATUS_UPTODATE;
+				read_ref((*tail)->name, (*tail)->old_sha1);
+			}
+		}
 		tail = &((*tail)->next);
 	}
 	strbuf_release(&buf);
Signature · 1 line
1.6.5.2.295.g0d105
#22 lore raw

PATCH v2 11/13 Allow helpers to request the path to the .git directory

In reply to Sverre Rabbelier

The 'gitdir' capability is reported by the remote helper if it requires the location of the .git directory. The location of the .git directory can then be used by the helper to store status files even when the current directory is not a git repository (such as is the case when cloning).

The location of the .git dir is specified as an absolute path.

---

Daniel, is this a good idea, or should we perhaps tell the helper the location of the git repository otherwise?

 transport-helper.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
transport-helper.c +6 -0
index a80d803..4f95e7b 100644
@@ -51,6 +51,12 @@ static struct child_process *get_helper(struct transport *transport)
 			data->fetch = 1;
 		if (!strcmp(buf.buf, "import"))
 			data->import = 1;
+		if (!strcmp(buf.buf, "gitdir")) {
+			struct strbuf gitdir = STRBUF_INIT;
+			strbuf_addf(&gitdir, "gitdir %s\n", get_git_dir());
+			write_in_full(helper->in, gitdir.buf, gitdir.len);
+			strbuf_reset(&gitdir);
+		}
 	}
 	return data->helper;
 }
Signature · 1 line
1.6.5.2.295.g0d105
#23 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Quoted 7 lines · Sverre Rabbelier

The 'gitdir' capability is reported by the remote helper if it requires the location of the .git directory. The location of the .git directory can then be used by the helper to store status files even when the current directory is not a git repository (such as is the case when cloning).

The location of the .git dir is specified as an absolute path.

I thought we cd into the repository in the middle of clone somewhere, before running stuff. In any case, I think it would be good to have something like that, but I think maybe we should tell it where it can put its status files, rather than telling it where the .git dir is. It would also be nice if this is the absolute path that gfi will base a relative path for the "marks" options on when importing.

-Daniel
*This .sig left intentionally blank*

#24 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Heya,

Quoted 2 lines · Daniel Barkalow

I thought we cd into the repository in the middle of clone somewhere, before running stuff.

It does, but not soon enough, that is, not before I needed it in my helper.

Quoted 3 lines

In any case, I think it would be good to have
something like that, but I think maybe we should tell it where it can put its status files, rather than telling it where the .git dir is.

Yes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?

Quoted 3 lines

It would
also be nice if this is the absolute path that gfi will base a relative path for the "marks" options on when importing.

The marks option has been dumped in favor of 'feature import-marks=' and 'feature export-marks=' which will be in the reroll of sr/gfi-options.

Signature · 3 lines
Cheers,

Sverre Rabbelier
#25 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Quoted 5 lines · Sverre Rabbelier
Quoted 3 lines

In any case, I think it would be good to have
something like that, but I think maybe we should tell it where it can put its status files, rather than telling it where the .git dir is.

Yes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?

What do you mean by <alias> here? Is it the <alias> in

	[remote "alias"]
                url = hg::http://some.where/repo/sito/ry.hg

IOW, can a user ever use the foreign interface directly from the command line, without ever defining such entries in .git/config, perhaps using "git remote"?

#26 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Heya,

Quoted 4 lines · Junio C Hamano

What do you mean by <alias> here?  Is it the <alias> in

       [remote "alias"]
               url = hg::http://some.where/repo/sito/ry.hg

Yes, that one.

Quoted 3 lines

IOW, can a user ever use the foreign interface directly from the command line, without ever defining such entries in .git/config, perhaps using "git remote"?

No, my primary use case for remote helpers is currently 'git clone hg::https://soc.googlecode.com/hg/', and to have 'git fetch origin' Just Work (tm) from that clone. My secondary use case though, is to support 'git fetch hg:: https://soc.googlecode.com/hg/' just as well and have 'git log FETCH_HEAD' Just Work (tm) too. In that light .git/info/remote-<vcs>/ is probably a better idea, so that the helper can use say '.git/info/remote-<vcs>/fetch/ for one-time fetches.

Signature · 3 lines
Cheers,

Sverre Rabbelier
#27 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

In reply to Sverre Rabbelier
Quoted 6 lines · Sverre Rabbelier

Heya,

Quoted 2 lines · Daniel Barkalow

I thought we cd into the repository in the middle of clone somewhere, before running stuff.

Quoted 7 lines

It does, but not soon enough, that is, not before I needed it in my helper.

Quoted 3 lines

In any case, I think it would be good to have
something like that, but I think maybe we should tell it where it can put its status files, rather than telling it where the .git dir is.

Yes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?

Seems reasonable to me, unless we make it .git/info/remote-<vcs>, and tell helper authors to deal with having different imports not conflict with each other.

Quoted 7 lines
Quoted 3 lines

It would
also be nice if this is the absolute path that gfi will base a relative path for the "marks" options on when importing.

The marks option has been dumped in favor of 'feature import-marks=' and 'feature export-marks=' which will be in the reroll of sr/gfi-options.

Right, but the values of those have to be paths, and I think they should be relative paths, relative to the helper's state directory.

-Daniel
*This .sig left intentionally blank*

#28 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Heya,

Quoted 5 lines · Daniel Barkalow
Quoted 1 line

Yes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?

Seems reasonable to me, unless we make it .git/info/remote-<vcs>, and tell helper authors to deal with having different imports not conflict with each other.

Ah, yeah, the helper might want to store some global state as well, so '.git/info/remote-<vcs>' is probably best.

Quoted 6 lines
Quoted 3 lines

The marks option has been dumped in favor of 'feature import-marks=' and 'feature export-marks=' which will be in the reroll of sr/gfi-options.

Right, but the values of those have to be paths, and I think they should be relative paths, relative to the helper's state directory.

Hmmm, I don't remember exactly what we decided the paths should be releative, pretty sure it was somewhere in .git/ though.

Signature · 3 lines
Cheers,

Sverre Rabbelier
#29 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Quoted 7 lines · Sverre Rabbelier

Heya,

Quoted 4 lines · Daniel Barkalow
Quoted 3 lines

The marks option has been dumped in favor of 'feature import-marks=' and 'feature export-marks=' which will be in the reroll of sr/gfi-options.

Quoted 5 lines
Quoted 2 lines

Right, but the values of those have to be paths, and I think they should be relative paths, relative to the helper's state directory.

Hmmm, I don't remember exactly what we decided the paths should be releative, pretty sure it was somewhere in .git/ though.

Well, gfi is used with different native systems, each of which will presumably put it somewhere different.

-Daniel
*This .sig left intentionally blank*

#30 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Heya,

Quoted 2 lines · Daniel Barkalow

Well, gfi is used with different native systems, each of which will presumably put it somewhere different.

Right, but I meant for git itself :). I assume that you meant that 'gitdir' (or 'infodir' , whatever) should return the same path, whatever we decide on?q

Signature · 3 lines
Cheers,

Sverre Rabbelier
#31 lore raw

Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory

Quoted 9 lines · Sverre Rabbelier

Heya,

Quoted 2 lines · Daniel Barkalow

Well, gfi is used with different native systems, each of which will presumably put it somewhere different.

Right, but I meant for git itself :). I assume that you meant that 'gitdir' (or 'infodir' , whatever) should return the same path, whatever we decide on?q

Yeah. I think the base that git uses wasn't decided on, although I may have missed that part of the thread. In any case, I do think it should be the directory passed to the helper.

-Daniel
*This .sig left intentionally blank*

#32 lore raw

PATCH v2 12/13 Basic build infrastructure for Python scripts

In reply to Sverre Rabbelier

From: Johan Herland <[email protected]>

This patch adds basic boilerplate support (based on corresponding Perl sections) for enabling the building and installation Python scripts.

There are currently no Python scripts being built, and when Python scripts are added in future patches, their building and installation can be disabled by defining NO_PYTHON.

---

Unchanged.

 Makefile      |   13 +++++++++++++
 configure.ac  |    3 +++
 t/test-lib.sh |    1 +
 3 files changed, 17 insertions(+), 0 deletions(-)
Makefile +13 -0
index 5d5976f..6d1593f 100644
@@ -168,6 +168,8 @@ all::
 #
 # Define NO_PERL if you do not want Perl scripts or libraries at all.
 #
+# Define NO_PYTHON if you do not want Python scripts or libraries at all.
+#
 # Define NO_TCLTK if you do not want Tcl/Tk GUI.
 #
 # The TCL_PATH variable governs the location of the Tcl interpreter
@@ -312,6 +314,7 @@ LIB_H =
 LIB_OBJS =
 PROGRAMS =
 SCRIPT_PERL =
+SCRIPT_PYTHON =
 SCRIPT_SH =
 TEST_PROGRAMS =
 
@@ -349,6 +352,7 @@ SCRIPT_PERL += git-svn.perl
 
 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \
 	  $(patsubst %.perl,%,$(SCRIPT_PERL)) \
+	  $(patsubst %.py,%,$(SCRIPT_PYTHON)) \
 	  git-instaweb
 
 # Empty...
@@ -402,8 +406,12 @@ endif
 ifndef PERL_PATH
 	PERL_PATH = /usr/bin/perl
 endif
+ifndef PYTHON_PATH
+	PYTHON_PATH = /usr/bin/python
+endif
 
 export PERL_PATH
+export PYTHON_PATH
 
 LIB_FILE=libgit.a
 XDIFF_LIB=xdiff/lib.a
@@ -1315,6 +1323,10 @@ ifeq ($(PERL_PATH),)
 NO_PERL=NoThanks
 endif
 
+ifeq ($(PYTHON_PATH),)
+NO_PYTHON=NoThanks
+endif
+
 QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
 QUIET_SUBDIR1  =
 
@@ -1362,6 +1374,7 @@ prefix_SQ = $(subst ','\'',$(prefix))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
+PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
 TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
 
 LIBS = $(GITLIBS) $(EXTLIBS)
configure.ac +3 -0
index b09b8e4..84b6cf4 100644
@@ -233,6 +233,9 @@ GIT_ARG_SET_PATH(shell)
 # Define PERL_PATH to provide path to Perl.
 GIT_ARG_SET_PATH(perl)
 #
+# Define PYTHON_PATH to provide path to Python.
+GIT_ARG_SET_PATH(python)
+#
 # Define ZLIB_PATH to provide path to zlib.
 GIT_ARG_SET_PATH(zlib)
 #
t/test-lib.sh +1 -0
index f2ca536..0b991db 100644
@@ -729,6 +729,7 @@ case $(uname -s) in
 esac
 
 test -z "$NO_PERL" && test_set_prereq PERL
+test -z "$NO_PYTHON" && test_set_prereq PYTHON
 
 # test whether the filesystem supports symbolic links
 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
Signature · 1 line
1.6.5.2.295.g0d105
#33 lore raw

PATCH v2 13/13 Add Python support library for remote helpers

In reply to Sverre Rabbelier

This patch introduces parts of a Python package called "git_remote_helpers" containing the building blocks for python helper.
The actual remote helpers itself are NOT part of this patch.

The patch includes the necessary Makefile additions to build and install the git_remote_cvs Python package along with the rest of Git.

This patch is based on Johan Herland's git_remote_cvs patch and has been improved by the following contributions:
- David Aguilar: Lots of Python coding style fixes
- David Aguilar: DESTDIR support in Makefile

Cc David Aguilar <[email protected]>
Cc Johan Herland <[email protected]>

---

Ejected all cvs specific parts (I grepped :P).

 Makefile                           |   38 ++
 git_remote_helpers/.gitignore      |    2 +
 git_remote_helpers/Makefile        |   35 ++
 git_remote_helpers/__init__.py     |   16 +
 git_remote_helpers/git/git.py      |  678 ++++++++++++++++++++++++++++++++++++
 git_remote_helpers/setup.py        |   17 +
 git_remote_helpers/util.py         |  194 ++++++++++
 t/test-lib.sh                      |    9 +
 8 files changed, 989 insertions(+), 0 deletions(-)
 create mode 100644 git_remote_helpers/.gitignore
 create mode 100644 git_remote_helpers/Makefile
 create mode 100644 git_remote_helpers/__init__.py
 create mode 100644 git_remote_helpers/git/__init__.py
 create mode 100644 git_remote_helpers/git/git.py
 create mode 100644 git_remote_helpers/setup.py
 create mode 100644 git_remote_helpers/util.py
Makefile +38 -0
index 6d1593f..701439f 100644
@@ -1406,6 +1406,9 @@ endif
 ifndef NO_PERL
 	$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all
 endif
+ifndef NO_PYTHON
+	$(QUIET_SUBDIR0)git_remote_helpers $(QUIET_SUBDIR1) PYTHON_PATH='$(PYTHON_PATH_SQ)' prefix='$(prefix_SQ)' all
+endif
 	$(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1)
 
 please_set_SHELL_PATH_to_a_more_modern_shell:
@@ -1524,6 +1527,35 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)) git-instaweb: % : unimplemented.sh
 	mv $@+ $@
 endif # NO_PERL
 
+ifndef NO_PYTHON
+$(patsubst %.py,%,$(SCRIPT_PYTHON)): GIT-CFLAGS
+$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py
+	$(QUIET_GEN)$(RM) $@ $@+ && \
+	INSTLIBDIR=`MAKEFLAGS= $(MAKE) -C git_remote_helpers -s \
+		--no-print-directory prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' \
+		instlibdir` && \
+	sed -e '1{' \
+	    -e '	s|#!.*python|#!$(PYTHON_PATH_SQ)|' \
+	    -e '}' \
+	    -e 's|^import sys.*|&; \\\
+	           import os; \\\
+	           sys.path[0] = os.environ.has_key("GITPYTHONLIB") and \\\
+	                         os.environ["GITPYTHONLIB"] or \\\
+	                         "@@INSTLIBDIR@@"|' \
+	    -e 's|@@INSTLIBDIR@@|'"$$INSTLIBDIR"'|g' \
+	    [email protected] >$@+ && \
+	chmod +x $@+ && \
+	mv $@+ $@
+else # NO_PYTHON
+$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : unimplemented.sh
+	$(QUIET_GEN)$(RM) $@ $@+ && \
+	sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
+	    -e 's|@@REASON@@|NO_PYTHON=$(NO_PYTHON)|g' \
+	    unimplemented.sh >$@+ && \
+	chmod +x $@+ && \
+	mv $@+ $@
+endif # NO_PYTHON
+
 configure: configure.ac
 	$(QUIET_GEN)$(RM) $@ $<+ && \
 	sed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
@@ -1748,6 +1780,9 @@ install: all
 ifndef NO_PERL
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
 endif
+ifndef NO_PYTHON
+	$(MAKE) -C git_remote_helpers prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
+endif
 ifndef NO_TCLTK
 	$(MAKE) -C gitk-git install
 	$(MAKE) -C git-gui gitexecdir='$(gitexec_instdir_SQ)' install
@@ -1862,6 +1897,9 @@ ifndef NO_PERL
 	$(RM) gitweb/gitweb.cgi
 	$(MAKE) -C perl clean
 endif
+ifndef NO_PYTHON
+	$(MAKE) -C git_remote_helpers clean
+endif
 	$(MAKE) -C templates/ clean
 	$(MAKE) -C t/ clean
 ifndef NO_TCLTK
git_remote_helpers/.gitignore new file +2 -0
new file mode 100644
index 0000000..2247d5f
@@ -0,0 +1,2 @@
+/build
+/dist
git_remote_helpers/Makefile new file +35 -0
new file mode 100644
index 0000000..c62dfd0
@@ -0,0 +1,35 @@
+#
+# Makefile for the git_remote_helpers python support modules
+#
+pysetupfile:=setup.py
+
+# Shell quote (do not use $(call) to accommodate ancient setups);
+DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
+
+ifndef PYTHON_PATH
+	PYTHON_PATH = /usr/bin/python
+endif
+ifndef prefix
+	prefix = $(HOME)
+endif
+ifndef V
+	QUIET = @
+	QUIETSETUP = --quiet
+endif
+
+PYLIBDIR=$(shell $(PYTHON_PATH) -c \
+	 "import sys; \
+	 print 'lib/python%i.%i/site-packages' % sys.version_info[:2]")
+
+all: $(pysetupfile)
+	$(QUIET)$(PYTHON_PATH) $(pysetupfile) $(QUIETSETUP) build
+
+install: $(pysetupfile)
+	$(PYTHON_PATH) $(pysetupfile) install --prefix $(DESTDIR_SQ)$(prefix)
+
+instlibdir: $(pysetupfile)
+	@echo "$(DESTDIR_SQ)$(prefix)/$(PYLIBDIR)"
+
+clean:
+	$(QUIET)$(PYTHON_PATH) $(pysetupfile) $(QUIETSETUP) clean -a
+	$(RM) *.pyo *.pyc
git_remote_helpers/__init__.py new file +16 -0
new file mode 100644
index 0000000..00f69cb
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+"""Support library package for git remote helpers.
+
+Git remote helpers are helper commands that interfaces with a non-git
+repository to provide automatic import of non-git history into a Git
+repository.
+
+This package provides the support library needed by these helpers..
+The following modules are included:
+
+- git.git - Interaction with Git repositories
+
+- util - General utility functionality use by the other modules in
+         this package, and also used directly by the helpers.
+"""
git_remote_helpers/git/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
git_remote_helpers/git/git.py new file +678 -0

678 lines not on this page · raw message

git_remote_helpers/setup.py new file +17 -0
new file mode 100644
index 0000000..4d434b6
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+"""Distutils build/install script for the git_remote_helpers package."""
+
+from distutils.core import setup
+
+setup(
+    name = 'git_remote_helpers',
+    version = '0.1.0',
+    description = 'Git remote helper program for non-git repositories',
+    license = 'GPLv2',
+    author = 'The Git Community',
+    author_email = '[email protected]',
+    url = 'http://www.git-scm.com/',
+    package_dir = {'git_remote_helpers': ''},
+    packages = ['git_remote_helpers', 'git_remote_helpers.git'],
+)
git_remote_helpers/util.py new file +194 -0

194 lines not on this page · raw message

t/test-lib.sh +9 -0
index 0b991db..6ed5b28 100644
@@ -638,6 +638,15 @@ test -d ../templates/blt || {
 	error "You haven't built things yet, have you?"
 }
 
+if test -z "$GIT_TEST_INSTALLED"
+then
+	GITPYTHONLIB="$(pwd)/../git_remote_helpers/build/lib"
+	export GITPYTHONLIB
+	test -d ../git_remote_helpers/build || {
+		error "You haven't built git_remote_helpers yet, have you?"
+	}
+fi
+
 if ! test -x ../test-chmtime; then
 	echo >&2 'You need to build test-chmtime:'
 	echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
Signature · 1 line
1.6.5.2.295.g0d105
#34 lore raw

Re: [PATCH v2 13/13] Add Python support library for remote helpers

Quoted 7 lines · Sverre Rabbelier

This patch introduces parts of a Python package called "git_remote_helpers" containing the building blocks for python helper.
The actual remote helpers itself are NOT part of this patch.

The patch includes the necessary Makefile additions to build and install the git_remote_cvs Python package along with the rest of Git.

There are a few typos in the above. How about:

This patch introduces parts of a Python package called "git_remote_helpers" containing the building blocks for remote helpers written in Python.
No actual remote helpers are part of this patch, the patch only includes the common basics needed to start writing such helpers.

Quoted 2 lines

The patch includes the necessary Makefile additions to build and install the git_remote_cvs Python package along with the rest of Git.

s/git_remote_cvs/git_remote_helpers/

Quoted 9 lines

This patch is based on Johan Herland's git_remote_cvs patch and has been improved by the following contributions:
- David Aguilar: Lots of Python coding style fixes
- David Aguilar: DESTDIR support in Makefile

Cc David Aguilar <[email protected]>
Cc Johan Herland <[email protected]>

---

Otherwise it all looks good. Nice work!

...Johan

Signature · 2 lines
Johan Herland, <[email protected]>
www.herland.net
#35 lore raw

Re: [PATCH v2 13/13] Add Python support library for remote helpers

Heya,

Quoted 1 line · Johan Herland

There are a few typos in the above.

Thanks, fixed locally, will include this in the next version.

Quoted 1 line

Otherwise it all looks good. Nice work!

Cool, thanks!

Signature · 3 lines
Cheers,

Sverre Rabbelier