Further preparatory work on the refs API before the pluggable
backend series can land.
* mh/split-under-lock: (33 commits)
lock_ref_sha1_basic(): only handle REF_NODEREF mode
commit_ref_update(): remove the flags parameter
lock_ref_for_update(): don't resolve symrefs
lock_ref_for_update(): don't re-read non-symbolic references
refs: resolve symbolic refs first
ref_transaction_update(): check refname_is_safe() at a minimum
unlock_ref(): move definition higher in the file
lock_ref_for_update(): new function
add_update(): initialize the whole ref_update
verify_refname_available(): adjust constness in declaration
refs: don't dereference on rename
refs: allow log-only updates
delete_branches(): use resolve_refdup()
ref_transaction_commit(): correctly report close_ref() failure
ref_transaction_create(): disallow recursive pruning
refs: make error messages more consistent
lock_ref_sha1_basic(): remove unneeded local variable
read_raw_ref(): move docstring to header file
read_raw_ref(): improve docstring
read_raw_ref(): rename symref argument to referent
...
@ -212,7 +212,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
@@ -212,7 +212,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
die(_("Couldn't look up commit object for HEAD"));
}
for (i = 0; i < argc; i++, strbuf_release(&bname)) {
const char *target;
char *target = NULL;
int flags = 0;
strbuf_branchname(&bname, argv[i]);
@ -231,11 +231,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
@@ -231,11 +231,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
}
}
target = resolve_ref_unsafe(name,
RESOLVE_REF_READING
| RESOLVE_REF_NO_RECURSE
| RESOLVE_REF_ALLOW_BAD_NAME,
sha1, &flags);
target = resolve_refdup(name,
RESOLVE_REF_READING
| RESOLVE_REF_NO_RECURSE
| RESOLVE_REF_ALLOW_BAD_NAME,
sha1, &flags);
if (!target) {
error(remote_branch
? _("remote-tracking branch '%s' not found.")
@ -248,7 +248,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
@@ -248,7 +248,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
if (delete_ref(name, is_null_sha1(sha1) ? NULL : sha1,
@ -258,7 +258,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
@@ -258,7 +258,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
: _("Error deleting branch '%s'"),
bname.buf);
ret = 1;
continue;
goto next;
}
if (!quiet) {
printf(remote_branch
@ -270,6 +270,9 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
@@ -270,6 +270,9 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
@ -120,25 +120,33 @@ int check_refname_format(const char *refname, int flags)
@@ -120,25 +120,33 @@ int check_refname_format(const char *refname, int flags)
int refname_is_safe(const char *refname)
{
if (starts_with(refname, "refs/")) {
const char *rest;
if (skip_prefix(refname, "refs/", &rest)) {
char *buf;
int result;
size_t restlen = strlen(rest);
/* rest must not be empty, or start or end with "/" */
@ -104,4 +106,76 @@ test_expect_success 'one new ref is a simple prefix of another' '
@@ -104,4 +106,76 @@ test_expect_success 'one new ref is a simple prefix of another' '
'
test_expect_success 'empty directory should not fool rev-parse' '
prefix=refs/e-rev-parse &&
git update-ref $prefix/foo $C &&
git pack-refs --all &&
mkdir -p .git/$prefix/foo/bar/baz &&
echo "$C" >expected &&
git rev-parse $prefix/foo >actual &&
test_cmp expected actual
'
test_expect_success 'empty directory should not fool for-each-ref' '
prefix=refs/e-for-each-ref &&
git update-ref $prefix/foo $C &&
git for-each-ref $prefix >expected &&
git pack-refs --all &&
mkdir -p .git/$prefix/foo/bar/baz &&
git for-each-ref $prefix >actual &&
test_cmp expected actual
'
test_expect_success 'empty directory should not fool create' '
prefix=refs/e-create &&
mkdir -p .git/$prefix/foo/bar/baz &&
printf "create %s $C\n" $prefix/foo |
git update-ref --stdin
'
test_expect_success 'empty directory should not fool verify' '
prefix=refs/e-verify &&
git update-ref $prefix/foo $C &&
git pack-refs --all &&
mkdir -p .git/$prefix/foo/bar/baz &&
printf "verify %s $C\n" $prefix/foo |
git update-ref --stdin
'
test_expect_success 'empty directory should not fool 1-arg update' '
prefix=refs/e-update-1 &&
git update-ref $prefix/foo $C &&
git pack-refs --all &&
mkdir -p .git/$prefix/foo/bar/baz &&
printf "update %s $D\n" $prefix/foo |
git update-ref --stdin
'
test_expect_success 'empty directory should not fool 2-arg update' '
prefix=refs/e-update-2 &&
git update-ref $prefix/foo $C &&
git pack-refs --all &&
mkdir -p .git/$prefix/foo/bar/baz &&
printf "update %s $D $C\n" $prefix/foo |
git update-ref --stdin
'
test_expect_success 'empty directory should not fool 0-arg delete' '
prefix=refs/e-delete-0 &&
git update-ref $prefix/foo $C &&
git pack-refs --all &&
mkdir -p .git/$prefix/foo/bar/baz &&
printf "delete %s\n" $prefix/foo |
git update-ref --stdin
'
test_expect_success 'empty directory should not fool 1-arg delete' '