Merge branch 'jk/negative-hiderefs'

A negative !ref entry in multi-value transfer.hideRefs
configuration can be used to say "don't hide this one".

* jk/negative-hiderefs:
  refs: support negative transfer.hideRefs
  docs/config.txt: reorder hideRefs config
This commit is contained in:
Junio C Hamano 2015-08-19 14:48:53 -07:00
Родитель 138014c3cf 2bc31d1631
Коммит 824a0be6be
3 изменённых файлов: 56 добавлений и 22 удалений

Просмотреть файл

@ -2313,13 +2313,10 @@ receive.denyNonFastForwards::
set when initializing a shared repository.
receive.hideRefs::
String(s) `receive-pack` uses to decide which refs to omit
from its initial advertisement. Use more than one
definitions to specify multiple prefix strings. A ref that
are under the hierarchies listed on the value of this
variable is excluded, and is hidden when responding to `git
push`, and an attempt to update or delete a hidden ref by
`git push` is rejected.
This variable is the same as `transfer.hideRefs`, but applies
only to `receive-pack` (and so affects pushes, but not fetches).
An attempt to update or delete a hidden ref by `git push` is
rejected.
receive.updateServerInfo::
If set to true, git-receive-pack will run git-update-server-info
@ -2607,9 +2604,18 @@ transfer.fsckObjects::
Defaults to false.
transfer.hideRefs::
This variable can be used to set both `receive.hideRefs`
and `uploadpack.hideRefs` at the same time to the same
values. See entries for these other variables.
String(s) `receive-pack` and `upload-pack` use to decide which
refs to omit from their initial advertisements. Use more than
one definition to specify multiple prefix strings. A ref that is
under the hierarchies listed in the value of this variable is
excluded, and is hidden when responding to `git push` or `git
fetch`. See `receive.hideRefs` and `uploadpack.hideRefs` for
program-specific versions of this config.
+
You may also include a `!` in front of the ref name to negate the entry,
explicitly exposing it, even if an earlier entry marked it as hidden.
If you have multiple hideRefs values, later entries override earlier ones
(and entries in more-specific config files override less-specific ones).
transfer.unpackLimit::
When `fetch.unpackLimit` or `receive.unpackLimit` are
@ -2624,13 +2630,10 @@ uploadarchive.allowUnreachable::
`false`.
uploadpack.hideRefs::
String(s) `upload-pack` uses to decide which refs to omit
from its initial advertisement. Use more than one
definitions to specify multiple prefix strings. A ref that
are under the hierarchies listed on the value of this
variable is excluded, and is hidden from `git ls-remote`,
`git fetch`, etc. An attempt to fetch a hidden ref by `git
fetch` will fail. See also `uploadpack.allowTipSHA1InWant`.
This variable is the same as `transfer.hideRefs`, but applies
only to `upload-pack` (and so affects only fetches, not pushes).
An attempt to fetch a hidden ref by `git fetch` will fail. See
also `uploadpack.allowTipSHA1InWant`.
uploadpack.allowTipSHA1InWant::
When `uploadpack.hideRefs` is in effect, allow `upload-pack`

18
refs.c
Просмотреть файл

@ -4371,17 +4371,25 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
int ref_is_hidden(const char *refname)
{
struct string_list_item *item;
int i;
if (!hide_refs)
return 0;
for_each_string_list_item(item, hide_refs) {
for (i = hide_refs->nr - 1; i >= 0; i--) {
const char *match = hide_refs->items[i].string;
int neg = 0;
int len;
if (!starts_with(refname, item->string))
if (*match == '!') {
neg = 1;
match++;
}
if (!starts_with(refname, match))
continue;
len = strlen(item->string);
len = strlen(match);
if (!refname[len] || refname[len] == '/')
return 1;
return !neg;
}
return 0;
}

Просмотреть файл

@ -128,6 +128,11 @@ test_expect_success 'Report match with --exit-code' '
test_cmp expect actual
'
test_expect_success 'set up some extra tags for ref hiding' '
git tag magic/one &&
git tag magic/two
'
for configsection in transfer uploadpack
do
test_expect_success "Hide some refs with $configsection.hiderefs" '
@ -138,6 +143,24 @@ do
sed -e "/ refs\/tags\//d" >expect &&
test_cmp expect actual
'
test_expect_success "Override hiding of $configsection.hiderefs" '
test_when_finished "test_unconfig $configsection.hiderefs" &&
git config --add $configsection.hiderefs refs/tags &&
git config --add $configsection.hiderefs "!refs/tags/magic" &&
git config --add $configsection.hiderefs refs/tags/magic/one &&
git ls-remote . >actual &&
grep refs/tags/magic/two actual &&
! grep refs/tags/magic/one actual
'
done
test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' '
test_config uploadpack.hiderefs refs/tags &&
test_config transfer.hiderefs "!refs/tags/magic" &&
git ls-remote . >actual &&
grep refs/tags/magic actual
'
test_done