{"thread":{"id":"21484","subject":"[PATCH v2 00/13] Reroll of the remote-vcs-helper series","startedAt":"2009-11-04T19:48:05Z","lastAt":"2009-11-06T06:05:27Z","messageCount":36,"participants":["Sverre Rabbelier","Daniel Barkalow","Junio C Hamano","Johan Herland"],"isPatch":true,"patchVersion":2,"patchTotal":13},"messages":[{"id":"126800","messageId":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":null,"subject":"[PATCH v2 00/13] Reroll of the remote-vcs-helper series","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:05Z","receivedAt":"2009-11-04T19:48:05Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Major changes include removal of the cvs specific code as well incorperation\nof most of Daniel's comments. For details see the post-triple-dash of the\nindividual patches.\n\nDaniel, I haven't yet had time to write the 'refspec' part, but that is\nsomething that can definitely go on top of the current series.\n\nDaniel Barkalow (7):\n      Fix memory leak in helper method for disconnect\n      Allow programs to not depend on remotes having urls\n      Use a function to determine whether a remote is valid\n      Allow fetch to modify refs\n      Add a config option for remotes to specify a foreign vcs\n      Add support for \"import\" helper command\n      Allow helpers to report in \"list\" command that the ref is unchanged\n\nJohan Herland (1):\n      Basic build infrastructure for Python scripts\n\nJohannes Schindelin (1):\n      Allow specifying the remote helper in the url\n\nSverre Rabbelier (4):\n      Write local refs written by the \"import\" helper command only once\n      Honour the refspec when updating refs after import\n      Allow helpers to request the path to the .git directory\n      Add Python support library for remote helpers\n\n Documentation/config.txt             |    4 +\n Documentation/git-remote-helpers.txt |   14 +-\n Makefile                             |   51 +++\n builtin-clone.c                      |    8 +-\n builtin-fetch.c                      |    7 +-\n builtin-ls-remote.c                  |    4 +-\n builtin-push.c                       |   68 ++--\n configure.ac                         |    3 +\n git_remote_helpers/.gitignore        |    2 +\n git_remote_helpers/Makefile          |   35 ++\n git_remote_helpers/__init__.py       |   16 +\n git_remote_helpers/git/git.py        |  678 ++++++++++++++++++++++++++++++++++\n git_remote_helpers/setup.py          |   17 +\n git_remote_helpers/util.py           |  194 ++++++++++\n remote.c                             |   15 +-\n remote.h                             |    2 +\n t/test-lib.sh                        |   10 +\n transport-helper.c                   |   99 +++++-\n transport.c                          |   31 ++-\n transport.h                          |   43 ++-\n 20 files changed, 1253 insertions(+), 48 deletions(-)\n"},{"id":"126810","messageId":"1257364098-1685-2-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 01/13] Fix memory leak in helper method for disconnect","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:06Z","receivedAt":"2009-11-04T19:48:06Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Daniel Barkalow <barkalow@iabervon.org>\n\nSince some cases may need to disconnect from the helper and reconnect,\nwrap the function that just disconnects in a function that also frees\ntransport->data.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n\n\tMoved to the beginning of the series as it is most important.\n\n transport-helper.c |    9 ++++++++-\n 1 files changed, 8 insertions(+), 1 deletions(-)\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex f57e84c..e24fcbb 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -67,6 +67,13 @@ static int disconnect_helper(struct transport *transport)\n \treturn 0;\n }\n \n+static int release_helper(struct transport *transport)\n+{\n+\tdisconnect_helper(transport);\n+\tfree(transport->data);\n+\treturn 0;\n+}\n+\n static int fetch_with_fetch(struct transport *transport,\n \t\t\t    int nr_heads, const struct ref **to_fetch)\n {\n@@ -163,6 +170,6 @@ int transport_helper_init(struct transport *transport, const char *name)\n \ttransport->data = data;\n \ttransport->get_refs_list = get_refs_list;\n \ttransport->fetch = fetch;\n-\ttransport->disconnect = disconnect_helper;\n+\ttransport->disconnect = release_helper;\n \treturn 0;\n }\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126813","messageId":"1257364098-1685-3-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 02/13] Allow programs to not depend on remotes having urls","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:07Z","receivedAt":"2009-11-04T19:48:07Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Daniel Barkalow <barkalow@iabervon.org>\n\nFor fetch and ls-remote, which use the first url of a remote, have\ntransport_get() determine this by passing a remote and passing NULL\nfor the url. For push, which uses every url of a remote, use each url\nin turn if there are any, and use NULL if there are none.\n\nThis will allow the transport code to do something different if the\nlocation is not specified with a url.\n\nAlso, have the message for a fetch say \"foreign\" if there is no url.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tUnchanged.\n\n builtin-fetch.c     |    7 +++-\n builtin-ls-remote.c |    4 +-\n builtin-push.c      |   68 +++++++++++++++++++++++++++++++-------------------\n transport.c         |    3 ++\n 4 files changed, 52 insertions(+), 30 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex a35a6f8..013a6ba 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -309,7 +309,10 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,\n \tif (!fp)\n \t\treturn error(\"cannot open %s: %s\\n\", filename, strerror(errno));\n \n-\turl = transport_anonymize_url(raw_url);\n+\tif (raw_url)\n+\t\turl = transport_anonymize_url(raw_url);\n+\telse\n+\t\turl = xstrdup(\"foreign\");\n \tfor (rm = ref_map; rm; rm = rm->next) {\n \t\tstruct ref *ref = NULL;\n \n@@ -704,7 +707,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \tif (!remote)\n \t\tdie(\"Where do you want to fetch from today?\");\n \n-\ttransport = transport_get(remote, remote->url[0]);\n+\ttransport = transport_get(remote, NULL);\n \tif (verbosity >= 2)\n \t\ttransport->verbose = 1;\n \tif (verbosity < 0)\ndiff --git a/builtin-ls-remote.c b/builtin-ls-remote.c\nindex 78a88f7..4c6fc58 100644\n--- a/builtin-ls-remote.c\n+++ b/builtin-ls-remote.c\n@@ -87,9 +87,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \tremote = nongit ? NULL : remote_get(dest);\n-\tif (remote && !remote->url_nr)\n+\tif (!nongit && !remote)\n \t\tdie(\"remote %s has no configured URL\", dest);\n-\ttransport = transport_get(remote, remote ? remote->url[0] : dest);\n+\ttransport = transport_get(remote, remote ? NULL : dest);\n \tif (uploadpack != NULL)\n \t\ttransport_set_option(transport, TRANS_OPT_UPLOADPACK, uploadpack);\n \ndiff --git a/builtin-push.c b/builtin-push.c\nindex 8631c06..88dd9f5 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -88,6 +88,36 @@ static void setup_default_push_refspecs(void)\n \t}\n }\n \n+static int push_with_options(struct transport *transport, int flags)\n+{\n+\tint err;\n+\tint nonfastforward;\n+\tif (receivepack)\n+\t\ttransport_set_option(transport,\n+\t\t\t\t     TRANS_OPT_RECEIVEPACK, receivepack);\n+\tif (thin)\n+\t\ttransport_set_option(transport, TRANS_OPT_THIN, \"yes\");\n+\n+\tif (flags & TRANSPORT_PUSH_VERBOSE)\n+\t\tfprintf(stderr, \"Pushing to %s\\n\", transport->url);\n+\terr = transport_push(transport, refspec_nr, refspec, flags,\n+\t\t\t     &nonfastforward);\n+\terr |= transport_disconnect(transport);\n+\n+\tif (!err)\n+\t\treturn 0;\n+\n+\terror(\"failed to push some refs to '%s'\", transport->url);\n+\n+\tif (nonfastforward && advice_push_nonfastforward) {\n+\t\tprintf(\"To prevent you from losing history, non-fast-forward updates were rejected\\n\"\n+\t\t       \"Merge the remote changes before pushing again.  See the 'non-fast forward'\\n\"\n+\t\t       \"section of 'git push --help' for details.\\n\");\n+\t}\n+\n+\treturn 1;\n+}\n+\n static int do_push(const char *repo, int flags)\n {\n \tint i, errs;\n@@ -136,33 +166,19 @@ static int do_push(const char *repo, int flags)\n \t\turl = remote->url;\n \t\turl_nr = remote->url_nr;\n \t}\n-\tfor (i = 0; i < url_nr; i++) {\n-\t\tstruct transport *transport =\n-\t\t\ttransport_get(remote, url[i]);\n-\t\tint err;\n-\t\tint nonfastforward;\n-\t\tif (receivepack)\n-\t\t\ttransport_set_option(transport,\n-\t\t\t\t\t     TRANS_OPT_RECEIVEPACK, receivepack);\n-\t\tif (thin)\n-\t\t\ttransport_set_option(transport, TRANS_OPT_THIN, \"yes\");\n-\n-\t\tif (flags & TRANSPORT_PUSH_VERBOSE)\n-\t\t\tfprintf(stderr, \"Pushing to %s\\n\", url[i]);\n-\t\terr = transport_push(transport, refspec_nr, refspec, flags,\n-\t\t\t\t     &nonfastforward);\n-\t\terr |= transport_disconnect(transport);\n-\n-\t\tif (!err)\n-\t\t\tcontinue;\n-\n-\t\terror(\"failed to push some refs to '%s'\", url[i]);\n-\t\tif (nonfastforward && advice_push_nonfastforward) {\n-\t\t\tprintf(\"To prevent you from losing history, non-fast-forward updates were rejected\\n\"\n-\t\t\t       \"Merge the remote changes before pushing again.  See the 'non-fast forward'\\n\"\n-\t\t\t       \"section of 'git push --help' for details.\\n\");\n+\tif (url_nr) {\n+\t\tfor (i = 0; i < url_nr; i++) {\n+\t\t\tstruct transport *transport =\n+\t\t\t\ttransport_get(remote, url[i]);\n+\t\t\tif (push_with_options(transport, flags))\n+\t\t\t\terrs++;\n \t\t}\n-\t\terrs++;\n+\t} else {\n+\t\tstruct transport *transport =\n+\t\t\ttransport_get(remote, NULL);\n+\n+\t\tif (push_with_options(transport, flags))\n+\t\t\terrs++;\n \t}\n \treturn !!errs;\n }\ndiff --git a/transport.c b/transport.c\nindex 644a30a..9daa686 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -813,6 +813,9 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \tstruct transport *ret = xcalloc(1, sizeof(*ret));\n \n \tret->remote = remote;\n+\n+\tif (!url && remote && remote->url)\n+\t\turl = remote->url[0];\n \tret->url = url;\n \n \tif (!prefixcmp(url, \"rsync:\")) {\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126804","messageId":"1257364098-1685-4-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 03/13] Use a function to determine whether a remote is valid","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:08Z","receivedAt":"2009-11-04T19:48:08Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Daniel Barkalow <barkalow@iabervon.org>\n\nCurrently, it only checks url, but it will allow other things in the future.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n\n\tUnchanged.\n\n remote.c |   13 +++++++++----\n 1 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/remote.c b/remote.c\nindex 73d33f2..15c9cec 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -52,6 +52,11 @@ static struct rewrites rewrites_push;\n #define BUF_SIZE (2048)\n static char buffer[BUF_SIZE];\n \n+static int valid_remote(const struct remote *remote)\n+{\n+\treturn !!remote->url;\n+}\n+\n static const char *alias_url(const char *url, struct rewrites *r)\n {\n \tint i, j;\n@@ -688,14 +693,14 @@ struct remote *remote_get(const char *name)\n \n \tret = make_remote(name, 0);\n \tif (valid_remote_nick(name)) {\n-\t\tif (!ret->url)\n+\t\tif (!valid_remote(ret))\n \t\t\tread_remotes_file(ret);\n-\t\tif (!ret->url)\n+\t\tif (!valid_remote(ret))\n \t\t\tread_branches_file(ret);\n \t}\n-\tif (name_given && !ret->url)\n+\tif (name_given && !valid_remote(ret))\n \t\tadd_url_alias(ret, name);\n-\tif (!ret->url)\n+\tif (!valid_remote(ret))\n \t\treturn NULL;\n \tret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec);\n \tret->push = parse_push_refspec(ret->push_refspec_nr, ret->push_refspec);\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126814","messageId":"1257364098-1685-5-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 04/13] Allow fetch to modify refs","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:09Z","receivedAt":"2009-11-04T19:48:09Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Daniel Barkalow <barkalow@iabervon.org>\n\nThis allows the transport to use the null sha1 for a ref reported to\nbe present in the remote repository to indicate that a ref exists but\nits actual value is presently unknown and will be set if the objects\nare fetched.\n\nAlso adds documentation to the API to specify exactly what the methods\nshould do and how they should interpret arguments.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tNow only changes constness (changes to line 526-257 removed).\n\n builtin-clone.c    |    3 ++-\n transport-helper.c |    4 ++--\n transport.c        |   13 +++++++------\n transport.h        |   41 +++++++++++++++++++++++++++++++++++++++--\n 4 files changed, 50 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex caf3025..5df8b0f 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -362,9 +362,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \tconst char *repo_name, *repo, *work_tree, *git_dir;\n \tchar *path, *dir;\n \tint dest_exists;\n-\tconst struct ref *refs, *remote_head, *mapped_refs;\n+\tconst struct ref *refs, *remote_head;\n \tconst struct ref *remote_head_points_at;\n \tconst struct ref *our_head_points_at;\n+\tstruct ref *mapped_refs;\n \tstruct strbuf key = STRBUF_INIT, value = STRBUF_INIT;\n \tstruct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;\n \tstruct transport *transport = NULL;\ndiff --git a/transport-helper.c b/transport-helper.c\nindex e24fcbb..53d8f08 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -75,7 +75,7 @@ static int release_helper(struct transport *transport)\n }\n \n static int fetch_with_fetch(struct transport *transport,\n-\t\t\t    int nr_heads, const struct ref **to_fetch)\n+\t\t\t    int nr_heads, struct ref **to_fetch)\n {\n \tstruct child_process *helper = get_helper(transport);\n \tFILE *file = xfdopen(helper->out, \"r\");\n@@ -99,7 +99,7 @@ static int fetch_with_fetch(struct transport *transport,\n }\n \n static int fetch(struct transport *transport,\n-\t\t int nr_heads, const struct ref **to_fetch)\n+\t\t int nr_heads, struct ref **to_fetch)\n {\n \tstruct helper_data *data = transport->data;\n \tint i, count;\ndiff --git a/transport.c b/transport.c\nindex 9daa686..5ae8db6 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -204,7 +204,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)\n }\n \n static int fetch_objs_via_rsync(struct transport *transport,\n-\t\t\t\tint nr_objs, const struct ref **to_fetch)\n+\t\t\t\tint nr_objs, struct ref **to_fetch)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct child_process rsync;\n@@ -408,7 +408,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus\n }\n \n static int fetch_refs_from_bundle(struct transport *transport,\n-\t\t\t       int nr_heads, const struct ref **to_fetch)\n+\t\t\t       int nr_heads, struct ref **to_fetch)\n {\n \tstruct bundle_transport_data *data = transport->data;\n \treturn unbundle(&data->header, data->fd);\n@@ -486,7 +486,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus\n }\n \n static int fetch_refs_via_pack(struct transport *transport,\n-\t\t\t       int nr_heads, const struct ref **to_fetch)\n+\t\t\t       int nr_heads, struct ref **to_fetch)\n {\n \tstruct git_transport_data *data = transport->data;\n \tchar **heads = xmalloc(nr_heads * sizeof(*heads));\n@@ -926,16 +926,17 @@ const struct ref *transport_get_remote_refs(struct transport *transport)\n \treturn transport->remote_refs;\n }\n \n-int transport_fetch_refs(struct transport *transport, const struct ref *refs)\n+int transport_fetch_refs(struct transport *transport, struct ref *refs)\n {\n \tint rc;\n \tint nr_heads = 0, nr_alloc = 0, nr_refs = 0;\n-\tconst struct ref **heads = NULL;\n-\tconst struct ref *rm;\n+\tstruct ref **heads = NULL;\n+\tstruct ref *rm;\n \n \tfor (rm = refs; rm; rm = rm->next) {\n \t\tnr_refs++;\n \t\tif (rm->peer_ref &&\n+\t\t    !is_null_sha1(rm->old_sha1) &&\n \t\t    !hashcmp(rm->peer_ref->old_sha1, rm->old_sha1))\n \t\t\tcontinue;\n \t\tALLOC_GROW(heads, nr_heads + 1, nr_alloc);\ndiff --git a/transport.h b/transport.h\nindex c14da6f..503db11 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -18,11 +18,48 @@ struct transport {\n \tint (*set_option)(struct transport *connection, const char *name,\n \t\t\t  const char *value);\n \n+\t/**\n+\t * Returns a list of the remote side's refs. In order to allow\n+\t * the transport to try to share connections, for_push is a\n+\t * hint as to whether the ultimate operation is a push or a fetch.\n+\t *\n+\t * If the transport is able to determine the remote hash for\n+\t * the ref without a huge amount of effort, it should store it\n+\t * in the ref's old_sha1 field; otherwise it should be all 0.\n+\t **/\n \tstruct ref *(*get_refs_list)(struct transport *transport, int for_push);\n-\tint (*fetch)(struct transport *transport, int refs_nr, const struct ref **refs);\n+\n+\t/**\n+\t * Fetch the objects for the given refs. Note that this gets\n+\t * an array, and should ignore the list structure.\n+\t *\n+\t * If the transport did not get hashes for refs in\n+\t * get_refs_list(), it should set the old_sha1 fields in the\n+\t * provided refs now.\n+\t **/\n+\tint (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);\n+\n+\t/**\n+\t * Push the objects and refs. Send the necessary objects, and\n+\t * then, for any refs where peer_ref is set and\n+\t * peer_ref->new_sha1 is different from old_sha1, tell the\n+\t * remote side to update each ref in the list from old_sha1 to\n+\t * peer_ref->new_sha1.\n+\t *\n+\t * Where possible, set the status for each ref appropriately.\n+\t *\n+\t * The transport must modify new_sha1 in the ref to the new\n+\t * value if the remote accepted the change. Note that this\n+\t * could be a different value from peer_ref->new_sha1 if the\n+\t * process involved generating new commits.\n+\t **/\n \tint (*push_refs)(struct transport *transport, struct ref *refs, int flags);\n \tint (*push)(struct transport *connection, int refspec_nr, const char **refspec, int flags);\n \n+\t/** get_refs_list(), fetch(), and push_refs() can keep\n+\t * resources (such as a connection) reserved for futher\n+\t * use. disconnect() releases these resources.\n+\t **/\n \tint (*disconnect)(struct transport *connection);\n \tchar *pack_lockfile;\n \tsigned verbose : 2;\n@@ -74,7 +111,7 @@ int transport_push(struct transport *connection,\n \n const struct ref *transport_get_remote_refs(struct transport *transport);\n \n-int transport_fetch_refs(struct transport *transport, const struct ref *refs);\n+int transport_fetch_refs(struct transport *transport, struct ref *refs);\n void transport_unlock_pack(struct transport *transport);\n int transport_disconnect(struct transport *transport);\n char *transport_anonymize_url(const char *url);\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126808","messageId":"1257364098-1685-6-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 05/13] Add a config option for remotes to specify a foreign vcs","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:10Z","receivedAt":"2009-11-04T19:48:10Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Daniel Barkalow <barkalow@iabervon.org>\n\nIf this is set, the url is not required, and the transport always uses\na helper named \"git-remote-<value>\".\n\nIt is a separate configuration option in order to allow a sensible\nconfiguration for foreign systems which either have no meaningful urls\nfor repositories or which require urls that do not specify the system\nused by the repository at that location. However, this only affects\nhow the name of the helper is determined, not anything about the\ninteraction with the helper, and the contruction is such that, if the\nforeign scm does happen to use a co-named url method, a url with that\nmethod may be used directly.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tUnchanged.\n\n Documentation/config.txt |    4 ++++\n remote.c                 |    4 +++-\n remote.h                 |    2 ++\n transport.c              |    5 +++++\n 4 files changed, 14 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex d1e2120..0d9d369 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1408,6 +1408,10 @@ remote.<name>.tagopt::\n \tSetting this value to \\--no-tags disables automatic tag following when\n \tfetching from remote <name>\n \n+remote.<name>.vcs::\n+\tSetting this to a value <vcs> will cause git to interact with\n+\tthe remote with the git-remote-<vcs> helper.\n+\n remotes.<group>::\n \tThe list of remotes which are fetched by \"git remote update\n \t<group>\".  See linkgit:git-remote[1].\ndiff --git a/remote.c b/remote.c\nindex 15c9cec..09bb79c 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -54,7 +54,7 @@ static char buffer[BUF_SIZE];\n \n static int valid_remote(const struct remote *remote)\n {\n-\treturn !!remote->url;\n+\treturn (!!remote->url) || (!!remote->foreign_vcs);\n }\n \n static const char *alias_url(const char *url, struct rewrites *r)\n@@ -444,6 +444,8 @@ static int handle_config(const char *key, const char *value, void *cb)\n \t} else if (!strcmp(subkey, \".proxy\")) {\n \t\treturn git_config_string((const char **)&remote->http_proxy,\n \t\t\t\t\t key, value);\n+\t} else if (!strcmp(subkey, \".vcs\")) {\n+\t\treturn git_config_string(&remote->foreign_vcs, key, value);\n \t}\n \treturn 0;\n }\ndiff --git a/remote.h b/remote.h\nindex 5db8420..ac0ce2f 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -11,6 +11,8 @@ struct remote {\n \tconst char *name;\n \tint origin;\n \n+\tconst char *foreign_vcs;\n+\n \tconst char **url;\n \tint url_nr;\n \tint url_alloc;\ndiff --git a/transport.c b/transport.c\nindex 5ae8db6..13bab4e 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -818,6 +818,11 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \t\turl = remote->url[0];\n \tret->url = url;\n \n+\tif (remote && remote->foreign_vcs) {\n+\t\ttransport_helper_init(ret, remote->foreign_vcs);\n+\t\treturn ret;\n+\t}\n+\n \tif (!prefixcmp(url, \"rsync:\")) {\n \t\tret->get_refs_list = get_refs_via_rsync;\n \t\tret->fetch = fetch_objs_via_rsync;\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126801","messageId":"1257364098-1685-7-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 06/13] Allow specifying the remote helper in the url","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:11Z","receivedAt":"2009-11-04T19:48:11Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThe common case for remote helpers will be to import some repository\nwhich can be specified by a single URL.  Support this use case by\nallowing users to say:\n\n\tgit clone hg::https://soc.googlecode.com/hg/ soc\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tReworded commit message to be more neutral.\n\n transport.c |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/transport.c b/transport.c\nindex 13bab4e..5d814b5 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -818,6 +818,16 @@ struct transport *transport_get(struct remote *remote, const char *url)\n \t\turl = remote->url[0];\n \tret->url = url;\n \n+\t/* maybe it is a foreign URL? */\n+\tif (url) {\n+\t\tconst char *p = url;\n+\n+\t\twhile (isalnum(*p))\n+\t\t\tp++;\n+\t\tif (!prefixcmp(p, \"::\"))\n+\t\t\tremote->foreign_vcs = xstrndup(url, p - url);\n+\t}\n+\n \tif (remote && remote->foreign_vcs) {\n \t\ttransport_helper_init(ret, remote->foreign_vcs);\n \t\treturn ret;\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126806","messageId":"1257364098-1685-8-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 07/13] Add support for \"import\" helper command","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:12Z","receivedAt":"2009-11-04T19:48:12Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Daniel Barkalow <barkalow@iabervon.org>\n\nThis command, supported if the \"import\" capability is advertized,\nallows a helper to support fetching by outputting a git-fast-import\nstream.\n\nIf both \"fetch\" and \"import\" are advertized, git itself will use\n\"fetch\" (although other users may use \"import\" in this case).\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tUndid the change to the read_ref line, see patch 0009 for a\n\tsuggested proper fix.\n\n Documentation/git-remote-helpers.txt |   10 ++++++\n transport-helper.c                   |   52 ++++++++++++++++++++++++++++++++++\n 2 files changed, 62 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\nindex 173ee23..e9aa67e 100644\n--- a/Documentation/git-remote-helpers.txt\n+++ b/Documentation/git-remote-helpers.txt\n@@ -43,6 +43,13 @@ Commands are given by the caller on the helper's standard input, one per line.\n +\n Supported if the helper has the \"fetch\" capability.\n \n+'import' <name>::\n+\tProduces a fast-import stream which imports the current value\n+\tof the named ref. It may additionally import other refs as\n+\tneeded to construct the history efficiently.\n++\n+Supported if the helper has the \"import\" capability.\n+\n If a fatal error occurs, the program writes the error message to\n stderr and exits. The caller should expect that a suitable error\n message has been printed if the child closes the connection without\n@@ -57,6 +64,9 @@ CAPABILITIES\n 'fetch'::\n \tThis helper supports the 'fetch' command.\n \n+'import'::\n+\tThis helper supports the 'import' command.\n+\n REF LIST ATTRIBUTES\n -------------------\n \ndiff --git a/transport-helper.c b/transport-helper.c\nindex 53d8f08..82caaae 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -11,6 +11,7 @@ struct helper_data\n \tconst char *name;\n \tstruct child_process *helper;\n \tunsigned fetch : 1;\n+\tunsigned import : 1;\n };\n \n static struct child_process *get_helper(struct transport *transport)\n@@ -48,6 +49,8 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tbreak;\n \t\tif (!strcmp(buf.buf, \"fetch\"))\n \t\t\tdata->fetch = 1;\n+\t\tif (!strcmp(buf.buf, \"import\"))\n+\t\t\tdata->import = 1;\n \t}\n \treturn data->helper;\n }\n@@ -98,6 +101,52 @@ static int fetch_with_fetch(struct transport *transport,\n \treturn 0;\n }\n \n+static int get_importer(struct transport *transport, struct child_process *fastimport)\n+{\n+\tstruct child_process *helper = get_helper(transport);\n+\tmemset(fastimport, 0, sizeof(*fastimport));\n+\tfastimport->in = helper->out;\n+\tfastimport->argv = xcalloc(5, sizeof(*fastimport->argv));\n+\tfastimport->argv[0] = \"fast-import\";\n+\tfastimport->argv[1] = \"--quiet\";\n+\n+\tfastimport->git_cmd = 1;\n+\treturn start_command(fastimport);\n+}\n+\n+static int fetch_with_import(struct transport *transport,\n+\t\t\t     int nr_heads, struct ref **to_fetch)\n+{\n+\tstruct child_process fastimport;\n+\tstruct child_process *helper = get_helper(transport);\n+\tint i;\n+\tstruct ref *posn;\n+\tstruct strbuf buf = STRBUF_INIT;\n+\n+\tif (get_importer(transport, &fastimport))\n+\t\tdie(\"Couldn't run fast-import\");\n+\n+\tfor (i = 0; i < nr_heads; i++) {\n+\t\tposn = to_fetch[i];\n+\t\tif (posn->status & REF_STATUS_UPTODATE)\n+\t\t\tcontinue;\n+\n+\t\tstrbuf_addf(&buf, \"import %s\\n\", posn->name);\n+\t\twrite_in_full(helper->in, buf.buf, buf.len);\n+\t\tstrbuf_reset(&buf);\n+\t}\n+\tdisconnect_helper(transport);\n+\tfinish_command(&fastimport);\n+\n+\tfor (i = 0; i < nr_heads; i++) {\n+\t\tposn = to_fetch[i];\n+\t\tif (posn->status & REF_STATUS_UPTODATE)\n+\t\t\tcontinue;\n+\t\tread_ref(posn->name, posn->old_sha1);\n+\t}\n+\treturn 0;\n+}\n+\n static int fetch(struct transport *transport,\n \t\t int nr_heads, struct ref **to_fetch)\n {\n@@ -115,6 +164,9 @@ static int fetch(struct transport *transport,\n \tif (data->fetch)\n \t\treturn fetch_with_fetch(transport, nr_heads, to_fetch);\n \n+\tif (data->import)\n+\t\treturn fetch_with_import(transport, nr_heads, to_fetch);\n+\n \treturn -1;\n }\n \n-- \n1.6.5.2.295.g0d105\n"},{"id":"126812","messageId":"1257364098-1685-9-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 08/13] Write local refs written by the \"import\" helper command only once","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:13Z","receivedAt":"2009-11-04T19:48:13Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"At clone time the \"import\" helper command has already written a\npackfile with all refs, so write_remote_refs will create a duplicate\nentry for each ref returned by wanted_peer_refs. Prevent this\nduplication by setting fetched_refs_written in the transport when\nexecuting the \"import\" helper command and only adding the extra refs\nif it is not set.\n\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tI am not 100% sure this is the proper fix, but I do know that\n\twithout this I get a .git/packed-refs file that has duplicate\n\tentries in it.\n\n builtin-clone.c    |    5 ++++-\n transport-helper.c |    3 +++\n transport.h        |    2 ++\n 3 files changed, 9 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex 5df8b0f..e44347e 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -542,7 +542,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \tif (refs) {\n \t\tclear_extra_refs();\n \n-\t\twrite_remote_refs(mapped_refs);\n+\t\tif(transport->fetched_refs_written)\n+\t\t\tpack_refs(PACK_REFS_ALL);\n+\t\telse\n+\t\t\twrite_remote_refs(mapped_refs);\n \n \t\tremote_head = find_ref_by_name(refs, \"HEAD\");\n \t\tremote_head_points_at =\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 82caaae..148496c 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -165,7 +165,10 @@ static int fetch(struct transport *transport,\n \t\treturn fetch_with_fetch(transport, nr_heads, to_fetch);\n \n \tif (data->import)\n+\t{\n+\t\ttransport->fetched_refs_written = 1;\n \t\treturn fetch_with_import(transport, nr_heads, to_fetch);\n+\t}\n \n \treturn -1;\n }\ndiff --git a/transport.h b/transport.h\nindex 503db11..7458b9e 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -65,6 +65,8 @@ struct transport {\n \tsigned verbose : 2;\n \t/* Force progress even if the output is not a tty */\n \tunsigned progress : 1;\n+\t/* Refs fetched by transport_get_remote_refs are already written */\n+\tunsigned fetched_refs_written : 1;\n };\n \n #define TRANSPORT_PUSH_ALL 1\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126805","messageId":"1257364098-1685-10-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:14Z","receivedAt":"2009-11-04T19:48:14Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"This way the helper can write to 'refs/remotes/origin/*' instead of\nwriting to 'refs/heads/*'.\n\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n  Daniel, does this look good to you?\n\n  Let's assume the following:\n  * list: only HEAD is a symref (to refs/heads/<branch>), all other\n          refs are '? refs/heads/<branch>'.\n  * import: the helper creates branches under refs/remotes/<alias>/*\n            (since the refspec code is not yet in that would allow\n             it to create them under refs/<vcs>/<alias>/*)\n\n  Now when updating the refs we do the following:\n  transport-helper.c:145 \"read_ref(posn->name, posn->old_sha1);\"\n\n  The value of posn->name looks like \"refs/heads/<branch>\". So what\n  does this lookup do? It tries to lookup the new value of the ref\n  _where it will be created_, this fails of course, since the ref\n  currently only exists as \"refs/remotes/origin/<branch>\". So, we\n  should instead be doing a lookup using posn->peer_ref->name, and\n  not do a lookup at all if it posn->peer_ref is not set (which\n  should not occur as we are passed only wanted peer refs).\n\n  Please let me know if this makes sense and both this and 0008 can\n  be squashed with 0007.\n\n transport-helper.c |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 148496c..72ed95b 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -142,7 +142,10 @@ static int fetch_with_import(struct transport *transport,\n \t\tposn = to_fetch[i];\n \t\tif (posn->status & REF_STATUS_UPTODATE)\n \t\t\tcontinue;\n-\t\tread_ref(posn->name, posn->old_sha1);\n+\t\tif(posn->peer_ref) {\n+\t\t\tread_ref(posn->peer_ref->name, posn->peer_ref->old_sha1);\n+\t\t\thashcpy(posn->old_sha1, posn->peer_ref->old_sha1);\n+\t\t}\n \t}\n \treturn 0;\n }\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126809","messageId":"1257364098-1685-11-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 10/13] Allow helpers to report in \"list\" command that the ref is unchanged","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:15Z","receivedAt":"2009-11-04T19:48:15Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Daniel Barkalow <barkalow@iabervon.org>\n\nHelpers may use a line like \"? name unchanged\" to specify that there\nis nothing new at that name, without any git-specific code to\ndetermine the correct response.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n\n\tUnchanged.\n\n Documentation/git-remote-helpers.txt |    4 +++-\n transport-helper.c                   |   22 ++++++++++++++++++++++\n 2 files changed, 25 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt\nindex e9aa67e..2c5130f 100644\n--- a/Documentation/git-remote-helpers.txt\n+++ b/Documentation/git-remote-helpers.txt\n@@ -70,7 +70,9 @@ CAPABILITIES\n REF LIST ATTRIBUTES\n -------------------\n \n-None are defined yet, but the caller must accept any which are supplied.\n+'unchanged'::\n+\tThis ref is unchanged since the last import or fetch, although\n+\tthe helper cannot necessarily determine what value that produced.\n \n Documentation\n -------------\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 72ed95b..a80d803 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -176,6 +176,22 @@ static int fetch(struct transport *transport,\n \treturn -1;\n }\n \n+static int has_attribute(const char *attrs, const char *attr) {\n+\tint len;\n+\tif (!attrs)\n+\t\treturn 0;\n+\n+\tlen = strlen(attr);\n+\tfor (;;) {\n+\t\tconst char *space = strchrnul(attrs, ' ');\n+\t\tif (len == space - attrs && !strncmp(attrs, attr, len))\n+\t\t\treturn 1;\n+\t\tif (!*space)\n+\t\t\treturn 0;\n+\t\tattrs = space + 1;\n+\t}\n+}\n+\n static struct ref *get_refs_list(struct transport *transport, int for_push)\n {\n \tstruct child_process *helper;\n@@ -210,6 +226,12 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)\n \t\t\t(*tail)->symref = xstrdup(buf.buf + 1);\n \t\telse if (buf.buf[0] != '?')\n \t\t\tget_sha1_hex(buf.buf, (*tail)->old_sha1);\n+\t\tif (eon) {\n+\t\t\tif (has_attribute(eon + 1, \"unchanged\")) {\n+\t\t\t\t(*tail)->status |= REF_STATUS_UPTODATE;\n+\t\t\t\tread_ref((*tail)->name, (*tail)->old_sha1);\n+\t\t\t}\n+\t\t}\n \t\ttail = &((*tail)->next);\n \t}\n \tstrbuf_release(&buf);\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126802","messageId":"1257364098-1685-12-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:16Z","receivedAt":"2009-11-04T19:48:16Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"The 'gitdir' capability is reported by the remote helper if it\nrequires the location of the .git directory. The location of the .git\ndirectory can then be used by the helper to store status files even\nwhen the current directory is not a git repository (such as is the\ncase when cloning).\n\nThe location of the .git dir is specified as an absolute path.\n\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tDaniel, is this a good idea, or should we perhaps tell the\n\thelper the location of the git repository otherwise?\n\n transport-helper.c |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex a80d803..4f95e7b 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -51,6 +51,12 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tdata->fetch = 1;\n \t\tif (!strcmp(buf.buf, \"import\"))\n \t\t\tdata->import = 1;\n+\t\tif (!strcmp(buf.buf, \"gitdir\")) {\n+\t\t\tstruct strbuf gitdir = STRBUF_INIT;\n+\t\t\tstrbuf_addf(&gitdir, \"gitdir %s\\n\", get_git_dir());\n+\t\t\twrite_in_full(helper->in, gitdir.buf, gitdir.len);\n+\t\t\tstrbuf_reset(&gitdir);\n+\t\t}\n \t}\n \treturn data->helper;\n }\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126811","messageId":"1257364098-1685-13-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 12/13] Basic build infrastructure for Python scripts","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:17Z","receivedAt":"2009-11-04T19:48:17Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"From: Johan Herland <johan@herland.net>\n\nThis patch adds basic boilerplate support (based on corresponding Perl\nsections) for enabling the building and installation Python scripts.\n\nThere are currently no Python scripts being built, and when Python\nscripts are added in future patches, their building and installation\ncan be disabled by defining NO_PYTHON.\n\nSigned-off-by: Johan Herland <johan@herland.net>\n---\n\n\tUnchanged.\n\n Makefile      |   13 +++++++++++++\n configure.ac  |    3 +++\n t/test-lib.sh |    1 +\n 3 files changed, 17 insertions(+), 0 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 5d5976f..6d1593f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -168,6 +168,8 @@ all::\n #\n # Define NO_PERL if you do not want Perl scripts or libraries at all.\n #\n+# Define NO_PYTHON if you do not want Python scripts or libraries at all.\n+#\n # Define NO_TCLTK if you do not want Tcl/Tk GUI.\n #\n # The TCL_PATH variable governs the location of the Tcl interpreter\n@@ -312,6 +314,7 @@ LIB_H =\n LIB_OBJS =\n PROGRAMS =\n SCRIPT_PERL =\n+SCRIPT_PYTHON =\n SCRIPT_SH =\n TEST_PROGRAMS =\n \n@@ -349,6 +352,7 @@ SCRIPT_PERL += git-svn.perl\n \n SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) \\\n \t  $(patsubst %.perl,%,$(SCRIPT_PERL)) \\\n+\t  $(patsubst %.py,%,$(SCRIPT_PYTHON)) \\\n \t  git-instaweb\n \n # Empty...\n@@ -402,8 +406,12 @@ endif\n ifndef PERL_PATH\n \tPERL_PATH = /usr/bin/perl\n endif\n+ifndef PYTHON_PATH\n+\tPYTHON_PATH = /usr/bin/python\n+endif\n \n export PERL_PATH\n+export PYTHON_PATH\n \n LIB_FILE=libgit.a\n XDIFF_LIB=xdiff/lib.a\n@@ -1315,6 +1323,10 @@ ifeq ($(PERL_PATH),)\n NO_PERL=NoThanks\n endif\n \n+ifeq ($(PYTHON_PATH),)\n+NO_PYTHON=NoThanks\n+endif\n+\n QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir\n QUIET_SUBDIR1  =\n \n@@ -1362,6 +1374,7 @@ prefix_SQ = $(subst ','\\'',$(prefix))\n \n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\n PERL_PATH_SQ = $(subst ','\\'',$(PERL_PATH))\n+PYTHON_PATH_SQ = $(subst ','\\'',$(PYTHON_PATH))\n TCLTK_PATH_SQ = $(subst ','\\'',$(TCLTK_PATH))\n \n LIBS = $(GITLIBS) $(EXTLIBS)\ndiff --git a/configure.ac b/configure.ac\nindex b09b8e4..84b6cf4 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -233,6 +233,9 @@ GIT_ARG_SET_PATH(shell)\n # Define PERL_PATH to provide path to Perl.\n GIT_ARG_SET_PATH(perl)\n #\n+# Define PYTHON_PATH to provide path to Python.\n+GIT_ARG_SET_PATH(python)\n+#\n # Define ZLIB_PATH to provide path to zlib.\n GIT_ARG_SET_PATH(zlib)\n #\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex f2ca536..0b991db 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -729,6 +729,7 @@ case $(uname -s) in\n esac\n \n test -z \"$NO_PERL\" && test_set_prereq PERL\n+test -z \"$NO_PYTHON\" && test_set_prereq PYTHON\n \n # test whether the filesystem supports symbolic links\n ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126807","messageId":"1257364098-1685-14-git-send-email-srabbelier@gmail.com","threadId":"21484","inReplyTo":"1257364098-1685-1-git-send-email-srabbelier@gmail.com","subject":"[PATCH v2 13/13] Add Python support library for remote helpers","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T19:48:18Z","receivedAt":"2009-11-04T19:48:18Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"This patch introduces parts of a Python package called\n\"git_remote_helpers\" containing the building blocks for\npython helper.\nThe actual remote helpers itself are NOT part of this patch.\n\nThe patch includes the necessary Makefile additions to build and install\nthe git_remote_cvs Python package along with the rest of Git.\n\nThis patch is based on Johan Herland's git_remote_cvs patch and\nhas been improved by the following contributions:\n- David Aguilar: Lots of Python coding style fixes\n- David Aguilar: DESTDIR support in Makefile\n\nCc: David Aguilar <davvid@gmail.com>\nCc: Johan Herland <johan@herland.net>\nSigned-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n---\n\n\tEjected all cvs specific parts (I grepped :P).\n\n Makefile                           |   38 ++\n git_remote_helpers/.gitignore      |    2 +\n git_remote_helpers/Makefile        |   35 ++\n git_remote_helpers/__init__.py     |   16 +\n git_remote_helpers/git/git.py      |  678 ++++++++++++++++++++++++++++++++++++\n git_remote_helpers/setup.py        |   17 +\n git_remote_helpers/util.py         |  194 ++++++++++\n t/test-lib.sh                      |    9 +\n 8 files changed, 989 insertions(+), 0 deletions(-)\n create mode 100644 git_remote_helpers/.gitignore\n create mode 100644 git_remote_helpers/Makefile\n create mode 100644 git_remote_helpers/__init__.py\n create mode 100644 git_remote_helpers/git/__init__.py\n create mode 100644 git_remote_helpers/git/git.py\n create mode 100644 git_remote_helpers/setup.py\n create mode 100644 git_remote_helpers/util.py\n\ndiff --git a/Makefile b/Makefile\nindex 6d1593f..701439f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1406,6 +1406,9 @@ endif\n ifndef NO_PERL\n \t$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all\n endif\n+ifndef NO_PYTHON\n+\t$(QUIET_SUBDIR0)git_remote_helpers $(QUIET_SUBDIR1) PYTHON_PATH='$(PYTHON_PATH_SQ)' prefix='$(prefix_SQ)' all\n+endif\n \t$(QUIET_SUBDIR0)templates $(QUIET_SUBDIR1)\n \n please_set_SHELL_PATH_to_a_more_modern_shell:\n@@ -1524,6 +1527,35 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)) git-instaweb: % : unimplemented.sh\n \tmv $@+ $@\n endif # NO_PERL\n \n+ifndef NO_PYTHON\n+$(patsubst %.py,%,$(SCRIPT_PYTHON)): GIT-CFLAGS\n+$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : %.py\n+\t$(QUIET_GEN)$(RM) $@ $@+ && \\\n+\tINSTLIBDIR=`MAKEFLAGS= $(MAKE) -C git_remote_helpers -s \\\n+\t\t--no-print-directory prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' \\\n+\t\tinstlibdir` && \\\n+\tsed -e '1{' \\\n+\t    -e '\ts|#!.*python|#!$(PYTHON_PATH_SQ)|' \\\n+\t    -e '}' \\\n+\t    -e 's|^import sys.*|&; \\\\\\\n+\t           import os; \\\\\\\n+\t           sys.path[0] = os.environ.has_key(\"GITPYTHONLIB\") and \\\\\\\n+\t                         os.environ[\"GITPYTHONLIB\"] or \\\\\\\n+\t                         \"@@INSTLIBDIR@@\"|' \\\n+\t    -e 's|@@INSTLIBDIR@@|'\"$$INSTLIBDIR\"'|g' \\\n+\t    $@.py >$@+ && \\\n+\tchmod +x $@+ && \\\n+\tmv $@+ $@\n+else # NO_PYTHON\n+$(patsubst %.py,%,$(SCRIPT_PYTHON)): % : unimplemented.sh\n+\t$(QUIET_GEN)$(RM) $@ $@+ && \\\n+\tsed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \\\n+\t    -e 's|@@REASON@@|NO_PYTHON=$(NO_PYTHON)|g' \\\n+\t    unimplemented.sh >$@+ && \\\n+\tchmod +x $@+ && \\\n+\tmv $@+ $@\n+endif # NO_PYTHON\n+\n configure: configure.ac\n \t$(QUIET_GEN)$(RM) $@ $<+ && \\\n \tsed -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n@@ -1748,6 +1780,9 @@ install: all\n ifndef NO_PERL\n \t$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install\n endif\n+ifndef NO_PYTHON\n+\t$(MAKE) -C git_remote_helpers prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install\n+endif\n ifndef NO_TCLTK\n \t$(MAKE) -C gitk-git install\n \t$(MAKE) -C git-gui gitexecdir='$(gitexec_instdir_SQ)' install\n@@ -1862,6 +1897,9 @@ ifndef NO_PERL\n \t$(RM) gitweb/gitweb.cgi\n \t$(MAKE) -C perl clean\n endif\n+ifndef NO_PYTHON\n+\t$(MAKE) -C git_remote_helpers clean\n+endif\n \t$(MAKE) -C templates/ clean\n \t$(MAKE) -C t/ clean\n ifndef NO_TCLTK\ndiff --git a/git_remote_helpers/.gitignore b/git_remote_helpers/.gitignore\nnew file mode 100644\nindex 0000000..2247d5f\n--- /dev/null\n+++ b/git_remote_helpers/.gitignore\n@@ -0,0 +1,2 @@\n+/build\n+/dist\ndiff --git a/git_remote_helpers/Makefile b/git_remote_helpers/Makefile\nnew file mode 100644\nindex 0000000..c62dfd0\n--- /dev/null\n+++ b/git_remote_helpers/Makefile\n@@ -0,0 +1,35 @@\n+#\n+# Makefile for the git_remote_helpers python support modules\n+#\n+pysetupfile:=setup.py\n+\n+# Shell quote (do not use $(call) to accommodate ancient setups);\n+DESTDIR_SQ = $(subst ','\\'',$(DESTDIR))\n+\n+ifndef PYTHON_PATH\n+\tPYTHON_PATH = /usr/bin/python\n+endif\n+ifndef prefix\n+\tprefix = $(HOME)\n+endif\n+ifndef V\n+\tQUIET = @\n+\tQUIETSETUP = --quiet\n+endif\n+\n+PYLIBDIR=$(shell $(PYTHON_PATH) -c \\\n+\t \"import sys; \\\n+\t print 'lib/python%i.%i/site-packages' % sys.version_info[:2]\")\n+\n+all: $(pysetupfile)\n+\t$(QUIET)$(PYTHON_PATH) $(pysetupfile) $(QUIETSETUP) build\n+\n+install: $(pysetupfile)\n+\t$(PYTHON_PATH) $(pysetupfile) install --prefix $(DESTDIR_SQ)$(prefix)\n+\n+instlibdir: $(pysetupfile)\n+\t@echo \"$(DESTDIR_SQ)$(prefix)/$(PYLIBDIR)\"\n+\n+clean:\n+\t$(QUIET)$(PYTHON_PATH) $(pysetupfile) $(QUIETSETUP) clean -a\n+\t$(RM) *.pyo *.pyc\ndiff --git a/git_remote_helpers/__init__.py b/git_remote_helpers/__init__.py\nnew file mode 100644\nindex 0000000..00f69cb\n--- /dev/null\n+++ b/git_remote_helpers/__init__.py\n@@ -0,0 +1,16 @@\n+#!/usr/bin/env python\n+\n+\"\"\"Support library package for git remote helpers.\n+\n+Git remote helpers are helper commands that interfaces with a non-git\n+repository to provide automatic import of non-git history into a Git\n+repository.\n+\n+This package provides the support library needed by these helpers..\n+The following modules are included:\n+\n+- git.git - Interaction with Git repositories\n+\n+- util - General utility functionality use by the other modules in\n+         this package, and also used directly by the helpers.\n+\"\"\"\ndiff --git a/git_remote_helpers/git/__init__.py b/git_remote_helpers/git/__init__.py\nnew file mode 100644\nindex 0000000..e69de29\ndiff --git a/git_remote_helpers/git/git.py b/git_remote_helpers/git/git.py\nnew file mode 100644\nindex 0000000..a383e6c\n--- /dev/null\n+++ b/git_remote_helpers/git/git.py\n@@ -0,0 +1,678 @@\n+#!/usr/bin/env python\n+\n+\"\"\"Functionality for interacting with Git repositories.\n+\n+This module provides classes for interfacing with a Git repository.\n+\"\"\"\n+\n+import os\n+import re\n+import time\n+from binascii import hexlify\n+from cStringIO import StringIO\n+import unittest\n+\n+from git_remote_helpers.util import debug, error, die, start_command, run_command\n+\n+\n+def get_git_dir ():\n+    \"\"\"Return the path to the GIT_DIR for this repo.\"\"\"\n+    args = (\"git\", \"rev-parse\", \"--git-dir\")\n+    exit_code, output, errors = run_command(args)\n+    if exit_code:\n+        die(\"Failed to retrieve git dir\")\n+    assert not errors\n+    return output.strip()\n+\n+\n+def parse_git_config ():\n+    \"\"\"Return a dict containing the parsed version of 'git config -l'.\"\"\"\n+    exit_code, output, errors = run_command((\"git\", \"config\", \"-z\", \"-l\"))\n+    if exit_code:\n+        die(\"Failed to retrieve git configuration\")\n+    assert not errors\n+    return dict([e.split('\\n', 1) for e in output.split(\"\\0\") if e])\n+\n+\n+def git_config_bool (value):\n+    \"\"\"Convert the given git config string value to True or False.\n+\n+    Raise ValueError if the given string was not recognized as a\n+    boolean value.\n+\n+    \"\"\"\n+    norm_value = str(value).strip().lower()\n+    if norm_value in (\"true\", \"1\", \"yes\", \"on\", \"\"):\n+        return True\n+    if norm_value in (\"false\", \"0\", \"no\", \"off\", \"none\"):\n+        return False\n+    raise ValueError(\"Failed to parse '%s' into a boolean value\" % (value))\n+\n+\n+def valid_git_ref (ref_name):\n+    \"\"\"Return True iff the given ref name is a valid git ref name.\"\"\"\n+    # The following is a reimplementation of the git check-ref-format\n+    # command.  The rules were derived from the git check-ref-format(1)\n+    # manual page.  This code should be replaced by a call to\n+    # check_ref_format() in the git library, when such is available.\n+    if ref_name.endswith('/') or \\\n+       ref_name.startswith('.') or \\\n+       ref_name.count('/.') or \\\n+       ref_name.count('..') or \\\n+       ref_name.endswith('.lock'):\n+        return False\n+    for c in ref_name:\n+        if ord(c) < 0x20 or ord(c) == 0x7f or c in \" ~^:?*[\":\n+            return False\n+    return True\n+\n+\n+class GitObjectFetcher(object):\n+\n+    \"\"\"Provide parsed access to 'git cat-file --batch'.\n+\n+    This provides a read-only interface to the Git object database.\n+\n+    \"\"\"\n+\n+    def __init__ (self):\n+        \"\"\"Initiate a 'git cat-file --batch' session.\"\"\"\n+        self.queue = []  # List of object names to be submitted\n+        self.in_transit = None  # Object name currently in transit\n+\n+        # 'git cat-file --batch' produces binary output which is likely\n+        # to be corrupted by the default \"rU\"-mode pipe opened by\n+        # start_command.  (Mode == \"rU\" does universal new-line\n+        # conversion, which mangles carriage returns.) Therefore, we\n+        # open an explicitly binary-safe pipe for transferring the\n+        # output from 'git cat-file --batch'.\n+        pipe_r_fd, pipe_w_fd = os.pipe()\n+        pipe_r = os.fdopen(pipe_r_fd, \"rb\")\n+        pipe_w = os.fdopen(pipe_w_fd, \"wb\")\n+        self.proc = start_command((\"git\", \"cat-file\", \"--batch\"),\n+                                  stdout = pipe_w)\n+        self.f = pipe_r\n+\n+    def __del__ (self):\n+        \"\"\"Verify completed communication with 'git cat-file --batch'.\"\"\"\n+        assert not self.queue\n+        assert self.in_transit is None\n+        self.proc.stdin.close()\n+        assert self.proc.wait() == 0  # Zero exit code\n+        assert self.f.read() == \"\"  # No remaining output\n+\n+    def _submit_next_object (self):\n+        \"\"\"Submit queue items to the 'git cat-file --batch' process.\n+\n+        If there are items in the queue, and there is currently no item\n+        currently in 'transit', then pop the first item off the queue,\n+        and submit it.\n+\n+        \"\"\"\n+        if self.queue and self.in_transit is None:\n+            self.in_transit = self.queue.pop(0)\n+            print >> self.proc.stdin, self.in_transit[0]\n+\n+    def push (self, obj, callback):\n+        \"\"\"Push the given object name onto the queue.\n+\n+        The given callback function will at some point in the future\n+        be called exactly once with the following arguments:\n+        - self - this GitObjectFetcher instance\n+        - obj  - the object name provided to push()\n+        - sha1 - the SHA1 of the object, if 'None' obj is missing\n+        - t    - the type of the object (tag/commit/tree/blob)\n+        - size - the size of the object in bytes\n+        - data - the object contents\n+\n+        \"\"\"\n+        self.queue.append((obj, callback))\n+        self._submit_next_object()  # (Re)start queue processing\n+\n+    def process_next_entry (self):\n+        \"\"\"Read the next entry off the queue and invoke callback.\"\"\"\n+        obj, cb = self.in_transit\n+        self.in_transit = None\n+        header = self.f.readline()\n+        if header == \"%s missing\\n\" % (obj):\n+            cb(self, obj, None, None, None, None)\n+            return\n+        sha1, t, size = header.split(\" \")\n+        assert len(sha1) == 40\n+        assert t in (\"tag\", \"commit\", \"tree\", \"blob\")\n+        assert size.endswith(\"\\n\")\n+        size = int(size.strip())\n+        data = self.f.read(size)\n+        assert self.f.read(1) == \"\\n\"\n+        cb(self, obj, sha1, t, size, data)\n+        self._submit_next_object()\n+\n+    def process (self):\n+        \"\"\"Process the current queue until empty.\"\"\"\n+        while self.in_transit is not None:\n+            self.process_next_entry()\n+\n+    # High-level convenience methods:\n+\n+    def get_sha1 (self, objspec):\n+        \"\"\"Return the SHA1 of the object specified by 'objspec'.\n+\n+        Return None if 'objspec' does not specify an existing object.\n+\n+        \"\"\"\n+        class _ObjHandler(object):\n+            \"\"\"Helper class for getting the returned SHA1.\"\"\"\n+            def __init__ (self, parser):\n+                self.parser = parser\n+                self.sha1 = None\n+\n+            def __call__ (self, parser, obj, sha1, t, size, data):\n+                # FIXME: Many unused arguments. Could this be cheaper?\n+                assert parser == self.parser\n+                self.sha1 = sha1\n+\n+        handler = _ObjHandler(self)\n+        self.push(objspec, handler)\n+        self.process()\n+        return handler.sha1\n+\n+    def open_obj (self, objspec):\n+        \"\"\"Return a file object wrapping the contents of a named object.\n+\n+        The caller is responsible for calling .close() on the returned\n+        file object.\n+\n+        Raise KeyError if 'objspec' does not exist in the repo.\n+\n+        \"\"\"\n+        class _ObjHandler(object):\n+            \"\"\"Helper class for parsing the returned git object.\"\"\"\n+            def __init__ (self, parser):\n+                \"\"\"Set up helper.\"\"\"\n+                self.parser = parser\n+                self.contents = StringIO()\n+                self.err = None\n+\n+            def __call__ (self, parser, obj, sha1, t, size, data):\n+                \"\"\"Git object callback (see GitObjectFetcher documentation).\"\"\"\n+                assert parser == self.parser\n+                if not sha1:  # Missing object\n+                    self.err = \"Missing object '%s'\" % obj\n+                else:\n+                    assert size == len(data)\n+                    self.contents.write(data)\n+\n+        handler = _ObjHandler(self)\n+        self.push(objspec, handler)\n+        self.process()\n+        if handler.err:\n+            raise KeyError(handler.err)\n+        handler.contents.seek(0)\n+        return handler.contents\n+\n+    def walk_tree (self, tree_objspec, callback, prefix = \"\"):\n+        \"\"\"Recursively walk the given Git tree object.\n+\n+        Recursively walk all subtrees of the given tree object, and\n+        invoke the given callback passing three arguments:\n+        (path, mode, data) with the path, permission bits, and contents\n+        of all the blobs found in the entire tree structure.\n+\n+        \"\"\"\n+        class _ObjHandler(object):\n+            \"\"\"Helper class for walking a git tree structure.\"\"\"\n+            def __init__ (self, parser, cb, path, mode = None):\n+                \"\"\"Set up helper.\"\"\"\n+                self.parser = parser\n+                self.cb = cb\n+                self.path = path\n+                self.mode = mode\n+                self.err = None\n+\n+            def parse_tree (self, treedata):\n+                \"\"\"Parse tree object data, yield tree entries.\n+\n+                Each tree entry is a 3-tuple (mode, sha1, path)\n+\n+                self.path is prepended to all paths yielded\n+                from this method.\n+\n+                \"\"\"\n+                while treedata:\n+                    mode = int(treedata[:6], 10)\n+                    # Turn 100xxx into xxx\n+                    if mode > 100000:\n+                        mode -= 100000\n+                    assert treedata[6] == \" \"\n+                    i = treedata.find(\"\\0\", 7)\n+                    assert i > 0\n+                    path = treedata[7:i]\n+                    sha1 = hexlify(treedata[i + 1: i + 21])\n+                    yield (mode, sha1, self.path + path)\n+                    treedata = treedata[i + 21:]\n+\n+            def __call__ (self, parser, obj, sha1, t, size, data):\n+                \"\"\"Git object callback (see GitObjectFetcher documentation).\"\"\"\n+                assert parser == self.parser\n+                if not sha1:  # Missing object\n+                    self.err = \"Missing object '%s'\" % (obj)\n+                    return\n+                assert size == len(data)\n+                if t == \"tree\":\n+                    if self.path:\n+                        self.path += \"/\"\n+                    # Recurse into all blobs and subtrees\n+                    for m, s, p in self.parse_tree(data):\n+                        parser.push(s,\n+                                    self.__class__(self.parser, self.cb, p, m))\n+                elif t == \"blob\":\n+                    self.cb(self.path, self.mode, data)\n+                else:\n+                    raise ValueError(\"Unknown object type '%s'\" % (t))\n+\n+        self.push(tree_objspec, _ObjHandler(self, callback, prefix))\n+        self.process()\n+\n+\n+class GitRefMap(object):\n+\n+    \"\"\"Map Git ref names to the Git object names they currently point to.\n+\n+    Behaves like a dictionary of Git ref names -> Git object names.\n+\n+    \"\"\"\n+\n+    def __init__ (self, obj_fetcher):\n+        \"\"\"Create a new Git ref -> object map.\"\"\"\n+        self.obj_fetcher = obj_fetcher\n+        self._cache = {}  # dict: refname -> objname\n+\n+    def _load (self, ref):\n+        \"\"\"Retrieve the object currently bound to the given ref.\n+\n+        The name of the object pointed to by the given ref is stored\n+        into this mapping, and also returned.\n+\n+        \"\"\"\n+        if ref not in self._cache:\n+            self._cache[ref] = self.obj_fetcher.get_sha1(ref)\n+        return self._cache[ref]\n+\n+    def __contains__ (self, refname):\n+        \"\"\"Return True if the given refname is present in this cache.\"\"\"\n+        return bool(self._load(refname))\n+\n+    def __getitem__ (self, refname):\n+        \"\"\"Return the git object name pointed to by the given refname.\"\"\"\n+        commit = self._load(refname)\n+        if commit is None:\n+            raise KeyError(\"Unknown ref '%s'\" % (refname))\n+        return commit\n+\n+    def get (self, refname, default = None):\n+        \"\"\"Return the git object name pointed to by the given refname.\"\"\"\n+        commit = self._load(refname)\n+        if commit is None:\n+            return default\n+        return commit\n+\n+\n+class GitFICommit(object):\n+\n+    \"\"\"Encapsulate the data in a Git fast-import commit command.\"\"\"\n+\n+    SHA1RE = re.compile(r'^[0-9a-f]{40}$')\n+\n+    @classmethod\n+    def parse_mode (cls, mode):\n+        \"\"\"Verify the given git file mode, and return it as a string.\"\"\"\n+        assert mode in (644, 755, 100644, 100755, 120000)\n+        return \"%i\" % (mode)\n+\n+    @classmethod\n+    def parse_objname (cls, objname):\n+        \"\"\"Return the given object name (or mark number) as a string.\"\"\"\n+        if isinstance(objname, int):  # Object name is a mark number\n+            assert objname > 0\n+            return \":%i\" % (objname)\n+\n+        # No existence check is done, only checks for valid format\n+        assert cls.SHA1RE.match(objname)  # Object name is valid SHA1\n+        return objname\n+\n+    @classmethod\n+    def quote_path (cls, path):\n+        \"\"\"Return a quoted version of the given path.\"\"\"\n+        path = path.replace(\"\\\\\", \"\\\\\\\\\")\n+        path = path.replace(\"\\n\", \"\\\\n\")\n+        path = path.replace('\"', '\\\\\"')\n+        return '\"%s\"' % (path)\n+\n+    @classmethod\n+    def parse_path (cls, path):\n+        \"\"\"Verify that the given path is valid, and quote it, if needed.\"\"\"\n+        assert not isinstance(path, int)  # Cannot be a mark number\n+\n+        # These checks verify the rules on the fast-import man page\n+        assert not path.count(\"//\")\n+        assert not path.endswith(\"/\")\n+        assert not path.startswith(\"/\")\n+        assert not path.count(\"/./\")\n+        assert not path.count(\"/../\")\n+        assert not path.endswith(\"/.\")\n+        assert not path.endswith(\"/..\")\n+        assert not path.startswith(\"./\")\n+        assert not path.startswith(\"../\")\n+\n+        if path.count('\"') + path.count('\\n') + path.count('\\\\'):\n+            return cls.quote_path(path)\n+        return path\n+\n+    def __init__ (self, name, email, timestamp, timezone, message):\n+        \"\"\"Create a new Git fast-import commit, with the given metadata.\"\"\"\n+        self.name = name\n+        self.email = email\n+        self.timestamp = timestamp\n+        self.timezone = timezone\n+        self.message = message\n+        self.pathops = []  # List of path operations in this commit\n+\n+    def modify (self, mode, blobname, path):\n+        \"\"\"Add a file modification to this Git fast-import commit.\"\"\"\n+        self.pathops.append((\"M\",\n+                             self.parse_mode(mode),\n+                             self.parse_objname(blobname),\n+                             self.parse_path(path)))\n+\n+    def delete (self, path):\n+        \"\"\"Add a file deletion to this Git fast-import commit.\"\"\"\n+        self.pathops.append((\"D\", self.parse_path(path)))\n+\n+    def copy (self, path, newpath):\n+        \"\"\"Add a file copy to this Git fast-import commit.\"\"\"\n+        self.pathops.append((\"C\",\n+                             self.parse_path(path),\n+                             self.parse_path(newpath)))\n+\n+    def rename (self, path, newpath):\n+        \"\"\"Add a file rename to this Git fast-import commit.\"\"\"\n+        self.pathops.append((\"R\",\n+                             self.parse_path(path),\n+                             self.parse_path(newpath)))\n+\n+    def note (self, blobname, commit):\n+        \"\"\"Add a note object to this Git fast-import commit.\"\"\"\n+        self.pathops.append((\"N\",\n+                             self.parse_objname(blobname),\n+                             self.parse_objname(commit)))\n+\n+    def deleteall (self):\n+        \"\"\"Delete all files in this Git fast-import commit.\"\"\"\n+        self.pathops.append(\"deleteall\")\n+\n+\n+class TestGitFICommit(unittest.TestCase):\n+\n+    \"\"\"GitFICommit selftests.\"\"\"\n+\n+    def test_basic (self):\n+        \"\"\"GitFICommit basic selftests.\"\"\"\n+\n+        def expect_fail (method, data):\n+            \"\"\"Verify that the method(data) raises an AssertionError.\"\"\"\n+            try:\n+                method(data)\n+            except AssertionError:\n+                return\n+            raise AssertionError(\"Failed test for invalid data '%s(%s)'\" %\n+                                 (method.__name__, repr(data)))\n+\n+    def test_parse_mode (self):\n+        \"\"\"GitFICommit.parse_mode() selftests.\"\"\"\n+        self.assertEqual(GitFICommit.parse_mode(644), \"644\")\n+        self.assertEqual(GitFICommit.parse_mode(755), \"755\")\n+        self.assertEqual(GitFICommit.parse_mode(100644), \"100644\")\n+        self.assertEqual(GitFICommit.parse_mode(100755), \"100755\")\n+        self.assertEqual(GitFICommit.parse_mode(120000), \"120000\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_mode, 0)\n+        self.assertRaises(AssertionError, GitFICommit.parse_mode, 123)\n+        self.assertRaises(AssertionError, GitFICommit.parse_mode, 600)\n+        self.assertRaises(AssertionError, GitFICommit.parse_mode, \"644\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_mode, \"abc\")\n+\n+    def test_parse_objname (self):\n+        \"\"\"GitFICommit.parse_objname() selftests.\"\"\"\n+        self.assertEqual(GitFICommit.parse_objname(1), \":1\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_objname, 0)\n+        self.assertRaises(AssertionError, GitFICommit.parse_objname, -1)\n+        self.assertEqual(GitFICommit.parse_objname(\"0123456789\" * 4),\n+                         \"0123456789\" * 4)\n+        self.assertEqual(GitFICommit.parse_objname(\"2468abcdef\" * 4),\n+                         \"2468abcdef\" * 4)\n+        self.assertRaises(AssertionError, GitFICommit.parse_objname,\n+                          \"abcdefghij\" * 4)\n+\n+    def test_parse_path (self):\n+        \"\"\"GitFICommit.parse_path() selftests.\"\"\"\n+        self.assertEqual(GitFICommit.parse_path(\"foo/bar\"), \"foo/bar\")\n+        self.assertEqual(GitFICommit.parse_path(\"path/with\\n and \\\" in it\"),\n+                         '\"path/with\\\\n and \\\\\" in it\"')\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, 1)\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, 0)\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, -1)\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"foo//bar\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"foo/bar/\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"/foo/bar\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"foo/./bar\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"foo/../bar\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"foo/bar/.\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"foo/bar/..\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"./foo/bar\")\n+        self.assertRaises(AssertionError, GitFICommit.parse_path, \"../foo/bar\")\n+\n+\n+class GitFastImport(object):\n+\n+    \"\"\"Encapsulate communication with git fast-import.\"\"\"\n+\n+    def __init__ (self, f, obj_fetcher, last_mark = 0):\n+        \"\"\"Set up self to communicate with a fast-import process through f.\"\"\"\n+        self.f = f  # File object where fast-import stream is written\n+        self.obj_fetcher = obj_fetcher  # GitObjectFetcher instance\n+        self.next_mark = last_mark + 1  # Next mark number\n+        self.refs = set()  # Keep track of the refnames we've seen\n+\n+    def comment (self, s):\n+        \"\"\"Write the given comment in the fast-import stream.\"\"\"\n+        assert \"\\n\" not in s, \"Malformed comment: '%s'\" % (s)\n+        self.f.write(\"# %s\\n\" % (s))\n+\n+    def commit (self, ref, commitdata):\n+        \"\"\"Make a commit on the given ref, with the given GitFICommit.\n+\n+        Return the mark number identifying this commit.\n+\n+        \"\"\"\n+        self.f.write(\"\"\"\\\n+commit %(ref)s\n+mark :%(mark)i\n+committer %(name)s <%(email)s> %(timestamp)i %(timezone)s\n+data %(msgLength)i\n+%(msg)s\n+\"\"\" % {\n+    'ref': ref,\n+    'mark': self.next_mark,\n+    'name': commitdata.name,\n+    'email': commitdata.email,\n+    'timestamp': commitdata.timestamp,\n+    'timezone': commitdata.timezone,\n+    'msgLength': len(commitdata.message),\n+    'msg': commitdata.message,\n+})\n+\n+        if ref not in self.refs:\n+            self.refs.add(ref)\n+            parent = ref + \"^0\"\n+            if self.obj_fetcher.get_sha1(parent):\n+                self.f.write(\"from %s\\n\" % (parent))\n+\n+        for op in commitdata.pathops:\n+            self.f.write(\" \".join(op))\n+            self.f.write(\"\\n\")\n+        self.f.write(\"\\n\")\n+        retval = self.next_mark\n+        self.next_mark += 1\n+        return retval\n+\n+    def blob (self, data):\n+        \"\"\"Import the given blob.\n+\n+        Return the mark number identifying this blob.\n+\n+        \"\"\"\n+        self.f.write(\"blob\\nmark :%i\\ndata %i\\n%s\\n\" %\n+                     (self.next_mark, len(data), data))\n+        retval = self.next_mark\n+        self.next_mark += 1\n+        return retval\n+\n+    def reset (self, ref, objname):\n+        \"\"\"Reset the given ref to point at the given Git object.\"\"\"\n+        self.f.write(\"reset %s\\nfrom %s\\n\\n\" %\n+                     (ref, GitFICommit.parse_objname(objname)))\n+        if ref not in self.refs:\n+            self.refs.add(ref)\n+\n+\n+class GitNotes(object):\n+\n+    \"\"\"Encapsulate access to Git notes.\n+\n+    Simulates a dictionary of object name (SHA1) -> Git note mappings.\n+\n+    \"\"\"\n+\n+    def __init__ (self, notes_ref, obj_fetcher):\n+        \"\"\"Create a new Git notes interface, bound to the given notes ref.\"\"\"\n+        self.notes_ref = notes_ref\n+        self.obj_fetcher = obj_fetcher  # Used to get objects from repo\n+        self.imports = []  # list: (objname, note data blob name) tuples\n+\n+    def __del__ (self):\n+        \"\"\"Verify that self.commit_notes() was called before destruction.\"\"\"\n+        if self.imports:\n+            error(\"Missing call to self.commit_notes().\")\n+            error(\"%i notes are not committed!\", len(self.imports))\n+\n+    def _load (self, objname):\n+        \"\"\"Return the note data associated with the given git object.\n+\n+        The note data is returned in string form. If no note is found\n+        for the given object, None is returned.\n+\n+        \"\"\"\n+        try:\n+            f = self.obj_fetcher.open_obj(\"%s:%s\" % (self.notes_ref, objname))\n+            ret = f.read()\n+            f.close()\n+        except KeyError:\n+            ret = None\n+        return ret\n+\n+    def __getitem__ (self, objname):\n+        \"\"\"Return the note contents associated with the given object.\n+\n+        Raise KeyError if given object has no associated note.\n+\n+        \"\"\"\n+        blobdata = self._load(objname)\n+        if blobdata is None:\n+            raise KeyError(\"Object '%s' has no note\" % (objname))\n+        return blobdata\n+\n+    def get (self, objname, default = None):\n+        \"\"\"Return the note contents associated with the given object.\n+\n+        Return given default if given object has no associated note.\n+\n+        \"\"\"\n+        blobdata = self._load(objname)\n+        if blobdata is None:\n+            return default\n+        return blobdata\n+\n+    def import_note (self, objname, data, gfi):\n+        \"\"\"Tell git fast-import to store data as a note for objname.\n+\n+        This method uses the given GitFastImport object to create a\n+        blob containing the given note data.  Also an entry mapping the\n+        given object name to the created blob is stored until\n+        commit_notes() is called.\n+\n+        Note that this method only works if it is later followed by a\n+        call to self.commit_notes() (which produces the note commit\n+        that refers to the blob produced here).\n+\n+        \"\"\"\n+        if not data.endswith(\"\\n\"):\n+            data += \"\\n\"\n+        gfi.comment(\"Importing note for object %s\" % (objname))\n+        mark = gfi.blob(data)\n+        self.imports.append((objname, mark))\n+\n+    def commit_notes (self, gfi, author, message):\n+        \"\"\"Produce a git fast-import note commit for the imported notes.\n+\n+        This method uses the given GitFastImport object to create a\n+        commit on the notes ref, introducing the notes previously\n+        submitted to import_note().\n+\n+        \"\"\"\n+        if not self.imports:\n+            return\n+        commitdata = GitFICommit(author[0], author[1],\n+                                 time.time(), \"0000\", message)\n+        for objname, blobname in self.imports:\n+            assert isinstance(objname, int) and objname > 0\n+            assert isinstance(blobname, int) and blobname > 0\n+            commitdata.note(blobname, objname)\n+        gfi.commit(self.notes_ref, commitdata)\n+        self.imports = []\n+\n+\n+class GitCachedNotes(GitNotes):\n+\n+    \"\"\"Encapsulate access to Git notes (cached version).\n+\n+    Only use this class if no caching is done at a higher level.\n+\n+    Simulates a dictionary of object name (SHA1) -> Git note mappings.\n+\n+    \"\"\"\n+\n+    def __init__ (self, notes_ref, obj_fetcher):\n+        \"\"\"Set up a caching wrapper around GitNotes.\"\"\"\n+        GitNotes.__init__(self, notes_ref, obj_fetcher)\n+        self._cache = {}  # Cache: object name -> note data\n+\n+    def __del__ (self):\n+        \"\"\"Verify that GitNotes' destructor is called.\"\"\"\n+        GitNotes.__del__(self)\n+\n+    def _load (self, objname):\n+        \"\"\"Extend GitNotes._load() with a local objname -> note cache.\"\"\"\n+        if objname not in self._cache:\n+            self._cache[objname] = GitNotes._load(self, objname)\n+        return self._cache[objname]\n+\n+    def import_note (self, objname, data, gfi):\n+        \"\"\"Extend GitNotes.import_note() with a local objname -> note cache.\"\"\"\n+        if not data.endswith(\"\\n\"):\n+            data += \"\\n\"\n+        assert objname not in self._cache\n+        self._cache[objname] = data\n+        GitNotes.import_note(self, objname, data, gfi)\n+\n+\n+if __name__ == '__main__':\n+    unittest.main()\ndiff --git a/git_remote_helpers/setup.py b/git_remote_helpers/setup.py\nnew file mode 100644\nindex 0000000..4d434b6\n--- /dev/null\n+++ b/git_remote_helpers/setup.py\n@@ -0,0 +1,17 @@\n+#!/usr/bin/env python\n+\n+\"\"\"Distutils build/install script for the git_remote_helpers package.\"\"\"\n+\n+from distutils.core import setup\n+\n+setup(\n+    name = 'git_remote_helpers',\n+    version = '0.1.0',\n+    description = 'Git remote helper program for non-git repositories',\n+    license = 'GPLv2',\n+    author = 'The Git Community',\n+    author_email = 'git@vger.kernel.org',\n+    url = 'http://www.git-scm.com/',\n+    package_dir = {'git_remote_helpers': ''},\n+    packages = ['git_remote_helpers', 'git_remote_helpers.git'],\n+)\ndiff --git a/git_remote_helpers/util.py b/git_remote_helpers/util.py\nnew file mode 100644\nindex 0000000..dce83e6\n--- /dev/null\n+++ b/git_remote_helpers/util.py\n@@ -0,0 +1,194 @@\n+#!/usr/bin/env python\n+\n+\"\"\"Misc. useful functionality used by the rest of this package.\n+\n+This module provides common functionality used by the other modules in\n+this package.\n+\n+\"\"\"\n+\n+import sys\n+import os\n+import subprocess\n+\n+\n+# Whether or not to show debug messages\n+DEBUG = False\n+\n+def notify(msg, *args):\n+    \"\"\"Print a message to stderr.\"\"\"\n+    print >> sys.stderr, msg % args\n+\n+def debug (msg, *args):\n+    \"\"\"Print a debug message to stderr when DEBUG is enabled.\"\"\"\n+    if DEBUG:\n+        print >> sys.stderr, msg % args\n+\n+def error (msg, *args):\n+    \"\"\"Print an error message to stderr.\"\"\"\n+    print >> sys.stderr, \"ERROR:\", msg % args\n+\n+def warn(msg, *args):\n+    \"\"\"Print a warning message to stderr.\"\"\"\n+    print >> sys.stderr, \"warning:\", msg % args\n+\n+def die (msg, *args):\n+    \"\"\"Print as error message to stderr and exit the program.\"\"\"\n+    error(msg, *args)\n+    sys.exit(1)\n+\n+\n+class ProgressIndicator(object):\n+\n+    \"\"\"Simple progress indicator.\n+\n+    Displayed as a spinning character by default, but can be customized\n+    by passing custom messages that overrides the spinning character.\n+\n+    \"\"\"\n+\n+    States = (\"|\", \"/\", \"-\", \"\\\\\")\n+\n+    def __init__ (self, prefix = \"\", f = sys.stdout):\n+        \"\"\"Create a new ProgressIndicator, bound to the given file object.\"\"\"\n+        self.n = 0  # Simple progress counter\n+        self.f = f  # Progress is written to this file object\n+        self.prev_len = 0  # Length of previous msg (to be overwritten)\n+        self.prefix = prefix  # Prefix prepended to each progress message\n+        self.prefix_lens = [] # Stack of prefix string lengths\n+\n+    def pushprefix (self, prefix):\n+        \"\"\"Append the given prefix onto the prefix stack.\"\"\"\n+        self.prefix_lens.append(len(self.prefix))\n+        self.prefix += prefix\n+\n+    def popprefix (self):\n+        \"\"\"Remove the last prefix from the prefix stack.\"\"\"\n+        prev_len = self.prefix_lens.pop()\n+        self.prefix = self.prefix[:prev_len]\n+\n+    def __call__ (self, msg = None, lf = False):\n+        \"\"\"Indicate progress, possibly with a custom message.\"\"\"\n+        if msg is None:\n+            msg = self.States[self.n % len(self.States)]\n+        msg = self.prefix + msg\n+        print >> self.f, \"\\r%-*s\" % (self.prev_len, msg),\n+        self.prev_len = len(msg.expandtabs())\n+        if lf:\n+            print >> self.f\n+            self.prev_len = 0\n+        self.n += 1\n+\n+    def finish (self, msg = \"done\", noprefix = False):\n+        \"\"\"Finalize progress indication with the given message.\"\"\"\n+        if noprefix:\n+            self.prefix = \"\"\n+        self(msg, True)\n+\n+\n+def start_command (args, cwd = None, shell = False, add_env = None,\n+                   stdin = subprocess.PIPE, stdout = subprocess.PIPE,\n+                   stderr = subprocess.PIPE):\n+    \"\"\"Start the given command, and return a subprocess object.\n+\n+    This provides a simpler interface to the subprocess module.\n+\n+    \"\"\"\n+    env = None\n+    if add_env is not None:\n+        env = os.environ.copy()\n+        env.update(add_env)\n+    return subprocess.Popen(args, bufsize = 1, stdin = stdin, stdout = stdout,\n+                            stderr = stderr, cwd = cwd, shell = shell,\n+                            env = env, universal_newlines = True)\n+\n+\n+def run_command (args, cwd = None, shell = False, add_env = None,\n+                 flag_error = True):\n+    \"\"\"Run the given command to completion, and return its results.\n+\n+    This provides a simpler interface to the subprocess module.\n+\n+    The results are formatted as a 3-tuple: (exit_code, output, errors)\n+\n+    If flag_error is enabled, Error messages will be produced if the\n+    subprocess terminated with a non-zero exit code and/or stderr\n+    output.\n+\n+    The other arguments are passed on to start_command().\n+\n+    \"\"\"\n+    process = start_command(args, cwd, shell, add_env)\n+    (output, errors) = process.communicate()\n+    exit_code = process.returncode\n+    if flag_error and errors:\n+        error(\"'%s' returned errors:\\n---\\n%s---\", \" \".join(args), errors)\n+    if flag_error and exit_code:\n+        error(\"'%s' returned exit code %i\", \" \".join(args), exit_code)\n+    return (exit_code, output, errors)\n+\n+\n+def file_reader_method (missing_ok = False):\n+    \"\"\"Decorator for simplifying reading of files.\n+\n+    If missing_ok is True, a failure to open a file for reading will\n+    not raise the usual IOError, but instead the wrapped method will be\n+    called with f == None.  The method must in this case properly\n+    handle f == None.\n+\n+    \"\"\"\n+    def _wrap (method):\n+        \"\"\"Teach given method to handle both filenames and file objects.\n+\n+        The given method must take a file object as its second argument\n+        (the first argument being 'self', of course).  This decorator\n+        will take a filename given as the second argument and promote\n+        it to a file object.\n+\n+        \"\"\"\n+        def _wrapped_method (self, filename, *args, **kwargs):\n+            if isinstance(filename, file):\n+                f = filename\n+            else:\n+                try:\n+                    f = open(filename, 'r')\n+                except IOError:\n+                    if missing_ok:\n+                        f = None\n+                    else:\n+                        raise\n+            try:\n+                return method(self, f, *args, **kwargs)\n+            finally:\n+                if not isinstance(filename, file) and f:\n+                    f.close()\n+        return _wrapped_method\n+    return _wrap\n+\n+\n+def file_writer_method (method):\n+    \"\"\"Decorator for simplifying writing of files.\n+\n+    Enables the given method to handle both filenames and file objects.\n+\n+    The given method must take a file object as its second argument\n+    (the first argument being 'self', of course).  This decorator will\n+    take a filename given as the second argument and promote it to a\n+    file object.\n+\n+    \"\"\"\n+    def _new_method (self, filename, *args, **kwargs):\n+        if isinstance(filename, file):\n+            f = filename\n+        else:\n+            # Make sure the containing directory exists\n+            parent_dir = os.path.dirname(filename)\n+            if not os.path.isdir(parent_dir):\n+                os.makedirs(parent_dir)\n+            f = open(filename, 'w')\n+        try:\n+            return method(self, f, *args, **kwargs)\n+        finally:\n+            if not isinstance(filename, file):\n+                f.close()\n+    return _new_method\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 0b991db..6ed5b28 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -638,6 +638,15 @@ test -d ../templates/blt || {\n \terror \"You haven't built things yet, have you?\"\n }\n \n+if test -z \"$GIT_TEST_INSTALLED\"\n+then\n+\tGITPYTHONLIB=\"$(pwd)/../git_remote_helpers/build/lib\"\n+\texport GITPYTHONLIB\n+\ttest -d ../git_remote_helpers/build || {\n+\t\terror \"You haven't built git_remote_helpers yet, have you?\"\n+\t}\n+fi\n+\n if ! test -x ../test-chmtime; then\n \techo >&2 'You need to build test-chmtime:'\n \techo >&2 'Run \"make test-chmtime\" in the source (toplevel) directory'\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126828","messageId":"alpine.LNX.2.00.0911041601170.14365@iabervon.org","threadId":"21484","inReplyTo":"1257364098-1685-10-git-send-email-srabbelier@gmail.com","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T21:20:11Z","receivedAt":"2009-11-04T21:20:11Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n\n> This way the helper can write to 'refs/remotes/origin/*' instead of\n> writing to 'refs/heads/*'.\n> \n> Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n> ---\n> \n>   Daniel, does this look good to you?\n> \n>   Let's assume the following:\n>   * list: only HEAD is a symref (to refs/heads/<branch>), all other\n>           refs are '? refs/heads/<branch>'.\n>   * import: the helper creates branches under refs/remotes/<alias>/*\n>             (since the refspec code is not yet in that would allow\n>              it to create them under refs/<vcs>/<alias>/*)\n>\n>   Now when updating the refs we do the following:\n>   transport-helper.c:145 \"read_ref(posn->name, posn->old_sha1);\"\n> \n>   The value of posn->name looks like \"refs/heads/<branch>\". So what\n>   does this lookup do? It tries to lookup the new value of the ref\n>   _where it will be created_, this fails of course, since the ref\n>   currently only exists as \"refs/remotes/origin/<branch>\". So, we\n>   should instead be doing a lookup using posn->peer_ref->name, and\n>   not do a lookup at all if it posn->peer_ref is not set (which\n>   should not occur as we are passed only wanted peer refs).\n\nThat's not true for \"git pull <url> <branch>\"; we do want the remote ref, \nbut it doesn't have a local peer. I think going straight to the refspec \ncommand is the right answer.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126829","messageId":"fabb9a1e0911041321i1ccec898r53ddafb9405c6331@mail.gmail.com","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911041601170.14365@iabervon.org","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T21:21:23Z","receivedAt":"2009-11-04T21:21:23Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Nov 4, 2009 at 22:20, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> That's not true for \"git pull <url> <branch>\"; we do want the remote ref,\n> but it doesn't have a local peer. I think going straight to the refspec\n> command is the right answer.\n\nCan you clarity what you mean with \"the refspec command\"?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126831","messageId":"alpine.LNX.2.00.0911041624401.14365@iabervon.org","threadId":"21484","inReplyTo":"fabb9a1e0911041321i1ccec898r53ddafb9405c6331@mail.gmail.com","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T21:30:07Z","receivedAt":"2009-11-04T21:30:07Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Wed, Nov 4, 2009 at 22:20, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > That's not true for \"git pull <url> <branch>\"; we do want the remote ref,\n> > but it doesn't have a local peer. I think going straight to the refspec\n> > command is the right answer.\n> \n> Can you clarity what you mean with \"the refspec command\"?\n\nWhatever it is that lets the helper tell the transport code where in the \nhelper's private namespace to look for refs. I'd been thinking the helper \nwould advertize the \"refspec\" capability, and the transport code would \ncall the \"refspec\" command in order to get the helper to report that; but \nthen I actually only said that the helper reports refspec, and not \nproposed a name for the command.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126833","messageId":"alpine.LNX.2.00.0911041621400.14365@iabervon.org","threadId":"21484","inReplyTo":"1257364098-1685-12-git-send-email-srabbelier@gmail.com","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T21:35:56Z","receivedAt":"2009-11-04T21:35:56Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n\n> The 'gitdir' capability is reported by the remote helper if it\n> requires the location of the .git directory. The location of the .git\n> directory can then be used by the helper to store status files even\n> when the current directory is not a git repository (such as is the\n> case when cloning).\n> \n> The location of the .git dir is specified as an absolute path.\n\nI thought we cd into the repository in the middle of clone somewhere, \nbefore running stuff. In any case, I think it would be good to have \nsomething like that, but I think maybe we should tell it where it can put \nits status files, rather than telling it where the .git dir is. It would \nalso be nice if this is the absolute path that gfi will base a relative \npath for the \"marks\" options on when importing.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126839","messageId":"fabb9a1e0911041406tce0956ai2ad3fe6cfbdc546d@mail.gmail.com","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911041621400.14365@iabervon.org","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T22:06:05Z","receivedAt":"2009-11-04T22:06:05Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Nov 4, 2009 at 22:35, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> I thought we cd into the repository in the middle of clone somewhere,\n> before running stuff.\n\nIt does, but not soon enough, that is, not before I needed it in my helper.\n\n> In any case, I think it would be good to have\n> something like that, but I think maybe we should tell it where it can put\n> its status files, rather than telling it where the .git dir is.\n\nYes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?\n\n> It would\n> also be nice if this is the absolute path that gfi will base a relative\n> path for the \"marks\" options on when importing.\n\nThe marks option has been dumped in favor of 'feature import-marks='\nand 'feature export-marks=' which will be in the reroll of\nsr/gfi-options.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126841","messageId":"alpine.LNX.2.00.0911041723010.14365@iabervon.org","threadId":"21484","inReplyTo":"fabb9a1e0911041406tce0956ai2ad3fe6cfbdc546d@mail.gmail.com","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T22:27:24Z","receivedAt":"2009-11-04T22:27:24Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Wed, Nov 4, 2009 at 22:35, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > I thought we cd into the repository in the middle of clone somewhere,\n> > before running stuff.\n> \n> It does, but not soon enough, that is, not before I needed it in my helper.\n> \n> > In any case, I think it would be good to have\n> > something like that, but I think maybe we should tell it where it can put\n> > its status files, rather than telling it where the .git dir is.\n> \n> Yes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?\n\nSeems reasonable to me, unless we make it .git/info/remote-<vcs>, and tell \nhelper authors to deal with having different imports not conflict with \neach other.\n\n> > It would\n> > also be nice if this is the absolute path that gfi will base a relative\n> > path for the \"marks\" options on when importing.\n> \n> The marks option has been dumped in favor of 'feature import-marks='\n> and 'feature export-marks=' which will be in the reroll of\n> sr/gfi-options.\n\nRight, but the values of those have to be paths, and I think they should \nbe relative paths, relative to the helper's state directory.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126843","messageId":"fabb9a1e0911041442k493c5d7cx493c2e5dac9d892c@mail.gmail.com","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911041723010.14365@iabervon.org","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T22:42:32Z","receivedAt":"2009-11-04T22:42:32Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Nov 4, 2009 at 23:27, Daniel Barkalow <barkalow@iabervon.org> wrote:\n>> Yes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?\n>\n> Seems reasonable to me, unless we make it .git/info/remote-<vcs>, and tell\n> helper authors to deal with having different imports not conflict with\n> each other.\n\nAh, yeah, the helper might want to store some global state as well, so\n'.git/info/remote-<vcs>' is probably best.\n\n>> The marks option has been dumped in favor of 'feature import-marks='\n>> and 'feature export-marks=' which will be in the reroll of\n>> sr/gfi-options.\n>\n> Right, but the values of those have to be paths, and I think they should\n> be relative paths, relative to the helper's state directory.\n\nHmmm, I don't remember exactly what we decided the paths should be\nreleative, pretty sure it was somewhere in .git/ though.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126848","messageId":"alpine.LNX.2.00.0911041748150.14365@iabervon.org","threadId":"21484","inReplyTo":"fabb9a1e0911041442k493c5d7cx493c2e5dac9d892c@mail.gmail.com","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T23:17:11Z","receivedAt":"2009-11-04T23:17:11Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Wed, Nov 4, 2009 at 23:27, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> >> The marks option has been dumped in favor of 'feature import-marks='\n> >> and 'feature export-marks=' which will be in the reroll of\n> >> sr/gfi-options.\n> >\n> > Right, but the values of those have to be paths, and I think they should\n> > be relative paths, relative to the helper's state directory.\n> \n> Hmmm, I don't remember exactly what we decided the paths should be\n> releative, pretty sure it was somewhere in .git/ though.\n\nWell, gfi is used with different native systems, each of which will \npresumably put it somewhere different.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126849","messageId":"fabb9a1e0911041518h9e3d07dneba3056848e98f3e@mail.gmail.com","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911041748150.14365@iabervon.org","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-04T23:18:52Z","receivedAt":"2009-11-04T23:18:52Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Nov 5, 2009 at 00:17, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> Well, gfi is used with different native systems, each of which will\n> presumably put it somewhere different.\n\nRight, but I meant for git itself :). I assume that you meant that\n'gitdir' (or 'infodir' , whatever) should return the same path,\nwhatever we decide on?q\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126850","messageId":"alpine.LNX.2.00.0911041819560.14365@iabervon.org","threadId":"21484","inReplyTo":"fabb9a1e0911041518h9e3d07dneba3056848e98f3e@mail.gmail.com","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-04T23:25:43Z","receivedAt":"2009-11-04T23:25:43Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Thu, 5 Nov 2009, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Thu, Nov 5, 2009 at 00:17, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > Well, gfi is used with different native systems, each of which will\n> > presumably put it somewhere different.\n> \n> Right, but I meant for git itself :). I assume that you meant that\n> 'gitdir' (or 'infodir' , whatever) should return the same path,\n> whatever we decide on?q\n\nYeah. I think the base that git uses wasn't decided on, although I may \nhave missed that part of the thread. In any case, I do think it should be \nthe directory passed to the helper.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126857","messageId":"7vd43xg7lf.fsf@alter.siamese.dyndns.org","threadId":"21484","inReplyTo":"fabb9a1e0911041406tce0956ai2ad3fe6cfbdc546d@mail.gmail.com","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-05T00:04:28Z","receivedAt":"2009-11-05T00:04:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sverre Rabbelier <srabbelier@gmail.com> writes:\n\n>> In any case, I think it would be good to have\n>> something like that, but I think maybe we should tell it where it can put\n>> its status files, rather than telling it where the .git dir is.\n>\n> Yes, that would probably be a good idea, .git/info/remote-<vcs>/<alias> perhaps?\n\nWhat do you mean by <alias> here?  Is it the <alias> in\n\n\t[remote \"alias\"]\n                url = hg::http://some.where/repo/sito/ry.hg\n\nIOW, can a user ever use the foreign interface directly from the command\nline, without ever defining such entries in .git/config, perhaps using\n\"git remote\"?\n"},{"id":"126858","messageId":"fabb9a1e0911041615o2a1afb6akdb120cdc94864e60@mail.gmail.com","threadId":"21484","inReplyTo":"7vd43xg7lf.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2 11/13] Allow helpers to request the path to the .git directory","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-05T00:15:55Z","receivedAt":"2009-11-05T00:15:55Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Nov 5, 2009 at 01:04, Junio C Hamano <gitster@pobox.com> wrote:\n> What do you mean by <alias> here?  Is it the <alias> in\n>\n>        [remote \"alias\"]\n>                url = hg::http://some.where/repo/sito/ry.hg\n\nYes, that one.\n\n> IOW, can a user ever use the foreign interface directly from the command\n> line, without ever defining such entries in .git/config, perhaps using\n> \"git remote\"?\n\nNo, my primary use case for remote helpers is currently 'git clone\nhg::https://soc.googlecode.com/hg/', and to have 'git fetch origin'\nJust Work (tm) from that clone. My secondary use case though, is to\nsupport 'git fetch hg:: https://soc.googlecode.com/hg/' just as well\nand have 'git log FETCH_HEAD' Just Work (tm) too. In that light\n.git/info/remote-<vcs>/ is probably a better idea, so that the helper\ncan use say '.git/info/remote-<vcs>/fetch/ for one-time fetches.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126867","messageId":"fabb9a1e0911041745x577f7e4rc678da4d7d559193@mail.gmail.com","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911041624401.14365@iabervon.org","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-05T01:45:46Z","receivedAt":"2009-11-05T01:45:46Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Wed, Nov 4, 2009 at 22:30, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n>> On Wed, Nov 4, 2009 at 22:20, Daniel Barkalow <barkalow@iabervon.org> wrote:\n>> > That's not true for \"git pull <url> <branch>\"; we do want the remote ref,\n>> > but it doesn't have a local peer.\n\nNo, I don't think that's right, when doing a fetch we want to store\nthe refs somewhere, sure, but not under 'refs/heads/<branch>', perhaps\n'refs/hg/fetch/<branch>', either way, the current code does not work.\n\n>> >I think going straight to the refspec\n>> > command is the right answer.\n>>\n>> Can you clarity what you mean with \"the refspec command\"?\n>\n> Whatever it is that lets the helper tell the transport code where in the\n> helper's private namespace to look for refs. I'd been thinking the helper\n> would advertize the \"refspec\" capability, and the transport code would\n> call the \"refspec\" command in order to get the helper to report that; but\n> then I actually only said that the helper reports refspec, and not\n> proposed a name for the command.\n\nCurrently I'm implementing so that it would work like this for the svn helper:\n\n$ echo capabilities | git remote-svn origin /path/to/hg/repo\nimport\nrefspec +refs/trunk:refs/svn/origin/trunk\nrefspec +refs/branches/*:refs/svn/origin/*\n\nThat way we can put the refspec in the config file at clone time.\n\nNow I've been browsing through the builtin-fetch code, and it looks\nlike the main problem is going to be to apply this refspec at all.\nI'll have a more extensive look tomorrow.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126876","messageId":"alpine.LNX.2.00.0911050016360.14365@iabervon.org","threadId":"21484","inReplyTo":"fabb9a1e0911041745x577f7e4rc678da4d7d559193@mail.gmail.com","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-05T05:34:38Z","receivedAt":"2009-11-05T05:34:38Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Thu, 5 Nov 2009, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Wed, Nov 4, 2009 at 22:30, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n> >> On Wed, Nov 4, 2009 at 22:20, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> >> > That's not true for \"git pull <url> <branch>\"; we do want the remote ref,\n> >> > but it doesn't have a local peer.\n> \n> No, I don't think that's right, when doing a fetch we want to store\n> the refs somewhere, sure, but not under 'refs/heads/<branch>', perhaps\n> 'refs/hg/fetch/<branch>', either way, the current code does not work.\n\nI think you've still got things backwards. From the point of view of \ntransport.c, refs/<vcs> is entirely opaque, and we never look at it. Those \naren't local peers. They're a way for the helper to communicate to \ntransport-helper.c. The user says: pull refs/heads/master of this hg \nrepo. Transport.c tries to fetch refs/heads/master and get the sha1 to \nwrite into FETCH_HEAD or wherever. Transport-helper.c says \"import \nrefs/heads/master\", and git-fast-import reads the resulting script and \nwrites some ref that the helper tells it to write. Then transport-helper.c \nfigures out where the ref was written, reads it, and updates the struct \nref representing the remote info. Then builtin-fetch looks at the struct \nref and writes it to the local repositories ref namespace or FETCH_HEAD.\n\n> >> >I think going straight to the refspec\n> >> > command is the right answer.\n> >>\n> >> Can you clarity what you mean with \"the refspec command\"?\n> >\n> > Whatever it is that lets the helper tell the transport code where in the\n> > helper's private namespace to look for refs. I'd been thinking the helper\n> > would advertize the \"refspec\" capability, and the transport code would\n> > call the \"refspec\" command in order to get the helper to report that; but\n> > then I actually only said that the helper reports refspec, and not\n> > proposed a name for the command.\n> \n> Currently I'm implementing so that it would work like this for the svn helper:\n> \n> $ echo capabilities | git remote-svn origin /path/to/hg/repo\n> import\n> refspec +refs/trunk:refs/svn/origin/trunk\n> refspec +refs/branches/*:refs/svn/origin/*\n> \n> That way we can put the refspec in the config file at clone time.\n> \n> Now I've been browsing through the builtin-fetch code, and it looks\n> like the main problem is going to be to apply this refspec at all.\n> I'll have a more extensive look tomorrow.\n\nThis is entirely not what I think we should have. The config file should \nsay refs/heads/*:refs/remotes/origin/* like it always does, because the \ntransport will list the refs like refs/heads/* and refs/tags/* and return \nthem like that.\n\nI'll see if I can write up an untested patch that does what I'm thinking \nof.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126881","messageId":"alpine.LNX.2.00.0911050145010.14365@iabervon.org","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911050016360.14365@iabervon.org","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-05T06:53:37Z","receivedAt":"2009-11-05T06:53:37Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Thu, 5 Nov 2009, Daniel Barkalow wrote:\n\n> On Thu, 5 Nov 2009, Sverre Rabbelier wrote:\n> \n> > Heya,\n> > \n> > On Wed, Nov 4, 2009 at 22:30, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > > On Wed, 4 Nov 2009, Sverre Rabbelier wrote:\n> > >> On Wed, Nov 4, 2009 at 22:20, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > >> > That's not true for \"git pull <url> <branch>\"; we do want the remote ref,\n> > >> > but it doesn't have a local peer.\n> > \n> > No, I don't think that's right, when doing a fetch we want to store\n> > the refs somewhere, sure, but not under 'refs/heads/<branch>', perhaps\n> > 'refs/hg/fetch/<branch>', either way, the current code does not work.\n> \n> I think you've still got things backwards. From the point of view of \n> transport.c, refs/<vcs> is entirely opaque, and we never look at it. Those \n> aren't local peers. They're a way for the helper to communicate to \n> transport-helper.c. The user says: pull refs/heads/master of this hg \n> repo. Transport.c tries to fetch refs/heads/master and get the sha1 to \n> write into FETCH_HEAD or wherever. Transport-helper.c says \"import \n> refs/heads/master\", and git-fast-import reads the resulting script and \n> writes some ref that the helper tells it to write. Then transport-helper.c \n> figures out where the ref was written, reads it, and updates the struct \n> ref representing the remote info. Then builtin-fetch looks at the struct \n> ref and writes it to the local repositories ref namespace or FETCH_HEAD.\n> \n> > >> >I think going straight to the refspec\n> > >> > command is the right answer.\n> > >>\n> > >> Can you clarity what you mean with \"the refspec command\"?\n> > >\n> > > Whatever it is that lets the helper tell the transport code where in the\n> > > helper's private namespace to look for refs. I'd been thinking the helper\n> > > would advertize the \"refspec\" capability, and the transport code would\n> > > call the \"refspec\" command in order to get the helper to report that; but\n> > > then I actually only said that the helper reports refspec, and not\n> > > proposed a name for the command.\n> > \n> > Currently I'm implementing so that it would work like this for the svn helper:\n> > \n> > $ echo capabilities | git remote-svn origin /path/to/hg/repo\n> > import\n> > refspec +refs/trunk:refs/svn/origin/trunk\n> > refspec +refs/branches/*:refs/svn/origin/*\n> > \n> > That way we can put the refspec in the config file at clone time.\n> > \n> > Now I've been browsing through the builtin-fetch code, and it looks\n> > like the main problem is going to be to apply this refspec at all.\n> > I'll have a more extensive look tomorrow.\n> \n> This is entirely not what I think we should have. The config file should \n> say refs/heads/*:refs/remotes/origin/* like it always does, because the \n> transport will list the refs like refs/heads/* and refs/tags/* and return \n> them like that.\n> \n> I'll see if I can write up an untested patch that does what I'm thinking \n> of.\n\nHere's a patch (on my original series, which doesn't seem to be in pu any \nmore, but should be floating around somewhere). Completely untested, \nexcept that it compiles. The idea is that the helper will say something \nlike:\n\nrefspec refs/heads/master:refs/svn/origin/trunk\nrefspec refs/heads/*:refs/svn/origin/branches/*\nrefspec refs/tags/*:refs/svn/origin/tags/*\n\nand transport-helper will use these patterns to figure out where to find \nthe correct value from the helper's private namespace when asked to fetch \nrefs/heads/topic.\n\n\t-Daniel\n\ncommit 483836f6411d2317f24c7594c557fb01133508b6\nAuthor: Daniel Barkalow <barkalow@iabervon.org>\nDate:   Thu Nov 5 01:39:02 2009 -0500\n\n    Allow helper to map private ref names into normal names\n    \n    This allows a helper to say that, when it handles \"import\n    refs/heads/topic\", the script it outputs will actually write to\n    refs/svn/origin/branches/topic; therefore, transport-helper should\n    read it from the latter location after git-fast-import completes.\n\ndiff --git a/remote.c b/remote.c\nindex f0441c4..58d1a61 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -790,6 +790,24 @@ static int match_name_with_pattern(const char *key, const char *name,\n \treturn ret;\n }\n \n+char *apply_refspecs(struct refspec *refspecs, int nr_refspec,\n+\t\t     const char *name)\n+{\n+\tint i;\n+\tchar *ret = NULL;\n+\tfor (i = 0; i < nr_refspec; i++) {\n+\t\tstruct refspec *refspec = refspecs + i;\n+\t\tif (refspec->pattern) {\n+\t\t\tif (match_name_with_pattern(refspec->src, name,\n+\t\t\t\t\t\t    refspec->dst, &ret))\n+\t\t\t\treturn ret;\n+\t\t} else if (!strcmp(refspec->src, name))\n+\t\t\treturn strdup(refspec->dst);\n+\t}\n+\treturn NULL;\n+\t\n+}\n+\n int remote_find_tracking(struct remote *remote, struct refspec *refspec)\n {\n \tint find_src = refspec->src == NULL;\ndiff --git a/remote.h b/remote.h\nindex ac0ce2f..c2f920b 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -91,6 +91,9 @@ void ref_remove_duplicates(struct ref *ref_map);\n int valid_fetch_refspec(const char *refspec);\n struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);\n \n+char *apply_refspecs(struct refspec *refspecs, int nr_refspec,\n+\t\t     const char *name);\n+\n int match_refs(struct ref *src, struct ref **dst,\n \t       int nr_refspec, const char **refspec, int all);\n \ndiff --git a/transport-helper.c b/transport-helper.c\nindex aa5ad3c..88573e7 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -5,6 +5,7 @@\n #include \"commit.h\"\n #include \"diff.h\"\n #include \"revision.h\"\n+#include \"remote.h\"\n \n struct helper_data\n {\n@@ -12,6 +13,9 @@ struct helper_data\n \tstruct child_process *helper;\n \tunsigned fetch : 1;\n \tunsigned import : 1;\n+\t/* These go from remote name (as in \"list\") to private name */\n+\tstruct refspec *refspecs;\n+\tint refspec_nr;\n };\n \n static struct child_process *get_helper(struct transport *transport)\n@@ -20,6 +24,9 @@ static struct child_process *get_helper(struct transport *transport)\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct child_process *helper;\n \tFILE *file;\n+\tconst char **refspecs = NULL;\n+\tint refspec_nr = 0;\n+\tint refspec_alloc = 0;\n \n \tif (data->helper)\n \t\treturn data->helper;\n@@ -53,6 +60,16 @@ static struct child_process *get_helper(struct transport *transport)\n \t\t\tdata->fetch = 1;\n \t\tif (!strcmp(buf.buf, \"import\"))\n \t\t\tdata->import = 1;\n+\t\tif (!prefixcmp(buf.buf, \"refspec \")) {\n+\t\t\tALLOC_GROW(refspecs,\n+\t\t\t\t   refspec_nr + 1,\n+\t\t\t\t   refspec_alloc);\n+\t\t\trefspecs[refspec_nr++] = strdup(buf.buf + strlen(\"refspec \"));\n+\t\t}\n+\t}\n+\tif (refspecs) {\n+\t\tdata->refspec_nr = refspec_nr;\n+\t\tdata->refspecs = parse_fetch_refspec(refspec_nr, refspecs);\n \t}\n \treturn data->helper;\n }\n@@ -121,6 +138,7 @@ static int fetch_with_import(struct transport *transport,\n {\n \tstruct child_process fastimport;\n \tstruct child_process *helper = get_helper(transport);\n+\tstruct helper_data *data = transport->data;\n \tint i;\n \tstruct ref *posn;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -141,10 +159,16 @@ static int fetch_with_import(struct transport *transport,\n \tfinish_command(&fastimport);\n \n \tfor (i = 0; i < nr_heads; i++) {\n+\t\tchar *private;\n \t\tposn = to_fetch[i];\n \t\tif (posn->status & REF_STATUS_UPTODATE)\n \t\t\tcontinue;\n-\t\tread_ref(posn->name, posn->old_sha1);\n+\t\tif (data->refspecs)\n+\t\t\tprivate = apply_refspecs(data->refspecs, data->refspec_nr, posn->name);\n+\t\telse\n+\t\t\tprivate = strdup(posn->name);\n+\t\tread_ref(private, posn->old_sha1);\n+\t\tfree(private);\n \t}\n \treturn 0;\n }\n"},{"id":"126886","messageId":"200911050855.01164.johan@herland.net","threadId":"21484","inReplyTo":"1257364098-1685-14-git-send-email-srabbelier@gmail.com","subject":"Re: [PATCH v2 13/13] Add Python support library for remote helpers","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2009-11-05T07:55:01Z","receivedAt":"2009-11-05T07:55:01Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Wednesday 04 November 2009, Sverre Rabbelier wrote:\n> This patch introduces parts of a Python package called\n> \"git_remote_helpers\" containing the building blocks for\n> python helper.\n> The actual remote helpers itself are NOT part of this patch.\n> \n> The patch includes the necessary Makefile additions to build and install\n> the git_remote_cvs Python package along with the rest of Git.\n\nThere are a few typos in the above. How about:\n\n  This patch introduces parts of a Python package called\n  \"git_remote_helpers\" containing the building blocks for\n  remote helpers written in Python.\n  No actual remote helpers are part of this patch, the patch\n  only includes the common basics needed to start writing such\n  helpers.\n\n> The patch includes the necessary Makefile additions to build and install\n> the git_remote_cvs Python package along with the rest of Git.\n\ns/git_remote_cvs/git_remote_helpers/\n\n> This patch is based on Johan Herland's git_remote_cvs patch and\n> has been improved by the following contributions:\n> - David Aguilar: Lots of Python coding style fixes\n> - David Aguilar: DESTDIR support in Makefile\n> \n> Cc: David Aguilar <davvid@gmail.com>\n> Cc: Johan Herland <johan@herland.net>\n> Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>\n> ---\n\nOtherwise it all looks good. Nice work!\n\n\n...Johan\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"126931","messageId":"fabb9a1e0911051551r2e13cfb9me0e668adb962f6bd@mail.gmail.com","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911050145010.14365@iabervon.org","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-05T23:51:42Z","receivedAt":"2009-11-05T23:51:42Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Nov 5, 2009 at 07:53, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> Here's a patch (on my original series, which doesn't seem to be in pu any\n> more, but should be floating around somewhere).\n\nWhy didn't you just base it against sr/vcs-helper which is currently\nin pu, now I have to try to find where your original series was, and\nrebase this patch against it. Assuming your main goal was to\nillustrate the direction you think we should go it would have been a\nlot easier that way.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126932","messageId":"fabb9a1e0911051614j63d602adycdc7adec7a388b25@mail.gmail.com","threadId":"21484","inReplyTo":"200911050855.01164.johan@herland.net","subject":"Re: [PATCH v2 13/13] Add Python support library for remote helpers","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-06T00:14:04Z","receivedAt":"2009-11-06T00:14:04Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Thu, Nov 5, 2009 at 08:55, Johan Herland <johan@herland.net> wrote:\n> There are a few typos in the above.\n\nThanks, fixed locally, will include this in the next version.\n\n> Otherwise it all looks good. Nice work!\n\nCool, thanks!\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126935","messageId":"alpine.LNX.2.00.0911051917100.14365@iabervon.org","threadId":"21484","inReplyTo":"fabb9a1e0911051551r2e13cfb9me0e668adb962f6bd@mail.gmail.com","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-06T00:19:29Z","receivedAt":"2009-11-06T00:19:29Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Fri, 6 Nov 2009, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Thu, Nov 5, 2009 at 07:53, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > Here's a patch (on my original series, which doesn't seem to be in pu any\n> > more, but should be floating around somewhere).\n> \n> Why didn't you just base it against sr/vcs-helper which is currently\n> in pu, now I have to try to find where your original series was, and\n> rebase this patch against it. Assuming your main goal was to\n> illustrate the direction you think we should go it would have been a\n> lot easier that way.\n\nI didn't understand the version of my patch that contains your changes, \nand I didn't know what was in it. I don't know why Junio squashed your \nchanges into my patch, particularly when I disagreed with those changes.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126937","messageId":"fabb9a1e0911051628v2ba15be2s9c3fb06879607cc0@mail.gmail.com","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911051917100.14365@iabervon.org","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-11-06T00:28:30Z","receivedAt":"2009-11-06T00:28:30Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Fri, Nov 6, 2009 at 01:19, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> I didn't understand the version of my patch that contains your changes,\n> and I didn't know what was in it.\n\nEither way, I managed to apply your patch, will send a new version of\nthe series tomorrow.\n\n> I don't know why Junio squashed your\n> changes into my patch, particularly when I disagreed with those changes.\n\nJunio didn't squash anything, it's just that pu still contains v4 of\nthe series, in which I had squashed my changes in.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"126939","messageId":"alpine.LNX.2.00.0911051929340.14365@iabervon.org","threadId":"21484","inReplyTo":"fabb9a1e0911051628v2ba15be2s9c3fb06879607cc0@mail.gmail.com","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-11-06T00:37:18Z","receivedAt":"2009-11-06T00:37:18Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Fri, 6 Nov 2009, Sverre Rabbelier wrote:\n\n> Heya,\n> \n> On Fri, Nov 6, 2009 at 01:19, Daniel Barkalow <barkalow@iabervon.org> wrote:\n> > I didn't understand the version of my patch that contains your changes,\n> > and I didn't know what was in it.\n> \n> Either way, I managed to apply your patch, will send a new version of\n> the series tomorrow.\n\nDoes it make sense now in what it's trying to do? (And does it turn out to \nwork?) I'm fairly certain it's the easiest way to make the remote appear \nmost natural to the rest of git, but I don't actually have code that wants \nto use it, so I wouldn't know if this just wouldn't work for hg or \nsomething.\n\n> > I don't know why Junio squashed your\n> > changes into my patch, particularly when I disagreed with those changes.\n> \n> Junio didn't squash anything, it's just that pu still contains v4 of\n> the series, in which I had squashed my changes in.\n\nOh, okay. You probably shouldn't squash un-acked changes into other \npeople's patches when taking over their series.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"},{"id":"126953","messageId":"7vd43w5gt4.fsf@alter.siamese.dyndns.org","threadId":"21484","inReplyTo":"alpine.LNX.2.00.0911051929340.14365@iabervon.org","subject":"Re: [PATCH v2 09/13] Honour the refspec when updating refs after import","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-11-06T06:05:27Z","receivedAt":"2009-11-06T06:05:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> On Fri, 6 Nov 2009, Sverre Rabbelier wrote:\n>\n>> > I don't know why Junio squashed your\n>> > changes into my patch, particularly when I disagreed with those changes.\n>> \n>> Junio didn't squash anything, it's just that pu still contains v4 of\n>> the series, in which I had squashed my changes in.\n>\n> Oh, okay. You probably shouldn't squash un-acked changes into other \n> people's patches when taking over their series.\n\nThanks for having this exchange.  You are right, and I should have more\nexplicitly explained what I was doing when I replaced two series (yours\nand Johan's cvs series) with Sverre's consolidated re-roll.\n"}]}