{"thread":{"id":"27756","subject":"[PATCHv9 0/4] ref namespaces","startedAt":"2011-07-05T17:54:05Z","lastAt":"2011-07-07T05:31:22Z","messageCount":7,"participants":["Josh Triplett","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"170835","messageId":"cover.1309888001.git.josh@joshtriplett.org","threadId":"27756","inReplyTo":null,"subject":"[PATCHv9 0/4] ref namespaces","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-07-05T17:54:05Z","receivedAt":"2011-07-05T17:54:05Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"This series adds support for dividing the refs of a single repository\ninto multiple namespaces, each of which can have its own branches, tags,\nand HEAD. Git can expose each namespace as an independent repository to\npull from and push to, while sharing the object store, and exposing all\nthe refs to operations such as git-gc.\n\nStoring multiple repositories as namespaces of a single repository\navoids storing duplicate copies of the same objects, such as when\nstoring multiple branches of the same source.  The alternates mechanism\nprovides similar support for avoiding duplicates, but alternates do not\nprevent duplication between new objects added to the repositories\nwithout ongoing maintenance, while namespaces do.\n\nThe first patch improves the prefix handling in the ref iteration\nfunctions, making it possible for us to implement\nfor_each_namespaced_ref later. The next two patches implement and then\nuse infrastructure for tracking the current namespace and iterating over\nthe refs in that namespace. The last patch adds general documentation\nfor namespaces, and specific references from the documentation on\nreceive-pack, upload-pack, http-backend, and git.\n\nv9: Fix a regression in alternatives handling, introduced in patch 3:\nthe ref filtering also filtered out the \".have\" refs added by\nreceive-pack to announce refs provided by alternates.  In the process of\nfixing this, also announce any refs outside the current namespace as\n\".have\" refs, to allow the client to use those for minimal transfer as\nwell.  Also, remove patch attribution in commit messages as requested by\nJunio C Hamano.  Finally, attempt to change the commit message style to\nmore closely match Git's preferred style; further feedback welcome on\nany other desired changes to the commit message style.\n\nJosh Triplett (4):\n  Fix prefix handling in ref iteration functions\n  ref namespaces: infrastructure\n  ref namespaces: Support remote repositories via upload-pack and\n    receive-pack\n  ref namespaces: documentation\n\n Documentation/Makefile                 |    2 +-\n Documentation/git-http-backend.txt     |    8 +++\n Documentation/git-receive-pack.txt     |    2 +-\n Documentation/git-upload-pack.txt      |    4 ++\n Documentation/git.txt                  |   13 +++++-\n Documentation/gitnamespaces.txt        |   75 ++++++++++++++++++++++++++++++++\n builtin/receive-pack.c                 |   37 +++++++++++++---\n cache.h                                |    3 +\n contrib/completion/git-completion.bash |    3 +-\n environment.c                          |   41 +++++++++++++++++\n git.c                                  |   18 +++++++-\n refs.c                                 |   33 ++++++++++++--\n refs.h                                 |    3 +\n upload-pack.c                          |   15 +++---\n 14 files changed, 233 insertions(+), 24 deletions(-)\n create mode 100644 Documentation/gitnamespaces.txt\n\n-- \n1.7.5.4\n"},{"id":"170836","messageId":"7abf27aee944796cdb23cf9703380fe726dbeecb.1309888001.git.josh@joshtriplett.org","threadId":"27756","inReplyTo":"cover.1309888001.git.josh@joshtriplett.org","subject":"[PATCHv9 1/4] Fix prefix handling in ref iteration functions","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-07-05T17:54:21Z","receivedAt":"2011-07-05T17:54:21Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"The do_for_each_ref iteration function accepts a prefix and a trim, and\nchecks for the prefix on each ref before passing in that ref; it also\nsupports trimming off part of the ref before passing it.  However,\ndo_for_each_ref used trim as the length of the prefix to check, ignoring\nthe actual length of the prefix.  Switch to using prefixcmp, checking\nthe entire length of the prefix string, to properly support a trim value\ndifferent than the length of the prefix.\n\nSeveral callers passed a prefix of \"refs/\" to filter out everything\noutside of refs/, but a trim of 0 to avoid trimming off the \"refs/\"; the\ntrim of 0 meant that the filter of \"refs/\" no longer applied.  Change\nthese callers to pass an empty prefix instead, to avoid changing the\nexisting behavior.  Various callers count on this lack of filtering,\nsuch as receive-pack which uses add_extra_ref to add alternates as refs\nnamed \".have\"; adding filtering would break that, causing\nt5501-fetch-push-alternates.sh to fail.  That lack of filtering doesn't\ncurrently have any other effect, since the loose ref functions can never\nsupply refs outside of \"refs/\", and packed-refs will not normally\ninclude such refs unless manually edited.\n\nSigned-off-by: Josh Triplett <josh@joshtriplett.org>\nSigned-off-by: Jamey Sharp <jamey@minilop.net>\n---\n refs.c |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 3a8789d..8bf8bb6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -584,7 +584,7 @@ int read_ref(const char *ref, unsigned char *sha1)\n static int do_one_ref(const char *base, each_ref_fn fn, int trim,\n \t\t      int flags, void *cb_data, struct ref_list *entry)\n {\n-\tif (strncmp(base, entry->name, trim))\n+\tif (prefixcmp(entry->name, base))\n \t\treturn 0;\n \n \tif (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {\n@@ -728,12 +728,12 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n \n int for_each_ref(each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(NULL, \"refs/\", fn, 0, 0, cb_data);\n+\treturn do_for_each_ref(NULL, \"\", fn, 0, 0, cb_data);\n }\n \n int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(submodule, \"refs/\", fn, 0, 0, cb_data);\n+\treturn do_for_each_ref(submodule, \"\", fn, 0, 0, cb_data);\n }\n \n int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)\n@@ -819,7 +819,7 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)\n \n int for_each_rawref(each_ref_fn fn, void *cb_data)\n {\n-\treturn do_for_each_ref(NULL, \"refs/\", fn, 0,\n+\treturn do_for_each_ref(NULL, \"\", fn, 0,\n \t\t\t       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);\n }\n \n-- \n1.7.5.4\n"},{"id":"170837","messageId":"4022201031d7e2ed11dd1a86e95762b6b468b10c.1309888001.git.josh@joshtriplett.org","threadId":"27756","inReplyTo":"cover.1309888001.git.josh@joshtriplett.org","subject":"[PATCHv9 2/4] ref namespaces: infrastructure","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-07-05T17:54:44Z","receivedAt":"2011-07-05T17:54:44Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Add support for dividing the refs of a single repository into multiple\nnamespaces, each of which can have its own branches, tags, and HEAD.\nGit can expose each namespace as an independent repository to pull from\nand push to, while sharing the object store, and exposing all the refs\nto operations such as git-gc.\n\nStoring multiple repositories as namespaces of a single repository\navoids storing duplicate copies of the same objects, such as when\nstoring multiple branches of the same source.  The alternates mechanism\nprovides similar support for avoiding duplicates, but alternates do not\nprevent duplication between new objects added to the repositories\nwithout ongoing maintenance, while namespaces do.\n\nTo specify a namespace, set the GIT_NAMESPACE environment variable to\nthe namespace.  For each ref namespace, git stores the corresponding\nrefs in a directory under refs/namespaces/.  For example,\nGIT_NAMESPACE=foo will store refs under refs/namespaces/foo/.  You can\nalso specify namespaces via the --namespace option to git.\n\nNote that namespaces which include a / will expand to a hierarchy of\nnamespaces; for example, GIT_NAMESPACE=foo/bar will store refs under\nrefs/namespaces/foo/refs/namespaces/bar/.  This makes paths in\nGIT_NAMESPACE behave hierarchically, so that cloning with\nGIT_NAMESPACE=foo/bar produces the same result as cloning with\nGIT_NAMESPACE=foo and cloning from that repo with GIT_NAMESPACE=bar.  It\nalso avoids ambiguity with strange namespace paths such as\nfoo/refs/heads/, which could otherwise generate directory/file conflicts\nwithin the refs directory.\n\nAdd the infrastructure for ref namespaces: handle the GIT_NAMESPACE\nenvironment variable and --namespace option, and support iterating over\nrefs in a namespace.\n\nSigned-off-by: Josh Triplett <josh@joshtriplett.org>\nSigned-off-by: Jamey Sharp <jamey@minilop.net>\n---\n cache.h                                |    3 ++\n contrib/completion/git-completion.bash |    1 +\n environment.c                          |   41 ++++++++++++++++++++++++++++++++\n git.c                                  |   18 ++++++++++++-\n refs.c                                 |   25 +++++++++++++++++++\n refs.h                                 |    3 ++\n 6 files changed, 89 insertions(+), 2 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex bc9e5eb..dc29ef3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -380,6 +380,7 @@ static inline enum object_type object_type(unsigned int mode)\n }\n \n #define GIT_DIR_ENVIRONMENT \"GIT_DIR\"\n+#define GIT_NAMESPACE_ENVIRONMENT \"GIT_NAMESPACE\"\n #define GIT_WORK_TREE_ENVIRONMENT \"GIT_WORK_TREE\"\n #define DEFAULT_GIT_DIR_ENVIRONMENT \".git\"\n #define DB_ENVIRONMENT \"GIT_OBJECT_DIRECTORY\"\n@@ -420,6 +421,8 @@ extern char *get_object_directory(void);\n extern char *get_index_file(void);\n extern char *get_graft_file(void);\n extern int set_git_dir(const char *path);\n+extern const char *get_git_namespace(void);\n+extern const char *strip_namespace(const char *namespaced_ref);\n extern const char *get_git_work_tree(void);\n extern const char *read_gitfile_gently(const char *path);\n extern void set_git_work_tree(const char *tree);\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 5a83090..e0b936d 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2640,6 +2640,7 @@ _git ()\n \t\t\t--exec-path\n \t\t\t--html-path\n \t\t\t--work-tree=\n+\t\t\t--namespace=\n \t\t\t--help\n \t\t\t\"\n \t\t\t;;\ndiff --git a/environment.c b/environment.c\nindex 94d58fd..aad274b 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -8,6 +8,7 @@\n  * are.\n  */\n #include \"cache.h\"\n+#include \"refs.h\"\n \n char git_default_email[MAX_GITNAME];\n char git_default_name[MAX_GITNAME];\n@@ -65,6 +66,9 @@ int core_preload_index = 0;\n char *git_work_tree_cfg;\n static char *work_tree;\n \n+static const char *namespace;\n+static size_t namespace_len;\n+\n static const char *git_dir;\n static char *git_object_dir, *git_index_file, *git_graft_file;\n \n@@ -86,6 +90,27 @@ const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = {\n \tNULL\n };\n \n+static char *expand_namespace(const char *raw_namespace)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstruct strbuf **components, **c;\n+\n+\tif (!raw_namespace || !*raw_namespace)\n+\t\treturn xstrdup(\"\");\n+\n+\tstrbuf_addstr(&buf, raw_namespace);\n+\tcomponents = strbuf_split(&buf, '/');\n+\tstrbuf_reset(&buf);\n+\tfor (c = components; *c; c++)\n+\t\tif (strcmp((*c)->buf, \"/\") != 0)\n+\t\t\tstrbuf_addf(&buf, \"refs/namespaces/%s\", (*c)->buf);\n+\tstrbuf_list_free(components);\n+\tif (check_ref_format(buf.buf) != CHECK_REF_FORMAT_OK)\n+\t\tdie(\"bad git namespace path \\\"%s\\\"\", raw_namespace);\n+\tstrbuf_addch(&buf, '/');\n+\treturn strbuf_detach(&buf, NULL);\n+}\n+\n static void setup_git_env(void)\n {\n \tgit_dir = getenv(GIT_DIR_ENVIRONMENT);\n@@ -111,6 +136,8 @@ static void setup_git_env(void)\n \t\tgit_graft_file = git_pathdup(\"info/grafts\");\n \tif (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))\n \t\tread_replace_refs = 0;\n+\tnamespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));\n+\tnamespace_len = strlen(namespace);\n }\n \n int is_bare_repository(void)\n@@ -131,6 +158,20 @@ const char *get_git_dir(void)\n \treturn git_dir;\n }\n \n+const char *get_git_namespace(void)\n+{\n+\tif (!namespace)\n+\t\tsetup_git_env();\n+\treturn namespace;\n+}\n+\n+const char *strip_namespace(const char *namespaced_ref)\n+{\n+\tif (prefixcmp(namespaced_ref, get_git_namespace()) != 0)\n+\t\treturn NULL;\n+\treturn namespaced_ref + namespace_len;\n+}\n+\n static int git_work_tree_initialized;\n \n /*\ndiff --git a/git.c b/git.c\nindex 8828c18..304522b 100644\n--- a/git.c\n+++ b/git.c\n@@ -7,8 +7,8 @@\n \n const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\\n\"\n-\t\"           [-p|--paginate|--no-pager] [--no-replace-objects]\\n\"\n-\t\"           [--bare] [--git-dir=<path>] [--work-tree=<path>]\\n\"\n+\t\"           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\\n\"\n+\t\"           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\\n\"\n \t\"           [-c name=value] [--help]\\n\"\n \t\"           <command> [<args>]\";\n \n@@ -126,6 +126,20 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)\n \t\t\tsetenv(GIT_DIR_ENVIRONMENT, cmd + 10, 1);\n \t\t\tif (envchanged)\n \t\t\t\t*envchanged = 1;\n+\t\t} else if (!strcmp(cmd, \"--namespace\")) {\n+\t\t\tif (*argc < 2) {\n+\t\t\t\tfprintf(stderr, \"No namespace given for --namespace.\\n\" );\n+\t\t\t\tusage(git_usage_string);\n+\t\t\t}\n+\t\t\tsetenv(GIT_NAMESPACE_ENVIRONMENT, (*argv)[1], 1);\n+\t\t\tif (envchanged)\n+\t\t\t\t*envchanged = 1;\n+\t\t\t(*argv)++;\n+\t\t\t(*argc)--;\n+\t\t} else if (!prefixcmp(cmd, \"--namespace=\")) {\n+\t\t\tsetenv(GIT_NAMESPACE_ENVIRONMENT, cmd + 12, 1);\n+\t\t\tif (envchanged)\n+\t\t\t\t*envchanged = 1;\n \t\t} else if (!strcmp(cmd, \"--work-tree\")) {\n \t\t\tif (*argc < 2) {\n \t\t\t\tfprintf(stderr, \"No directory given for --work-tree.\\n\" );\ndiff --git a/refs.c b/refs.c\nindex 8bf8bb6..6f313a9 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -782,6 +782,31 @@ int for_each_replace_ref(each_ref_fn fn, void *cb_data)\n \treturn do_for_each_ref(NULL, \"refs/replace/\", fn, 13, 0, cb_data);\n }\n \n+int head_ref_namespaced(each_ref_fn fn, void *cb_data)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint ret = 0;\n+\tunsigned char sha1[20];\n+\tint flag;\n+\n+\tstrbuf_addf(&buf, \"%sHEAD\", get_git_namespace());\n+\tif (resolve_ref(buf.buf, sha1, 1, &flag))\n+\t\tret = fn(buf.buf, sha1, flag, cb_data);\n+\tstrbuf_release(&buf);\n+\n+\treturn ret;\n+}\n+\n+int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tint ret;\n+\tstrbuf_addf(&buf, \"%srefs/\", get_git_namespace());\n+\tret = do_for_each_ref(NULL, buf.buf, fn, 0, 0, cb_data);\n+\tstrbuf_release(&buf);\n+\treturn ret;\n+}\n+\n int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,\n \tconst char *prefix, void *cb_data)\n {\ndiff --git a/refs.h b/refs.h\nindex 5de06e5..dfb086e 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -36,6 +36,9 @@ extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, voi\n extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n \n+extern int head_ref_namespaced(each_ref_fn fn, void *cb_data);\n+extern int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);\n+\n static inline const char *has_glob_specials(const char *pattern)\n {\n \treturn strpbrk(pattern, \"?*[\");\n-- \n1.7.5.4\n"},{"id":"170839","messageId":"fff78c90d7f9deb0a8294fe3158ab0285e1610ff.1309888001.git.josh@joshtriplett.org","threadId":"27756","inReplyTo":"cover.1309888001.git.josh@joshtriplett.org","subject":"[PATCHv9 3/4] ref namespaces: Support remote repositories via upload-pack and receive-pack","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-07-05T17:55:00Z","receivedAt":"2011-07-05T17:55:00Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Change upload-pack and receive-pack to use the namespace-prefixed refs\nwhen working with the repository, and use the unprefixed refs when\ntalking to the client, maintaining the masquerade.  This allows\nclone, pull, fetch, and push to work with a suitably configured\nGIT_NAMESPACE.\n\nWith appropriate configuration, this also allows http-backend to expose\nnamespaces as multiple repositories with different paths.  This only\nrequires setting GIT_NAMESPACE, which http-backend passes through to\nupload-pack and receive-pack.\n\nSigned-off-by: Josh Triplett <josh@joshtriplett.org>\nSigned-off-by: Jamey Sharp <jamey@minilop.net>\n---\n builtin/receive-pack.c |   37 +++++++++++++++++++++++++++++++------\n upload-pack.c          |   15 ++++++++-------\n 2 files changed, 39 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex e1a687a..2d36378 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -120,9 +120,17 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void\n \treturn 0;\n }\n \n+static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n+{\n+\tpath = strip_namespace(path);\n+\tif (!path)\n+\t\tpath = \".have\";\n+\treturn show_ref(path, sha1, flag, cb_data);\n+}\n+\n static void write_head_info(void)\n {\n-\tfor_each_ref(show_ref, NULL);\n+\tfor_each_ref(show_ref_cb, NULL);\n \tif (!sent_capabilities)\n \t\tshow_ref(\"capabilities^{}\", null_sha1, 0, NULL);\n \n@@ -333,6 +341,8 @@ static void refuse_unconfigured_deny_delete_current(void)\n static const char *update(struct command *cmd)\n {\n \tconst char *name = cmd->ref_name;\n+\tstruct strbuf namespaced_name_buf = STRBUF_INIT;\n+\tconst char *namespaced_name;\n \tunsigned char *old_sha1 = cmd->old_sha1;\n \tunsigned char *new_sha1 = cmd->new_sha1;\n \tstruct ref_lock *lock;\n@@ -343,7 +353,10 @@ static const char *update(struct command *cmd)\n \t\treturn \"funny refname\";\n \t}\n \n-\tif (is_ref_checked_out(name)) {\n+\tstrbuf_addf(&namespaced_name_buf, \"%s%s\", get_git_namespace(), name);\n+\tnamespaced_name = strbuf_detach(&namespaced_name_buf, NULL);\n+\n+\tif (is_ref_checked_out(namespaced_name)) {\n \t\tswitch (deny_current_branch) {\n \t\tcase DENY_IGNORE:\n \t\t\tbreak;\n@@ -371,7 +384,7 @@ static const char *update(struct command *cmd)\n \t\t\treturn \"deletion prohibited\";\n \t\t}\n \n-\t\tif (!strcmp(name, head_name)) {\n+\t\tif (!strcmp(namespaced_name, head_name)) {\n \t\t\tswitch (deny_delete_current) {\n \t\t\tcase DENY_IGNORE:\n \t\t\t\tbreak;\n@@ -427,14 +440,14 @@ static const char *update(struct command *cmd)\n \t\t\trp_warning(\"Allowing deletion of corrupt ref.\");\n \t\t\told_sha1 = NULL;\n \t\t}\n-\t\tif (delete_ref(name, old_sha1, 0)) {\n+\t\tif (delete_ref(namespaced_name, old_sha1, 0)) {\n \t\t\trp_error(\"failed to delete %s\", name);\n \t\t\treturn \"failed to delete\";\n \t\t}\n \t\treturn NULL; /* good */\n \t}\n \telse {\n-\t\tlock = lock_any_ref_for_update(name, old_sha1, 0);\n+\t\tlock = lock_any_ref_for_update(namespaced_name, old_sha1, 0);\n \t\tif (!lock) {\n \t\t\trp_error(\"failed to lock %s\", name);\n \t\t\treturn \"failed to lock\";\n@@ -491,17 +504,29 @@ static void run_update_post_hook(struct command *commands)\n \n static void check_aliased_update(struct command *cmd, struct string_list *list)\n {\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tconst char *dst_name;\n \tstruct string_list_item *item;\n \tstruct command *dst_cmd;\n \tunsigned char sha1[20];\n \tchar cmd_oldh[41], cmd_newh[41], dst_oldh[41], dst_newh[41];\n \tint flag;\n \n-\tconst char *dst_name = resolve_ref(cmd->ref_name, sha1, 0, &flag);\n+\tstrbuf_addf(&buf, \"%s%s\", get_git_namespace(), cmd->ref_name);\n+\tdst_name = resolve_ref(buf.buf, sha1, 0, &flag);\n+\tstrbuf_release(&buf);\n \n \tif (!(flag & REF_ISSYMREF))\n \t\treturn;\n \n+\tdst_name = strip_namespace(dst_name);\n+\tif (!dst_name) {\n+\t\trp_error(\"refusing update to broken symref '%s'\", cmd->ref_name);\n+\t\tcmd->skip_update = 1;\n+\t\tcmd->error_string = \"broken symref\";\n+\t\treturn;\n+\t}\n+\n \tif ((item = string_list_lookup(list, dst_name)) == NULL)\n \t\treturn;\n \ndiff --git a/upload-pack.c b/upload-pack.c\nindex ce5cbbe..267e5b1 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -641,16 +641,17 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \t\t\" side-band-64k ofs-delta shallow no-progress\"\n \t\t\" include-tag multi_ack_detailed\";\n \tstruct object *o = parse_object(sha1);\n+\tconst char *refname_nons = strip_namespace(refname);\n \n \tif (!o)\n \t\tdie(\"git upload-pack: cannot find object %s:\", sha1_to_hex(sha1));\n \n \tif (capabilities)\n-\t\tpacket_write(1, \"%s %s%c%s%s\\n\", sha1_to_hex(sha1), refname,\n+\t\tpacket_write(1, \"%s %s%c%s%s\\n\", sha1_to_hex(sha1), refname_nons,\n \t\t\t     0, capabilities,\n \t\t\t     stateless_rpc ? \" no-done\" : \"\");\n \telse\n-\t\tpacket_write(1, \"%s %s\\n\", sha1_to_hex(sha1), refname);\n+\t\tpacket_write(1, \"%s %s\\n\", sha1_to_hex(sha1), refname_nons);\n \tcapabilities = NULL;\n \tif (!(o->flags & OUR_REF)) {\n \t\to->flags |= OUR_REF;\n@@ -659,7 +660,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \tif (o->type == OBJ_TAG) {\n \t\to = deref_tag(o, refname, 0);\n \t\tif (o)\n-\t\t\tpacket_write(1, \"%s %s^{}\\n\", sha1_to_hex(o->sha1), refname);\n+\t\t\tpacket_write(1, \"%s %s^{}\\n\", sha1_to_hex(o->sha1), refname_nons);\n \t}\n \treturn 0;\n }\n@@ -680,12 +681,12 @@ static void upload_pack(void)\n {\n \tif (advertise_refs || !stateless_rpc) {\n \t\treset_timeout();\n-\t\thead_ref(send_ref, NULL);\n-\t\tfor_each_ref(send_ref, NULL);\n+\t\thead_ref_namespaced(send_ref, NULL);\n+\t\tfor_each_namespaced_ref(send_ref, NULL);\n \t\tpacket_flush(1);\n \t} else {\n-\t\thead_ref(mark_our_ref, NULL);\n-\t\tfor_each_ref(mark_our_ref, NULL);\n+\t\thead_ref_namespaced(mark_our_ref, NULL);\n+\t\tfor_each_namespaced_ref(mark_our_ref, NULL);\n \t}\n \tif (advertise_refs)\n \t\treturn;\n-- \n1.7.5.4\n"},{"id":"170838","messageId":"3d5b8135858458dd69c813ec5f3d5272ea66153d.1309888001.git.josh@joshtriplett.org","threadId":"27756","inReplyTo":"cover.1309888001.git.josh@joshtriplett.org","subject":"[PATCHv9 4/4] ref namespaces: documentation","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-07-05T17:55:26Z","receivedAt":"2011-07-05T17:55:26Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"Document the namespace mechanism in a new gitnamespaces(7) page.\nReference it from receive-pack and upload-pack.\n\nDocument the new --namespace option and GIT_NAMESPACE environment\nvariable in git(1), and reference gitnamespaces(7).\n\nAdd a sample Apache configuration to http-backend(1) to support\nnamespaced repositories, and reference gitnamespaces(7).\n\nSigned-off-by: Josh Triplett <josh@joshtriplett.org>\nSigned-off-by: Jamey Sharp <jamey@minilop.net>\n---\n Documentation/Makefile                 |    2 +-\n Documentation/git-http-backend.txt     |    8 +++\n Documentation/git-receive-pack.txt     |    2 +-\n Documentation/git-upload-pack.txt      |    4 ++\n Documentation/git.txt                  |   13 +++++-\n Documentation/gitnamespaces.txt        |   75 ++++++++++++++++++++++++++++++++\n contrib/completion/git-completion.bash |    2 +-\n 7 files changed, 101 insertions(+), 5 deletions(-)\n create mode 100644 Documentation/gitnamespaces.txt\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex 36989b7..2004fbe 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -6,7 +6,7 @@ MAN5_TXT=gitattributes.txt gitignore.txt gitmodules.txt githooks.txt \\\n \tgitrepository-layout.txt\n MAN7_TXT=gitcli.txt gittutorial.txt gittutorial-2.txt \\\n \tgitcvs-migration.txt gitcore-tutorial.txt gitglossary.txt \\\n-\tgitdiffcore.txt gitrevisions.txt gitworkflows.txt\n+\tgitdiffcore.txt gitnamespaces.txt gitrevisions.txt gitworkflows.txt\n \n MAN_TXT = $(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT)\n MAN_XML=$(patsubst %.txt,%.xml,$(MAN_TXT))\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex 277d9e1..f4e0741 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -119,6 +119,14 @@ ScriptAliasMatch \\\n \n ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/\n ----------------------------------------------------------------\n++\n+To serve multiple repositories from different linkgit:gitnamespaces[7] in a\n+single repository:\n++\n+----------------------------------------------------------------\n+SetEnvIf Request_URI \"^/git/([^/]*)\" GIT_NAMESPACE=$1\n+ScriptAliasMatch ^/git/[^/]*(.*) /usr/libexec/git-core/git-http-backend/storage.git$1\n+----------------------------------------------------------------\n \n Accelerated static Apache 2.x::\n \tSimilar to the above, but Apache can be used to return static\ndiff --git a/Documentation/git-receive-pack.txt b/Documentation/git-receive-pack.txt\nindex f34e0ae..3534ba0 100644\n--- a/Documentation/git-receive-pack.txt\n+++ b/Documentation/git-receive-pack.txt\n@@ -149,7 +149,7 @@ if the repository is packed and is served via a dumb transport.\n \n SEE ALSO\n --------\n-linkgit:git-send-pack[1]\n+linkgit:git-send-pack[1], linkgit:gitnamespaces[7]\n \n GIT\n ---\ndiff --git a/Documentation/git-upload-pack.txt b/Documentation/git-upload-pack.txt\nindex 4c0ca9d..61a9a04 100644\n--- a/Documentation/git-upload-pack.txt\n+++ b/Documentation/git-upload-pack.txt\n@@ -33,6 +33,10 @@ OPTIONS\n <directory>::\n \tThe repository to sync from.\n \n+SEE ALSO\n+--------\n+linkgit:gitnamespaces[7]\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 3c7a832..81cb1c6 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -10,8 +10,8 @@ SYNOPSIS\n --------\n [verse]\n 'git' [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n-    [-p|--paginate|--no-pager] [--no-replace-objects]\n-    [--bare] [--git-dir=<path>] [--work-tree=<path>]\n+    [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n+    [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n     [-c <name>=<value>]\n     [--help] <command> [<args>]\n \n@@ -330,6 +330,11 @@ help ...`.\n \tvariable (see core.worktree in linkgit:git-config[1] for a\n \tmore detailed discussion).\n \n+--namespace=<path>::\n+\tSet the git namespace.  See linkgit:gitnamespaces[7] for more\n+\tdetails.  Equivalent to setting the `GIT_NAMESPACE` environment\n+\tvariable.\n+\n --bare::\n \tTreat the repository as a bare repository.  If GIT_DIR\n \tenvironment is not set, it is set to the current working\n@@ -594,6 +599,10 @@ git so take care if using Cogito etc.\n \tThis can also be controlled by the '--work-tree' command line\n \toption and the core.worktree configuration variable.\n \n+'GIT_NAMESPACE'::\n+\tSet the git namespace; see linkgit:gitnamespaces[7] for details.\n+\tThe '--namespace' command-line option also sets this value.\n+\n 'GIT_CEILING_DIRECTORIES'::\n \tThis should be a colon-separated list of absolute paths.\n \tIf set, it is a list of directories that git should not chdir\ndiff --git a/Documentation/gitnamespaces.txt b/Documentation/gitnamespaces.txt\nnew file mode 100644\nindex 0000000..ed8924e\n--- /dev/null\n+++ b/Documentation/gitnamespaces.txt\n@@ -0,0 +1,75 @@\n+gitnamespaces(7)\n+================\n+\n+NAME\n+----\n+gitnamespaces - Git namespaces\n+\n+DESCRIPTION\n+-----------\n+\n+Git supports dividing the refs of a single repository into multiple\n+namespaces, each of which has its own branches, tags, and HEAD.  Git can\n+expose each namespace as an independent repository to pull from and push\n+to, while sharing the object store, and exposing all the refs to\n+operations such as linkgit:git-gc[1].\n+\n+Storing multiple repositories as namespaces of a single repository\n+avoids storing duplicate copies of the same objects, such as when\n+storing multiple branches of the same source.  The alternates mechanism\n+provides similar support for avoiding duplicates, but alternates do not\n+prevent duplication between new objects added to the repositories\n+without ongoing maintenance, while namespaces do.\n+\n+To specify a namespace, set the `GIT_NAMESPACE` environment variable to\n+the namespace.  For each ref namespace, git stores the corresponding\n+refs in a directory under `refs/namespaces/`.  For example,\n+`GIT_NAMESPACE=foo` will store refs under `refs/namespaces/foo/`.  You\n+can also specify namespaces via the `--namespace` option to\n+linkgit:git[1].\n+\n+Note that namespaces which include a `/` will expand to a hierarchy of\n+namespaces; for example, `GIT_NAMESPACE=foo/bar` will store refs under\n+`refs/namespaces/foo/refs/namespaces/bar/`.  This makes paths in\n+`GIT_NAMESPACE` behave hierarchically, so that cloning with\n+`GIT_NAMESPACE=foo/bar` produces the same result as cloning with\n+`GIT_NAMESPACE=foo` and cloning from that repo with `GIT_NAMESPACE=bar`.  It\n+also avoids ambiguity with strange namespace paths such as `foo/refs/heads/`,\n+which could otherwise generate directory/file conflicts within the `refs`\n+directory.\n+\n+linkgit:git-upload-pack[1] and linkgit:git-receive-pack[1] rewrite the\n+names of refs as specified by `GIT_NAMESPACE`.  git-upload-pack and\n+git-receive-pack will ignore all references outside the specified\n+namespace.\n+\n+The smart HTTP server, linkgit:git-http-backend[1], will pass\n+GIT_NAMESPACE through to the backend programs; see\n+linkgit:git-http-backend[1] for sample configuration to expose\n+repository namespaces as repositories.\n+\n+For a simple local test, you can use linkgit:git-remote-ext[1]:\n+\n+----------\n+git clone ext::'git --namespace=foo %s /tmp/prefixed.git'\n+----------\n+\n+SECURITY\n+--------\n+\n+Anyone with access to any namespace within a repository can potentially\n+access objects from any other namespace stored in the same repository.\n+You can't directly say \"give me object ABCD\" if you don't have a ref to\n+it, but you can do some other sneaky things like:\n+\n+. Claiming to push ABCD, at which point the server will optimize out the\n+  need for you to actually send it. Now you have a ref to ABCD and can\n+  fetch it (claiming not to have it, of course).\n+\n+. Requesting other refs, claiming that you have ABCD, at which point the\n+  server may generate deltas against ABCD.\n+\n+None of this causes a problem if you only host public repositories, or\n+if everyone who may read one namespace may also read everything in every\n+other namespace (for instance, if everyone in an organization has read\n+permission to every repository).\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex e0b936d..8648a36 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1469,7 +1469,7 @@ _git_help ()\n \t__gitcomp \"$__git_all_commands $(__git_aliases)\n \t\tattributes cli core-tutorial cvs-migration\n \t\tdiffcore gitk glossary hooks ignore modules\n-\t\trepository-layout tutorial tutorial-2\n+\t\tnamespaces repository-layout tutorial tutorial-2\n \t\tworkflows\n \t\t\"\n }\n-- \n1.7.5.4\n"},{"id":"170940","messageId":"7vy60bkzmf.fsf@alter.siamese.dyndns.org","threadId":"27756","inReplyTo":"fff78c90d7f9deb0a8294fe3158ab0285e1610ff.1309888001.git.josh@joshtriplett.org","subject":"Re: [PATCHv9 3/4] ref namespaces: Support remote repositories via upload-pack and receive-pack","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-07-06T18:55:36Z","receivedAt":"2011-07-06T18:55:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Josh Triplett <josh@joshtriplett.org> writes:\n\n> Change upload-pack and receive-pack to use the namespace-prefixed refs\n> when working with the repository, and use the unprefixed refs when\n> talking to the client, maintaining the masquerade.  This allows\n> clone, pull, fetch, and push to work with a suitably configured\n> GIT_NAMESPACE.\n>\n> With appropriate configuration, this also allows http-backend to expose\n> namespaces as multiple repositories with different paths.  This only\n> requires setting GIT_NAMESPACE, which http-backend passes through to\n> upload-pack and receive-pack.\n>\n> Signed-off-by: Josh Triplett <josh@joshtriplett.org>\n> Signed-off-by: Jamey Sharp <jamey@minilop.net>\n> ---\n>  builtin/receive-pack.c |   37 +++++++++++++++++++++++++++++++------\n>  upload-pack.c          |   15 ++++++++-------\n>  2 files changed, 39 insertions(+), 13 deletions(-)\n>\n> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\n> index e1a687a..2d36378 100644\n> --- a/builtin/receive-pack.c\n> +++ b/builtin/receive-pack.c\n> @@ -120,9 +120,17 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void\n>  \treturn 0;\n>  }\n>  \n> +static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n> +{\n> +\tpath = strip_namespace(path);\n> +\tif (!path)\n> +\t\tpath = \".have\";\n> +\treturn show_ref(path, sha1, flag, cb_data);\n\nAt the first glance, this felt somewhat unoptimal as it forbids us from\nstuffing fake \"ref\" entries other than \".have\" via the add_extra_ref()\ninterface, and I wondered if it would make sense to do something like this\ninstead:\n\n\tconst char *ns_path = strip_namespace(path);\n        if (!ns_path)\n        \tns_path = path;\n\treturn show_ref(ns_path, sha1, flag, cb_data);\n\nBut that is flawed, and I think your patch does the right thing.  The\njustification is a bit subtle [*1*] and I think it needs to be explained\nin a comment around here, not just in the 0/4 cover letter message.\n\nThanks.\n\n[Footnote]\n\n*1* If this callback was called for a genuine \".have\" that is there only\nto tell the other side that the history leading to the commit needs not to\nbe sent to us, we want to send it as \".have\". On the other hand, if this\ncallback were called for a real ref that is outside the current scope, we\nwant to tell the other side that it is not something they can update but\nwe still also want to tell the other side that the history leading to the\ncommit needs not to be sent to us.  It is the _right_ thing to do to\ndemotes refs outside the current scope as something that the pusher can\nuse to reduce network traffic yet something that the cannot update by\nusing the existing \".have\" mechanism.\n"},{"id":"170963","messageId":"20110707053122.GA1798@leaf","threadId":"27756","inReplyTo":"7vy60bkzmf.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCHv9 3/4] ref namespaces: Support remote repositories via upload-pack and receive-pack","fromName":"Josh Triplett","fromEmail":"josh@joshtriplett.org","sentAt":"2011-07-07T05:31:22Z","receivedAt":"2011-07-07T05:31:22Z","isPatch":false,"sender":{"key":"josh@joshtriplett.org","avatar":"https://avatars.githubusercontent.com/u/162737?v=4"},"body":"On Wed, Jul 06, 2011 at 11:55:36AM -0700, Junio C Hamano wrote:\n> Josh Triplett <josh@joshtriplett.org> writes:\n> \n> > Change upload-pack and receive-pack to use the namespace-prefixed refs\n> > when working with the repository, and use the unprefixed refs when\n> > talking to the client, maintaining the masquerade.  This allows\n> > clone, pull, fetch, and push to work with a suitably configured\n> > GIT_NAMESPACE.\n> >\n> > With appropriate configuration, this also allows http-backend to expose\n> > namespaces as multiple repositories with different paths.  This only\n> > requires setting GIT_NAMESPACE, which http-backend passes through to\n> > upload-pack and receive-pack.\n> >\n> > Signed-off-by: Josh Triplett <josh@joshtriplett.org>\n> > Signed-off-by: Jamey Sharp <jamey@minilop.net>\n> > ---\n> >  builtin/receive-pack.c |   37 +++++++++++++++++++++++++++++++------\n> >  upload-pack.c          |   15 ++++++++-------\n> >  2 files changed, 39 insertions(+), 13 deletions(-)\n> >\n> > diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\n> > index e1a687a..2d36378 100644\n> > --- a/builtin/receive-pack.c\n> > +++ b/builtin/receive-pack.c\n> > @@ -120,9 +120,17 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void\n> >  \treturn 0;\n> >  }\n> >  \n> > +static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n> > +{\n> > +\tpath = strip_namespace(path);\n> > +\tif (!path)\n> > +\t\tpath = \".have\";\n> > +\treturn show_ref(path, sha1, flag, cb_data);\n> \n> At the first glance, this felt somewhat unoptimal as it forbids us from\n> stuffing fake \"ref\" entries other than \".have\" via the add_extra_ref()\n> interface, and I wondered if it would make sense to do something like this\n> instead:\n> \n> \tconst char *ns_path = strip_namespace(path);\n>         if (!ns_path)\n>         \tns_path = path;\n> \treturn show_ref(ns_path, sha1, flag, cb_data);\n> \n> But that is flawed, and I think your patch does the right thing.  The\n> justification is a bit subtle [*1*] and I think it needs to be explained\n> in a comment around here, not just in the 0/4 cover letter message.\n\nWill do.  How does the following coment sound?\n\n/* We advertise refs outside our current namespace as .have refs, so\n * that the client can use them to minimize data transfer but will\n * otherwise ignore them. */\n\n- Josh Triplett\n"}]}