diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-02-17 15:25:57 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-02-17 15:25:57 -0800 |
commit | ce735bf7fd66c6404e86e5a313f35abc0394b838 (patch) | |
tree | ac1605c58fb6a3b12c90a4085cc6a0a7ada64da9 /refs.c | |
parent | abea4dc76a675d4ac0f27a2367256dc31981d1ca (diff) | |
parent | daebaa78137d59693a808c1f0bdec0ecb40fc12e (diff) | |
download | git-ce735bf7fd66c6404e86e5a313f35abc0394b838.tar.gz git-ce735bf7fd66c6404e86e5a313f35abc0394b838.tar.xz |
Merge branch 'jc/hidden-refs'
Allow the server side to redact the refs/ namespace it shows to the
client.
Will merge to 'master'.
* jc/hidden-refs:
upload/receive-pack: allow hiding ref hierarchies
upload-pack: simplify request validation
upload-pack: share more code
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -3,6 +3,7 @@ #include "object.h" #include "tag.h" #include "dir.h" +#include "string-list.h" /* * Make sure "ref" is something reasonable to have under ".git/refs/"; @@ -2554,3 +2555,46 @@ char *shorten_unambiguous_ref(const char *refname, int strict) free(short_name); return xstrdup(refname); } + +static struct string_list *hide_refs; + +int parse_hide_refs_config(const char *var, const char *value, const char *section) +{ + if (!strcmp("transfer.hiderefs", var) || + /* NEEDSWORK: use parse_config_key() once both are merged */ + (!prefixcmp(var, section) && var[strlen(section)] == '.' && + !strcmp(var + strlen(section), ".hiderefs"))) { + char *ref; + int len; + + if (!value) + return config_error_nonbool(var); + ref = xstrdup(value); + len = strlen(ref); + while (len && ref[len - 1] == '/') + ref[--len] = '\0'; + if (!hide_refs) { + hide_refs = xcalloc(1, sizeof(*hide_refs)); + hide_refs->strdup_strings = 1; + } + string_list_append(hide_refs, ref); + } + return 0; +} + +int ref_is_hidden(const char *refname) +{ + struct string_list_item *item; + + if (!hide_refs) + return 0; + for_each_string_list_item(item, hide_refs) { + int len; + if (prefixcmp(refname, item->string)) + continue; + len = strlen(item->string); + if (!refname[len] || refname[len] == '/') + return 1; + } + return 0; +} |