Merge branch 'hn/refs-cleanup'

Preliminary clean-ups around refs API, plus file format
specification documentation for the reftable backend.

* hn/refs-cleanup:
  reftable: define version 2 of the spec to accomodate SHA256
  reftable: clarify how empty tables should be written
  reftable: file format documentation
  refs: improve documentation for ref iterator
  t: use update-ref and show-ref to reading/writing refs
  refs.h: clarify reflog iteration order
This commit is contained in:
Junio C Hamano 2020-06-12 13:57:13 -07:00
commit eebb51ba8c
9 changed files with 1137 additions and 25 deletions

View File

@ -93,6 +93,7 @@ TECH_DOCS += technical/protocol-capabilities
TECH_DOCS += technical/protocol-common
TECH_DOCS += technical/protocol-v2
TECH_DOCS += technical/racy-git
TECH_DOCS += technical/reftable
TECH_DOCS += technical/send-pack-pipeline
TECH_DOCS += technical/shallow
TECH_DOCS += technical/signature-format

File diff suppressed because it is too large Load Diff

18
refs.h
View File

@ -432,19 +432,35 @@ int delete_refs(const char *msg, struct string_list *refnames,
int refs_delete_reflog(struct ref_store *refs, const char *refname);
int delete_reflog(const char *refname);
/* iterate over reflog entries */
/*
* Callback to process a reflog entry found by the iteration functions (see
* below)
*/
typedef int each_reflog_ent_fn(
struct object_id *old_oid, struct object_id *new_oid,
const char *committer, timestamp_t timestamp,
int tz, const char *msg, void *cb_data);
/* Iterate over reflog entries in the log for `refname`. */
/* oldest entry first */
int refs_for_each_reflog_ent(struct ref_store *refs, const char *refname,
each_reflog_ent_fn fn, void *cb_data);
/* youngest entry first */
int refs_for_each_reflog_ent_reverse(struct ref_store *refs,
const char *refname,
each_reflog_ent_fn fn,
void *cb_data);
/*
* Iterate over reflog entries in the log for `refname` in the main ref store.
*/
/* oldest entry first */
int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data);
/* youngest entry first */
int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void *cb_data);
/*

View File

@ -347,9 +347,13 @@ int is_empty_ref_iterator(struct ref_iterator *ref_iterator);
/*
* Return an iterator that goes over each reference in `refs` for
* which the refname begins with prefix. If trim is non-zero, then
* trim that many characters off the beginning of each refname. flags
* can be DO_FOR_EACH_INCLUDE_BROKEN to include broken references in
* the iteration. The output is ordered by refname.
* trim that many characters off the beginning of each refname.
* The output is ordered by refname. The following flags are supported:
*
* DO_FOR_EACH_INCLUDE_BROKEN: include broken references in
* the iteration.
*
* DO_FOR_EACH_PER_WORKTREE_ONLY: only produce REF_TYPE_PER_WORKTREE refs.
*/
struct ref_iterator *refs_ref_iterator_begin(
struct ref_store *refs,
@ -438,6 +442,14 @@ void base_ref_iterator_free(struct ref_iterator *iter);
/* Virtual function declarations for ref_iterators: */
/*
* backend-specific implementation of ref_iterator_advance. For symrefs, the
* function should set REF_ISSYMREF, and it should also dereference the symref
* to provide the OID referent. If DO_FOR_EACH_INCLUDE_BROKEN is set, symrefs
* with non-existent referents and refs pointing to non-existent object names
* should also be returned. If DO_FOR_EACH_PER_WORKTREE_ONLY, only
* REF_TYPE_PER_WORKTREE refs should be returned.
*/
typedef int ref_iterator_advance_fn(struct ref_iterator *ref_iterator);
typedef int ref_iterator_peel_fn(struct ref_iterator *ref_iterator,

View File

@ -62,7 +62,7 @@ test_expect_success 'check commit-tree' '
'
test_expect_success 'check rev-list' '
echo $SHA >"$REAL/HEAD" &&
git update-ref "HEAD" "$SHA" &&
test "$SHA" = "$(git rev-list HEAD)"
'

View File

@ -37,15 +37,15 @@ test_expect_success setup '
test_expect_success "create $m" '
git update-ref $m $A &&
test $A = $(cat .git/$m)
test $A = $(git show-ref -s --verify $m)
'
test_expect_success "create $m with oldvalue verification" '
git update-ref $m $B $A &&
test $B = $(cat .git/$m)
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "fail to delete $m with stale ref" '
test_must_fail git update-ref -d $m $A &&
test $B = "$(cat .git/$m)"
test $B = "$(git show-ref -s --verify $m)"
'
test_expect_success "delete $m" '
test_when_finished "rm -f .git/$m" &&
@ -56,7 +56,7 @@ test_expect_success "delete $m" '
test_expect_success "delete $m without oldvalue verification" '
test_when_finished "rm -f .git/$m" &&
git update-ref $m $A &&
test $A = $(cat .git/$m) &&
test $A = $(git show-ref -s --verify $m) &&
git update-ref -d $m &&
test_path_is_missing .git/$m
'
@ -69,15 +69,15 @@ test_expect_success "fail to create $n" '
test_expect_success "create $m (by HEAD)" '
git update-ref HEAD $A &&
test $A = $(cat .git/$m)
test $A = $(git show-ref -s --verify $m)
'
test_expect_success "create $m (by HEAD) with oldvalue verification" '
git update-ref HEAD $B $A &&
test $B = $(cat .git/$m)
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "fail to delete $m (by HEAD) with stale ref" '
test_must_fail git update-ref -d HEAD $A &&
test $B = $(cat .git/$m)
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "delete $m (by HEAD)" '
test_when_finished "rm -f .git/$m" &&
@ -178,14 +178,14 @@ test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always'
test_expect_success "create $m (by HEAD)" '
git update-ref HEAD $A &&
test $A = $(cat .git/$m)
test $A = $(git show-ref -s --verify $m)
'
test_expect_success 'pack refs' '
git pack-refs --all
'
test_expect_success "move $m (by HEAD)" '
git update-ref HEAD $B $A &&
test $B = $(cat .git/$m)
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
test_when_finished "rm -f .git/$m" &&
@ -255,7 +255,7 @@ test_expect_success '(not) change HEAD with wrong SHA1' '
'
test_expect_success "(not) changed .git/$m" '
test_when_finished "rm -f .git/$m" &&
! test $B = $(cat .git/$m)
! test $B = $(git show-ref -s --verify $m)
'
rm -f .git/logs/refs/heads/master
@ -263,19 +263,19 @@ test_expect_success "create $m (logged by touch)" '
test_config core.logAllRefUpdates false &&
GIT_COMMITTER_DATE="2005-05-26 23:30" \
git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
test $A = $(cat .git/$m)
test $A = $(git show-ref -s --verify $m)
'
test_expect_success "update $m (logged by touch)" '
test_config core.logAllRefUpdates false &&
GIT_COMMITTER_DATE="2005-05-26 23:31" \
git update-ref HEAD $B $A -m "Switch" &&
test $B = $(cat .git/$m)
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "set $m (logged by touch)" '
test_config core.logAllRefUpdates false &&
GIT_COMMITTER_DATE="2005-05-26 23:41" \
git update-ref HEAD $A &&
test $A = $(cat .git/$m)
test $A = $(git show-ref -s --verify $m)
'
test_expect_success 'empty directory removal' '
@ -319,19 +319,19 @@ test_expect_success "create $m (logged by config)" '
test_config core.logAllRefUpdates true &&
GIT_COMMITTER_DATE="2005-05-26 23:32" \
git update-ref HEAD $A -m "Initial Creation" &&
test $A = $(cat .git/$m)
test $A = $(git show-ref -s --verify $m)
'
test_expect_success "update $m (logged by config)" '
test_config core.logAllRefUpdates true &&
GIT_COMMITTER_DATE="2005-05-26 23:33" \
git update-ref HEAD'" $B $A "'-m "Switch" &&
test $B = $(cat .git/$m)
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "set $m (logged by config)" '
test_config core.logAllRefUpdates true &&
GIT_COMMITTER_DATE="2005-05-26 23:43" \
git update-ref HEAD $A &&
test $A = $(cat .git/$m)
test $A = $(git show-ref -s --verify $m)
'
cat >expect <<EOF

View File

@ -207,7 +207,7 @@ test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
{
# we do not want to use rev-parse here, because
# we are testing it
cat .git/refs/heads/foobar &&
git show-ref -s refs/heads/foobar &&
printf "%s\n" --
} >expect &&
git rev-parse foobar -- >actual &&

View File

@ -135,7 +135,7 @@ test_expect_success 'tag replaced commit' '
test_expect_success '"git fsck" works' '
git fsck master >fsck_master.out &&
test_i18ngrep "dangling commit $R" fsck_master.out &&
test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
test_i18ngrep "dangling tag $(git show-ref -s refs/tags/mytag)" fsck_master.out &&
test -z "$(git fsck)"
'

View File

@ -48,8 +48,8 @@ test_expect_success REMOTE_SVN 'simple fetch' '
'
test_debug '
cat .git/refs/svn/svnsim/master
cat .git/refs/remotes/svnsim/master
git show-ref -s refs/svn/svnsim/master
git show-ref -s refs/remotes/svnsim/master
'
test_expect_success REMOTE_SVN 'repeated fetch, nothing shall change' '