aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-02-17 15:25:57 -0800
committerJunio C Hamano <gitster@pobox.com>2013-02-17 15:25:57 -0800
commitce735bf7fd66c6404e86e5a313f35abc0394b838 (patch)
treeac1605c58fb6a3b12c90a4085cc6a0a7ada64da9 /refs.c
parentabea4dc76a675d4ac0f27a2367256dc31981d1ca (diff)
parentdaebaa78137d59693a808c1f0bdec0ecb40fc12e (diff)
downloadgit-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.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/refs.c b/refs.c
index 296282530..175b9fcaa 100644
--- a/refs.c
+++ b/refs.c
@@ -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;
+}