refs backend
Subsystems (2)
v6 cover refs backend
This version incorporates fixes for function scope from Ramsay Jones.
It breaks patches down a bit more, to make them easier to review and understand. Michael Haggerty had some suggestions here.
As suggested by Duy Nguyen, it replaces the resolve_ref_unsafe backend method with read_raw_ref, moving resolve_ref_unsafe to the common code.
It adds support for running tests under alternate ref backends.
It fixes two indentation errors, one reported by Eric Wong.
It updates the documentation to include info about a few more limitations on the LMDB backend. It incorporates other LMDB-related suggestions from Duy Nguyen, e.g. using MDB_NOSUBDIR.
There's a fix for non-normal ref renames, also from Duy Nguyen.
Symbolic ref splitting has a bug fix, suggested by Michael Haggerty.
There are other, more minor changes suggested by Michael Haggerty and Duy Nguyen.
David Turner (29):
refs: move head_ref{,_submodule} to the common code
refs: move for_each_*ref* functions into common code
files-backend: break out ref reading
refs: move resolve_ref_unsafe into common code
refs: add method for do_for_each_ref
refs: add do_for_each_per_worktree_ref
refs: add methods for reflog
refs: add method for initial ref transaction commit
refs: add method for delete_refs
refs: add methods to init refs db
refs: add method to rename refs
refs: handle non-normal ref renames
refs: make lock generic
refs: move duplicate check to common code
refs: allow log-only updates
refs: don't dereference on rename
refs: on symref reflog expire, lock symref not referrent
refs: resolve symbolic refs first
refs: always handle non-normal refs in files backend
init: allow alternate ref strorage to be set for new repos
refs: check submodules' ref storage config
clone: allow ref storage backend to be set for clone
svn: learn ref-storage argument
refs: register ref storage backends
config: read ref storage config on startup
refs: break out resolve_ref_unsafe_submodule
refs: add LMDB refs storage backend
refs: tests for lmdb backend
tests: add ref-storage argument
Ramsay Jones (1):
refs: reduce the visibility of do_for_each_ref()
Ronnie Sahlberg (2):
refs: add a backend method structure with transaction functions
refs: add methods for misc ref operations
.gitignore | 1 + Documentation/config.txt | 9 + Documentation/git-clone.txt | 6 + Documentation/git-init-db.txt | 2 +- Documentation/git-init.txt | 8 +- Documentation/technical/refs-lmdb-backend.txt | 61 + Documentation/technical/repository-version.txt | 7 + Makefile | 12 + builtin/clone.c | 5 + builtin/init-db.c | 55 +- builtin/submodule--helper.c | 2 +- cache.h | 2 + config.c | 24 + configure.ac | 33 + contrib/completion/git-completion.bash | 6 +- contrib/workdir/git-new-workdir | 3 + git-submodule.sh | 13 + git-svn.perl | 6 +- path.c | 30 +- refs.c | 632 +++++++- refs.h | 16 + refs/files-backend.c | 686 ++++----- refs/lmdb-backend.c | 1886 ++++++++++++++++++++++++ refs/refs-internal.h | 123 +- setup.c | 12 + t/README | 6 + t/lib-submodule-update.sh | 15 +- t/lib-t6000.sh | 7 +- t/t0001-init.sh | 25 + t/t0008-ignores.sh | 2 +- t/t0062-revision-walking.sh | 6 + t/t1021-rerere-in-workdir.sh | 6 + t/t1200-tutorial.sh | 8 +- t/t1302-repo-version.sh | 6 + t/t1305-config-include.sh | 17 +- t/t1400-update-ref.sh | 6 + t/t1401-symbolic-ref.sh | 17 +- t/t1404-update-ref-df-conflicts.sh | 8 +- t/t1410-reflog.sh | 16 + t/t1430-bad-ref-name.sh | 6 + t/t1450-fsck.sh | 12 +- t/t1460-refs-lmdb-backend.sh | 1109 ++++++++++++++ t/t1470-refs-lmdb-backend-reflog.sh | 359 +++++ t/t1480-refs-lmdb-submodule.sh | 85 ++ t/t1506-rev-parse-diagnosis.sh | 4 +- t/t2013-checkout-submodule.sh | 2 +- t/t2105-update-index-gitfile.sh | 4 +- t/t2107-update-index-basic.sh | 6 +- t/t2201-add-update-typechange.sh | 4 +- t/t3001-ls-files-others-exclude.sh | 2 +- t/t3010-ls-files-killed-modified.sh | 4 +- t/t3040-subprojects-basic.sh | 4 +- t/t3050-subprojects-fetch.sh | 2 +- t/t3200-branch.sh | 84 +- t/t3210-pack-refs.sh | 7 + t/t3211-peel-ref.sh | 6 + t/t3308-notes-merge.sh | 2 +- t/t3404-rebase-interactive.sh | 2 +- t/t3600-rm.sh | 2 +- t/t3800-mktag.sh | 4 +- t/t3903-stash.sh | 2 +- t/t4010-diff-pathspec.sh | 2 +- t/t4020-diff-external.sh | 2 +- t/t4027-diff-submodule.sh | 2 +- t/t4035-diff-quiet.sh | 2 +- t/t4255-am-submodule.sh | 2 +- t/t5000-tar-tree.sh | 3 +- t/t5304-prune.sh | 2 +- t/t5312-prune-corruption.sh | 11 +- t/t5500-fetch-pack.sh | 10 +- t/t5510-fetch.sh | 30 +- t/t5526-fetch-submodules.sh | 4 +- t/t5527-fetch-odd-refs.sh | 7 + t/t5537-fetch-shallow.sh | 7 + t/t5700-clone-reference.sh | 42 +- t/t6001-rev-list-graft.sh | 3 +- t/t6010-merge-base.sh | 2 +- t/t6050-replace.sh | 4 +- t/t6120-describe.sh | 6 +- t/t6301-for-each-ref-errors.sh | 12 +- t/t7201-co.sh | 2 +- t/t7300-clean.sh | 25 +- t/t7400-submodule-basic.sh | 18 +- t/t7402-submodule-rebase.sh | 2 +- t/t7405-submodule-merge.sh | 10 +- t/t9104-git-svn-follow-parent.sh | 3 +- t/t9115-git-svn-dcommit-funky-renames.sh | 2 +- t/t9350-fast-export.sh | 6 +- t/t9902-completion.sh | 3 +- t/t9903-bash-prompt.sh | 1 + t/test-lib-functions.sh | 53 +- t/test-lib.sh | 12 + test-refs-lmdb-backend.c | 65 + 93 files changed, 5257 insertions(+), 595 deletions(-) create mode 100644 Documentation/technical/refs-lmdb-backend.txt create mode 100644 refs/lmdb-backend.c create mode 100755 t/t1460-refs-lmdb-backend.sh create mode 100755 t/t1470-refs-lmdb-backend-reflog.sh create mode 100755 t/t1480-refs-lmdb-submodule.sh create mode 100644 test-refs-lmdb-backend.c
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 1/32 refs: move head_ref{,_submodule} to the common code
These don't use any backend-specific functions. These were previously defined in terms of the do_head_ref helper function, but since they are otherwise identical, we don't need that function.
--- refs.c | 23 +++++++++++++++++++++++ refs/files-backend.c | 28 ---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-)
refs.c +23 -0
@@ -1082,3 +1082,26 @@ int rename_ref_available(const char *oldname, const char *newname)strbuf_release (&err);return ret; } + +int head_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data) +{ +struct object_id oid; +int flag; + +if (submodule) { +if (resolve_gitlink_ref (submodule,"HEAD" , oid.hash) ==0 ) +return fn ("HEAD" , &oid,0 , cb_data); + +return 0 ; + } + +if (!read_ref_full ("HEAD" ,RESOLVE_REF_READING , oid.hash, &flag)) +return fn ("HEAD" , &oid, flag, cb_data); + +return 0 ; +} + +int head_ref (each_ref_fn fn,void *cb_data) +{ +return head_ref_submodule (NULL , fn, cb_data); +}
refs/files-backend.c +0 -28
@@ -1753,34 +1753,6 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,return do_for_each_entry (refs, base, do_one_ref, &data); } -static int do_head_ref (const char *submodule,each_ref_fn fn,void *cb_data) -{ -struct object_id oid; -int flag; - -if (submodule) { -if (resolve_gitlink_ref (submodule,"HEAD" , oid.hash) ==0 ) -return fn ("HEAD" , &oid,0 , cb_data); - -return 0 ; - } - -if (!read_ref_full ("HEAD" ,RESOLVE_REF_READING , oid.hash, &flag)) -return fn ("HEAD" , &oid, flag, cb_data); - -return 0 ; -} - -int head_ref (each_ref_fn fn,void *cb_data) -{ -return do_head_ref (NULL , fn, cb_data); -} - -int head_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data) -{ -return do_head_ref (submodule, fn, cb_data); -} -int for_each_ref (each_ref_fn fn,void *cb_data) {return do_for_each_ref (&ref_cache,"" , fn,0 ,0 , cb_data);
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 2/32 refs: move for_each_*ref* functions into common code
In reply to David TurnerMake do_for_each_ref take a submodule as an argument instead of a ref_cache. Since all for_each_*ref* functions are defined in terms of do_for_each_ref, we can then move them into the common code.
Later, we can simply make do_for_each_ref into a backend function.
--- refs.c | 52 +++++++++++++++++++++++++++++++++++++++++++ refs/files-backend.c | 62 +++++----------------------------------------------- refs/refs-internal.h | 9 ++++++++ 3 files changed, 66 insertions(+), 57 deletions(-)
refs.c +52 -0
@@ -1105,3 +1105,55 @@ int head_ref(each_ref_fn fn, void *cb_data) {return head_ref_submodule (NULL , fn, cb_data); } + +int for_each_ref (each_ref_fn fn,void *cb_data) +{ +return do_for_each_ref (NULL ,"" , fn,0 ,0 , cb_data); +} + +int for_each_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data) +{ +return do_for_each_ref (submodule,"" , fn,0 ,0 , cb_data); +} + +int for_each_ref_in (const char *prefix,each_ref_fn fn,void *cb_data) +{ +return do_for_each_ref (NULL , prefix, fn,strlen (prefix),0 , cb_data); +} + +int for_each_fullref_in (const char *prefix,each_ref_fn fn,void *cb_data,unsigned int broken) +{ +unsigned int flag =0 ; + +if (broken) + flag =DO_FOR_EACH_INCLUDE_BROKEN ; +return do_for_each_ref (NULL , prefix, fn,0 , flag, cb_data); +} + +int for_each_ref_in_submodule (const char *submodule,const char *prefix, +each_ref_fn fn,void *cb_data) +{ +return do_for_each_ref (submodule, prefix, fn,strlen (prefix),0 , cb_data); +} + +int for_each_replace_ref (each_ref_fn fn,void *cb_data) +{ +return do_for_each_ref (NULL , git_replace_ref_base, fn, +strlen (git_replace_ref_base),0 , cb_data); +} + +int for_each_namespaced_ref (each_ref_fn fn,void *cb_data) +{ +struct strbuf buf =STRBUF_INIT ; +int ret; +strbuf_addf (&buf,"%srefs/" ,get_git_namespace ()); + ret =do_for_each_ref (NULL , buf.buf, fn,0 ,0 , cb_data); +strbuf_release (&buf); +return ret; +} + +int for_each_rawref (each_ref_fn fn,void *cb_data) +{ +return do_for_each_ref (NULL ,"" , fn,0 , +DO_FOR_EACH_INCLUDE_BROKEN , cb_data); +}
refs/files-backend.c +5 -57
82 lines not on this page · raw message
refs/refs-internal.h +9 -0
@@ -197,4 +197,13 @@ const char *find_descendant_ref(const char *dirname,int rename_ref_available (const char *oldname,const char *newname); + +/* Include broken references in a do_for_each_ref*() iteration: */ +#define DO_FOR_EACH_INCLUDE_BROKEN 0x01 + +/* +* The common backend for the for_each_*ref* functions +*/ +int do_for_each_ref (const char *submodule,const char *base, +each_ref_fn fn,int trim,int flags,void *cb_data);#endif /* REFS_REFS_INTERNAL_H */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 3/32 files-backend: break out ref reading
In reply to David TurnerRefactor resolve_ref_1 in terms of a new function read_raw_ref, which is responsible for reading ref data from the ref storage.
Later, we will make read_raw_ref a pluggable backend function, and make resolve_ref_unsafe common.
Testing done: Hacked in code to run both old and new version of resolve_ref_1 and compare all outputs, failing dramatically if outputs differed. Ran test suite.
--- refs/files-backend.c | 265 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 159 insertions(+), 106 deletions(-)
refs/files-backend.c +159 -106
@@ -1377,10 +1377,9 @@ static struct ref_entry *get_packed_ref(const char *refname)/* * A loose ref file doesn't exist; check for a packed ref. The -* options are forwarded from resolve_safe_unsafe(). +* options are forwarded from resolve_ref_unsafe(). */ static int resolve_missing_loose_ref (const char *refname, -int resolve_flags,unsigned char *sha1,int *flags) {
@@ -1398,64 +1397,48 @@ static int resolve_missing_loose_ref(const char *refname,return 0 ; }/* The reference is not a packed reference, either. */ -if (resolve_flags &RESOLVE_REF_READING ) { - errno =ENOENT ; -return -1 ; - }else { -hashclr (sha1); -return 0 ; - } + errno =ENOENT ; +return -1 ; } -/* This function needs to return a meaningful errno on failure */ -static const char *resolve_ref_1 (const char *refname, -int resolve_flags, -unsigned char *sha1, -int *flags, -struct strbuf *sb_refname, -struct strbuf *sb_path, -struct strbuf *sb_contents) +/* +* Read a raw ref from the filesystem or packed refs file. +* +* If the ref is a sha1, fill in sha1 and return 0. +* +* If the ref is symbolic, fill in *symref with the referrent +* (e.g. "refs/heads/master") and return 0. The caller is responsible +* for validating the referrent. Set REF_ISSYMREF in flags. +* +* If the ref is neither a symbolic ref nor a sha1, it is broken. Set +* REF_ISBROKEN in flags, set errno to EINVAL, and return -1. +* +* If the ref doesn't exist, set errno to ENOENT and return -1. +* +* If there is another error reading the ref, set errno appropriately and +* return -1. +* +* Backend-specific flags might be set in flags as well, regardless of +* outcome. +* +* sb_path is workspace: the caller should allocate and free it. +*/ +static int read_raw_ref (const char *refname,unsigned char *sha1, +struct strbuf *symref,struct strbuf *sb_path, +unsigned int *flags) { -int depth =MAXDEPTH ; -int bad_name =0 ; - -if (flags) - *flags =0 ; +struct strbuf sb_contents =STRBUF_INIT ; +int ret =-1 ; +const char *path; +const char *buf; -if (check_refname_format (refname,REFNAME_ALLOW_ONELEVEL )) { -if (flags) - *flags |=REF_BAD_NAME ; +strbuf_reset (sb_path); +strbuf_git_path (sb_path,"%s" , refname); + path = sb_path->buf; -if (!(resolve_flags &RESOLVE_REF_ALLOW_BAD_NAME ) || - !refname_is_safe (refname)) { - errno =EINVAL ; -return NULL ; - } -/* -* dwim_ref() uses REF_ISBROKEN to distinguish between -* missing refs and refs that were present but invalid, -* to complain about the latter to stderr. -* -* We don't know whether the ref exists, so don't set -* REF_ISBROKEN yet. -*/ - bad_name =1 ; - } -for (;;) { -const char *path; +for (;;) {struct stat st; -char *buf;int fd; - -if (--depth <0 ) { - errno =ELOOP ; -return NULL ; - } - -strbuf_reset (sb_path); -strbuf_git_path (sb_path,"%s" , refname); - path = sb_path->buf; -/* * We might have to loop back here to avoid a race * condition: first we lstat() the file, then we try
@@ -1465,49 +1448,45 @@ static const char *resolve_ref_1(const char *refname,* we don't want to report that as an error but rather * try again starting with the lstat(). */ - stat_ref: +if (lstat (path, &st) <0 ) {if (errno !=ENOENT ) -return NULL ; -if (resolve_missing_loose_ref (refname, resolve_flags, - sha1, flags)) -return NULL ; -if (bad_name) { -hashclr (sha1); -if (flags) - *flags |=REF_ISBROKEN ; - } -return refname; +break ; +if (resolve_missing_loose_ref (refname, sha1, flags)) +break ; + ret =0 ; +break ; }/* Follow "normalized" - ie "refs/.." symlinks by hand */ if (S_ISLNK (st.st_mode)) { -strbuf_reset (sb_contents); -if (strbuf_readlink (sb_contents, path,0 ) <0 ) { +strbuf_reset (&sb_contents); +if (strbuf_readlink (&sb_contents, path,0 ) <0 ) {if (errno ==ENOENT || errno ==EINVAL )/* inconsistent with lstat; retry */ - goto stat_ref; +continue ;else -return NULL ; +break ; } -if (starts_with (sb_contents->buf,"refs/" ) && - !check_refname_format (sb_contents->buf,0 )) { -strbuf_swap (sb_refname, sb_contents); - refname = sb_refname->buf; +if (starts_with (sb_contents.buf,"refs/" ) && + !check_refname_format (sb_contents.buf,0 )) { +strbuf_swap (&sb_contents, symref);if (flags) *flags |=REF_ISSYMREF ; -if (resolve_flags &RESOLVE_REF_NO_RECURSE ) { -hashclr (sha1); -return refname; - } -continue ; + ret =0 ; +break ; + }else { +/* bogus symlink ref */ +if (flags) + *flags |=REF_ISBROKEN ; +break ; } }/* Is it a directory? */ if (S_ISDIR (st.st_mode)) { errno =EISDIR ; -return NULL ; +break ; }/*
@@ -1518,35 +1497,110 @@ static const char *resolve_ref_1(const char *refname,if (fd <0 ) {if (errno ==ENOENT )/* inconsistent with lstat; retry */ - goto stat_ref; +continue ;else -return NULL ; +break ; } -strbuf_reset (sb_contents); -if (strbuf_read (sb_contents, fd,256 ) <0 ) { +strbuf_reset (&sb_contents); +if (strbuf_read (&sb_contents, fd,256 ) <0 ) {int save_errno = errno;close (fd); errno = save_errno; -return NULL ; +break ; }close (fd); -strbuf_rtrim (sb_contents); +strbuf_rtrim (&sb_contents); + buf = sb_contents.buf; +if (starts_with (buf,"ref:" )) { + buf +=4 ; +while (isspace (*buf)) + buf++; + +strbuf_reset (symref); +strbuf_addstr (symref, buf); +if (flags) + *flags |=REF_ISSYMREF ; + ret =0 ; +break ; + }/* -* Is it a symbolic ref? +* Please note that FETCH_HEAD has additional +* data after the sha. */ -if (!starts_with (sb_contents->buf,"ref:" )) { -/* -* Please note that FETCH_HEAD has a second -* line containing other data. -*/ -if (get_sha1_hex (sb_contents->buf, sha1) || - (sb_contents->buf[40 ] !='\0' && !isspace (sb_contents->buf[40 ]))) { +if (get_sha1_hex (buf, sha1) || + (buf[40 ] !='\0' && !isspace (buf[40 ]))) { +if (flags) + *flags |=REF_ISBROKEN ; + errno =EINVAL ; +break ; + } + ret =0 ; +break ; + } + +strbuf_release (&sb_contents); +return ret; +} + +/* This function needs to return a meaningful errno on failure */ +static const char *resolve_ref_1 (const char *refname, +int resolve_flags, +unsigned char *sha1, +int *flags, +struct strbuf *sb_refname, +struct strbuf *sb_path) +{ +int bad_name =0 ; +int symref_count; + +if (flags) + *flags =0 ; + +if (check_refname_format (refname,REFNAME_ALLOW_ONELEVEL )) { +if (flags) + *flags |=REF_BAD_NAME ; + +if (!(resolve_flags &RESOLVE_REF_ALLOW_BAD_NAME ) || + !refname_is_safe (refname)) { + errno =EINVAL ; +return NULL ; + } +/* +* dwim_ref() uses REF_ISBROKEN to distinguish between +* missing refs and refs that were present but invalid, +* to complain about the latter to stderr. +* +* We don't know whether the ref exists, so don't set +* REF_ISBROKEN yet. +*/ + bad_name =1 ; + } + +for (symref_count =0 ; symref_count <MAXDEPTH ; symref_count++) { +int read_flags =0 ; + +if (read_raw_ref (refname, sha1, sb_refname, sb_path, &read_flags)) { +int saved_errno = errno; +if (flags) + *flags |= read_flags; + errno = saved_errno; +if (bad_name) { +hashclr (sha1);if (flags) *flags |=REF_ISBROKEN ; - errno =EINVAL ; + } +if (resolve_flags &RESOLVE_REF_READING || errno !=ENOENT ) {return NULL ; + }else { +hashclr (sha1); +return refname; } + } +if (flags) + *flags |= read_flags; + +if (!(read_flags &REF_ISSYMREF )) {if (bad_name) {hashclr (sha1);if (flags)
@@ -1554,44 +1608,43 @@ static const char *resolve_ref_1(const char *refname, }return refname; } -if (flags) - *flags |=REF_ISSYMREF ; - buf = sb_contents->buf +4 ; -while (isspace (*buf)) - buf++; -strbuf_reset (sb_refname); -strbuf_addstr (sb_refname, buf); + refname = sb_refname->buf;if (resolve_flags &RESOLVE_REF_NO_RECURSE ) {hashclr (sha1); +if (bad_name && flags) + *flags |=REF_ISBROKEN ;return refname; } -if (check_refname_format (buf,REFNAME_ALLOW_ONELEVEL )) { + +if (check_refname_format (refname,REFNAME_ALLOW_ONELEVEL )) {if (flags) *flags |=REF_ISBROKEN ; -if (!(resolve_flags &RESOLVE_REF_ALLOW_BAD_NAME ) || - !refname_is_safe (buf)) { + !refname_is_safe (refname)) { errno =EINVAL ;return NULL ; } bad_name =1 ; } } + +if (flags) + *flags |=REF_ISBROKEN ; +return NULL ; }const char *resolve_ref_unsafe (const char *refname,int resolve_flags,unsigned char *sha1,int *flags) {static struct strbuf sb_refname =STRBUF_INIT ; -struct strbuf sb_contents =STRBUF_INIT ;struct strbuf sb_path =STRBUF_INIT ;const char *ret; ret =resolve_ref_1 (refname, resolve_flags, sha1, flags, - &sb_refname, &sb_path, &sb_contents); + &sb_refname, &sb_path); +strbuf_release (&sb_path); -strbuf_release (&sb_contents);return ret; }
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 4/32 refs: move resolve_ref_unsafe into common code
In reply to David TurnerNow that resolve_ref_unsafe's only interaction with the backend is through read_raw_ref, we can move it into the common code. Later, we'll replace read_raw_ref with a backend function.
--- refs.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++ refs/files-backend.c | 115 ++------------------------------------------------- refs/refs-internal.h | 6 +++ 3 files changed, 114 insertions(+), 111 deletions(-)
refs.c +104 -0
@@ -1157,3 +1157,107 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)return do_for_each_ref (NULL ,"" , fn,0 ,DO_FOR_EACH_INCLUDE_BROKEN , cb_data); } +/* This function needs to return a meaningful errno on failure */ +static const char *resolve_ref_1 (const char *refname, +int resolve_flags, +unsigned char *sha1, +int *flags, +struct strbuf *sb_refname, +struct strbuf *sb_path) +{ +int bad_name =0 ; +int symref_count; + +if (flags) + *flags =0 ; + +if (check_refname_format (refname,REFNAME_ALLOW_ONELEVEL )) { +if (flags) + *flags |=REF_BAD_NAME ; + +if (!(resolve_flags &RESOLVE_REF_ALLOW_BAD_NAME ) || + !refname_is_safe (refname)) { + errno =EINVAL ; +return NULL ; + } +/* +* dwim_ref() uses REF_ISBROKEN to distinguish between +* missing refs and refs that were present but invalid, +* to complain about the latter to stderr. +* +* We don't know whether the ref exists, so don't set +* REF_ISBROKEN yet. +*/ + bad_name =1 ; + } + +for (symref_count =0 ; symref_count <SYMREF_MAXDEPTH ; symref_count++) { +int read_flags =0 ; + +if (read_raw_ref (refname, sha1, sb_refname, sb_path, &read_flags)) { +int saved_errno = errno; +if (flags) + *flags |= read_flags; + errno = saved_errno; +if (bad_name) { +hashclr (sha1); +if (flags) + *flags |=REF_ISBROKEN ; + } +if (resolve_flags &RESOLVE_REF_READING || errno !=ENOENT ) { +return NULL ; + }else { +hashclr (sha1); +return refname; + } + } +if (flags) + *flags |= read_flags; + +if (!(read_flags &REF_ISSYMREF )) { +if (bad_name) { +hashclr (sha1); +if (flags) + *flags |=REF_ISBROKEN ; + } +return refname; + } + + refname = sb_refname->buf; +if (resolve_flags &RESOLVE_REF_NO_RECURSE ) { +hashclr (sha1); +if (bad_name && flags) + *flags |=REF_ISBROKEN ; +return refname; + } + +if (check_refname_format (refname,REFNAME_ALLOW_ONELEVEL )) { +if (flags) + *flags |=REF_ISBROKEN ; +if (!(resolve_flags &RESOLVE_REF_ALLOW_BAD_NAME ) || + !refname_is_safe (refname)) { + errno =EINVAL ; +return NULL ; + } + bad_name =1 ; + } + } + +if (flags) + *flags |=REF_ISBROKEN ; +return NULL ; +} + +const char *resolve_ref_unsafe (const char *refname,int resolve_flags, +unsigned char *sha1,int *flags) +{ +static struct strbuf sb_refname =STRBUF_INIT ; +struct strbuf sb_path =STRBUF_INIT ; +const char *ret; + + ret =resolve_ref_1 (refname, resolve_flags, sha1, flags, + &sb_refname, &sb_path); + +strbuf_release (&sb_path); +return ret; +}
refs/files-backend.c +4 -111
139 lines not on this page · raw message
refs/refs-internal.h +6 -0
@@ -197,6 +197,8 @@ const char *find_descendant_ref(const char *dirname,int rename_ref_available (const char *oldname,const char *newname); +/* We allow "recursive" symbolic refs. Only within reason, though */ +#define SYMREF_MAXDEPTH 5/* Include broken references in a do_for_each_ref*() iteration: */ #define DO_FOR_EACH_INCLUDE_BROKEN 0x01
@@ -206,4 +208,8 @@ int rename_ref_available(const char *oldname, const char *newname);*/ int do_for_each_ref (const char *submodule,const char *base,each_ref_fn fn,int trim,int flags,void *cb_data); + +int read_raw_ref (const char *refname,unsigned char *sha1, +struct strbuf *symref,struct strbuf *sb_path, +unsigned int *flags);#endif /* REFS_REFS_INTERNAL_H */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 5/32 refs: add a backend method structure with transaction functions
In reply to David TurnerFrom: Ronnie Sahlberg <[email protected]>
Add a ref structure for storage backend methods. Start by adding a method pointer for the transaction commit function.
Add a function set_refs_backend to switch between storage backends. The files based storage backend is the default.
--- refs.c | 41 +++++++++++++++++++++++++++++++++++++++++ refs.h | 7 +++++++ refs/files-backend.c | 10 ++++++++-- refs/refs-internal.h | 12 ++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-)
refs.c +41 -0
@@ -10,6 +10,39 @@#include "tag.h" /* +* We always have a files backend and it is the default. +*/ +static struct ref_storage_be *the_refs_backend = &refs_be_files; +/* +* List of all available backends +*/ +static struct ref_storage_be *refs_backends = &refs_be_files; + +int set_ref_storage_backend (const char *name) +{ +struct ref_storage_be *be; + +for (be = refs_backends; be; be = be->next) +if (!strcmp (be->name, name)) { + the_refs_backend = be; +return 0 ; + } +return 1 ; +} + +int ref_storage_backend_exists (const char *name) +{ +struct ref_storage_be *be; + +for (be = refs_backends; be; be = be->next) +if (!strcmp (be->name, name)) { + the_refs_backend = be; +return 1 ; + } +return 0 ; +} + +/* * How to handle various characters in refnames: * 0: An acceptable character for refs * 1: End-of-component
@@ -1157,6 +1190,7 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)return do_for_each_ref (NULL ,"" , fn,0 ,DO_FOR_EACH_INCLUDE_BROKEN , cb_data); } +/* This function needs to return a meaningful errno on failure */ static const char *resolve_ref_1(const char *refname, int resolve_flags,
@@ -1261,3 +1295,10 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,strbuf_release (&sb_path);return ret; } + +/* backend functions */ +int ref_transaction_commit (struct ref_transaction *transaction, +struct strbuf *err) +{ +return the_refs_backend->transaction_commit (transaction, err); +}
refs.h +7 -0
@@ -508,4 +508,11 @@ extern int reflog_expire(const char *refname, const unsigned char *sha1,reflog_expiry_cleanup_fn cleanup_fn, void *policy_cb_data); +/* +* Switch to an alternate ref storage backend. +*/ +int set_ref_storage_backend (const char *name); + +int ref_storage_backend_exists (const char *name); +#endif /* REFS_H */
refs/files-backend.c +8 -2
@@ -3012,8 +3012,8 @@ static int ref_update_reject_duplicates(struct string_list *refnames,return 0 ; } -int ref_transaction_commit (struct ref_transaction *transaction, -struct strbuf *err) +static int files_transaction_commit (struct ref_transaction *transaction, +struct strbuf *err) {int ret =0 , i;int n = transaction->nr;
@@ -3399,3 +3399,9 @@ int reflog_expire(const char *refname, const unsigned char *sha1,unlock_ref (lock);return -1 ; } + +struct ref_storage_be refs_be_files = { +NULL , +"files" , + files_transaction_commit, +};
refs/refs-internal.h +12 -0
@@ -212,4 +212,16 @@ int do_for_each_ref(const char *submodule, const char *base,int read_raw_ref (const char *refname,unsigned char *sha1,struct strbuf *symref,struct strbuf *sb_path,unsigned int *flags); + +/* refs backends */ +typedef int ref_transaction_commit_fn (struct ref_transaction *transaction, +struct strbuf *err); + +struct ref_storage_be { +struct ref_storage_be *next; +const char *name; +ref_transaction_commit_fn *transaction_commit; +}; + +extern struct ref_storage_be refs_be_files;#endif /* REFS_REFS_INTERNAL_H */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 6/32 refs: add methods for misc ref operations
In reply to David TurnerFrom: Ronnie Sahlberg <[email protected]>
Add ref backend methods for:read_raw_ref, verify_refname_available, pack_refs, peel_ref, create_symref, resolve_gitlink_ref.
read_raw_ref becomes static because it's not used outside refs.c
--- refs.c | 37 +++++++++++++++++++++++++++++++++++++ refs/files-backend.c | 33 ++++++++++++++++++++++----------- refs/refs-internal.h | 27 +++++++++++++++++++++++---- 3 files changed, 82 insertions(+), 15 deletions(-)
refs.c +37 -0
@@ -1191,6 +1191,14 @@ int for_each_rawref(each_ref_fn fn, void *cb_data) DO_FOR_EACH_INCLUDE_BROKEN, cb_data); } +static int read_raw_ref (const char *refname,unsigned char *sha1, +struct strbuf *symref,struct strbuf *sb_path, +unsigned int *flags) +{ +return the_refs_backend->read_raw_ref (refname, sha1, symref, sb_path, + flags); +} +/* This function needs to return a meaningful errno on failure */ static const char *resolve_ref_1(const char *refname, int resolve_flags,
@@ -1302,3 +1310,32 @@ int ref_transaction_commit(struct ref_transaction *transaction, {return the_refs_backend->transaction_commit (transaction, err); } + +int verify_refname_available (const char *refname,struct string_list *extra, +struct string_list *skip,struct strbuf *err) +{ +return the_refs_backend->verify_refname_available (refname, extra, skip, err); +} + +int pack_refs (unsigned int flags) +{ +return the_refs_backend->pack_refs (flags); +} + +int peel_ref (const char *refname,unsigned char *sha1) +{ +return the_refs_backend->peel_ref (refname, sha1); +} + +int create_symref (const char *ref_target,const char *refs_heads_master, +const char *logmsg) +{ +return the_refs_backend->create_symref (ref_target, refs_heads_master, + logmsg); +} + +int resolve_gitlink_ref (const char *path,const char *refname, +unsigned char *sha1) +{ +return the_refs_backend->resolve_gitlink_ref (path, refname, sha1); +}
refs/files-backend.c +22 -11
@@ -1338,7 +1338,8 @@ static int resolve_gitlink_ref_recursive(struct ref_cache *refs,return resolve_gitlink_ref_recursive (refs, p, sha1, recursion+1 ); } -int resolve_gitlink_ref (const char *path,const char *refname,unsigned char *sha1) +static int files_resolve_gitlink_ref (const char *path,const char *refname, +unsigned char *sha1) {int len =strlen (path), retval;struct strbuf submodule =STRBUF_INIT ;
@@ -1421,9 +1422,9 @@ static int resolve_missing_loose_ref(const char *refname,* * sb_path is workspace: the caller should allocate and free it. */ -int read_raw_ref (const char *refname,unsigned char *sha1, -struct strbuf *symref,struct strbuf *sb_path, -unsigned int *flags) +static int files_read_raw_ref (const char *refname,unsigned char *sha1, +struct strbuf *symref,struct strbuf *sb_path, +unsigned int *flags) {struct strbuf sb_contents =STRBUF_INIT ;int ret =-1 ;
@@ -1576,7 +1577,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)return status; } -int peel_ref (const char *refname,unsigned char *sha1) +static int files_peel_ref (const char *refname,unsigned char *sha1) {int flag;unsigned char base[20 ];
@@ -2136,7 +2137,7 @@ static void prune_refs(struct ref_to_prune *r) } } -int pack_refs (unsigned int flags) +static int files_pack_refs (unsigned int flags) {struct pack_refs_cb_data cbdata;
@@ -2327,10 +2328,10 @@ out:return ret; } -int verify_refname_available (const char *newname, -struct string_list *extras, -struct string_list *skip, -struct strbuf *err) +static int files_verify_refname_available (const char *newname, +struct string_list *extras, +struct string_list *skip, +struct strbuf *err) {struct ref_dir *packed_refs =get_packed_refs (&ref_cache);struct ref_dir *loose_refs =get_loose_refs (&ref_cache);
@@ -2750,7 +2751,9 @@ static int create_symref_locked(struct ref_lock *lock, const char *refname,return 0 ; } -int create_symref (const char *refname,const char *target,const char *logmsg) +static int files_create_symref (const char *refname, +const char *target, +const char *logmsg) {struct strbuf err =STRBUF_INIT ;struct ref_lock *lock;
@@ -3404,4 +3407,12 @@ struct ref_storage_be refs_be_files = {NULL ,"files" , files_transaction_commit, + + files_pack_refs, + files_peel_ref, + files_create_symref, + + files_read_raw_ref, + files_verify_refname_available, + files_resolve_gitlink_ref, };
refs/refs-internal.h +23 -4
@@ -209,18 +209,37 @@ int rename_ref_available(const char *oldname, const char *newname);int do_for_each_ref (const char *submodule,const char *base,each_ref_fn fn,int trim,int flags,void *cb_data); -int read_raw_ref (const char *refname,unsigned char *sha1, -struct strbuf *symref,struct strbuf *sb_path, -unsigned int *flags); -/* refs backends */ typedef int ref_transaction_commit_fn (struct ref_transaction *transaction,struct strbuf *err); +/* misc methods */ +typedef int pack_refs_fn (unsigned int flags); +typedef int peel_ref_fn (const char *refname,unsigned char *sha1); +typedef int create_symref_fn (const char *ref_target, +const char *refs_heads_master, +const char *logmsg); + +/* resolution methods */ +typedef int read_raw_ref_fn (const char *refname,unsigned char *sha1, +struct strbuf *symref,struct strbuf *sb_path, +unsigned int *flags); +typedef int verify_refname_available_fn (const char *refname,struct string_list *extra,struct string_list *skip,struct strbuf *err); +typedef int resolve_gitlink_ref_fn (const char *path,const char *refname, +unsigned char *sha1); +struct ref_storage_be {struct ref_storage_be *next;const char *name;ref_transaction_commit_fn *transaction_commit; + +pack_refs_fn *pack_refs; +peel_ref_fn *peel_ref; +create_symref_fn *create_symref; + +read_raw_ref_fn *read_raw_ref; +verify_refname_available_fn *verify_refname_available; +resolve_gitlink_ref_fn *resolve_gitlink_ref; };extern struct ref_storage_be refs_be_files;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 7/32 refs: add method for do_for_each_ref
In reply to David TurnerAdd a ref backend method for do_for_each_ref.
--- refs.c | 8 ++++++++ refs/files-backend.c | 7 +++++-- refs/refs-internal.h | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-)
refs.c +8 -0
@@ -1339,3 +1339,11 @@ int resolve_gitlink_ref(const char *path, const char *refname, {return the_refs_backend->resolve_gitlink_ref (path, refname, sha1); } + +int do_for_each_ref (const char *submodule,const char *base, +each_ref_fn fn,int trim,int flags, +void *cb_data) +{ +return the_refs_backend->do_for_each_ref (submodule, base, fn, trim, + flags, cb_data); +}
refs/files-backend.c +5 -2
@@ -1679,8 +1679,9 @@ static int do_for_each_entry(struct ref_cache *refs, const char *base,* value, stop the iteration and return that value; otherwise, return * 0. */ -int do_for_each_ref (const char *submodule,const char *base, -each_ref_fn fn,int trim,int flags,void *cb_data) +static int files_do_for_each_ref (const char *submodule,const char *base, +each_ref_fn fn,int trim,int flags, +void *cb_data) {struct ref_entry_cb data;struct ref_cache *refs;
@@ -3415,4 +3416,6 @@ struct ref_storage_be refs_be_files = { files_read_raw_ref, files_verify_refname_available, files_resolve_gitlink_ref, + + files_do_for_each_ref, };
refs/refs-internal.h +5 -0
@@ -227,6 +227,9 @@ typedef int read_raw_ref_fn(const char *refname, unsigned char *sha1,typedef int verify_refname_available_fn (const char *refname,struct string_list *extra,struct string_list *skip,struct strbuf *err);typedef int resolve_gitlink_ref_fn (const char *path,const char *refname,unsigned char *sha1); +typedef int do_for_each_ref_fn (const char *submodule,const char *base, +each_ref_fn fn,int trim,int flags, +void *cb_data);struct ref_storage_be {struct ref_storage_be *next;
@@ -240,6 +243,8 @@ struct ref_storage_be {read_raw_ref_fn *read_raw_ref;verify_refname_available_fn *verify_refname_available;resolve_gitlink_ref_fn *resolve_gitlink_ref; + +do_for_each_ref_fn *do_for_each_ref; };extern struct ref_storage_be refs_be_files;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 8/32 refs: reduce the visibility of do_for_each_ref()
In reply to David TurnerFrom: Ramsay Jones <[email protected]>
Now that we have moved do_for_each_ref into refs.c, it no longer needs to be public.
--- refs.c | 19 +++++++++++-------- refs/refs-internal.h | 6 ------ 2 files changed, 11 insertions(+), 14 deletions(-)
refs.c +11 -8
@@ -1139,6 +1139,17 @@ int head_ref(each_ref_fn fn, void *cb_data)return head_ref_submodule (NULL , fn, cb_data); } +/* +* The common backend for the for_each_*ref* functions +*/ +static int do_for_each_ref (const char *submodule,const char *base, +each_ref_fn fn,int trim,int flags, +void *cb_data) +{ +return the_refs_backend->do_for_each_ref (submodule, base, fn, trim, + flags, cb_data); +} +int for_each_ref (each_ref_fn fn,void *cb_data) {return do_for_each_ref (NULL ,"" , fn,0 ,0 , cb_data);
@@ -1339,11 +1350,3 @@ int resolve_gitlink_ref(const char *path, const char *refname, {return the_refs_backend->resolve_gitlink_ref (path, refname, sha1); } - -int do_for_each_ref (const char *submodule,const char *base, -each_ref_fn fn,int trim,int flags, -void *cb_data) -{ -return the_refs_backend->do_for_each_ref (submodule, base, fn, trim, - flags, cb_data); -}
refs/refs-internal.h +0 -6
@@ -203,12 +203,6 @@ int rename_ref_available(const char *oldname, const char *newname);/* Include broken references in a do_for_each_ref*() iteration: */ #define DO_FOR_EACH_INCLUDE_BROKEN 0x01 -/* -* The common backend for the for_each_*ref* functions -*/ -int do_for_each_ref (const char *submodule,const char *base, -each_ref_fn fn,int trim,int flags,void *cb_data); -/* refs backends */ typedef int ref_transaction_commit_fn (struct ref_transaction *transaction,struct strbuf *err);
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 9/32 refs: add do_for_each_per_worktree_ref
In reply to David TurnerAlternate refs backends might still use files to store per-worktree refs. So the files backend's ref-loading infrastructure should be available to those backends, just for use on per-worktree refs. Add do_for_each_per_worktree_ref, which iterates over per-worktree refs.
--- refs/files-backend.c | 16 ++++++++++++++++ refs/refs-internal.h | 7 +++++++ 2 files changed, 23 insertions(+)
refs/files-backend.c +16 -0
@@ -565,6 +565,10 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)struct ref_entry *old_current_ref;int retval; +if (data->flags &DO_FOR_EACH_PER_WORKTREE_ONLY && +ref_type (entry->name) !=REF_TYPE_PER_WORKTREE ) +return 0 ; +if (!starts_with (entry->name, data->base))return 0 ;
@@ -1701,6 +1705,18 @@ static int files_do_for_each_ref(const char *submodule, const char *base,return do_for_each_entry (refs, base, do_one_ref, &data); } +int do_for_each_per_worktree_ref (const char *submodule,const char *base, +each_ref_fn fn,int trim,int flags, +void *cb_data) +{ +/* +* It's important that this one use the files backend, since +* that's what controls the per-worktree refs +*/ +return files_do_for_each_ref (submodule, base, fn, trim, + flags |DO_FOR_EACH_PER_WORKTREE_ONLY , cb_data); +} +static void unlock_ref (struct ref_lock *lock) {/* Do not free lock->lk -- atexit() still looks at them */
refs/refs-internal.h +7 -0
@@ -203,6 +203,13 @@ int rename_ref_available(const char *oldname, const char *newname);/* Include broken references in a do_for_each_ref*() iteration: */ #define DO_FOR_EACH_INCLUDE_BROKEN 0x01 +/* Only include per-worktree refs in a do_for_each_ref*() iteration */ +#define DO_FOR_EACH_PER_WORKTREE_ONLY 0x02 + +int do_for_each_per_worktree_ref (const char *submodule,const char *base, +each_ref_fn fn,int trim,int flags, +void *cb_data); +/* refs backends */ typedef int ref_transaction_commit_fn (struct ref_transaction *transaction,struct strbuf *err);
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 10/32 refs: add methods for reflog
In reply to David TurnerIn the file-based backend, the reflog piggybacks on the ref lock. Since other backends won't have the same sort of ref lock, ref backends must also handle reflogs.
--- refs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ refs/files-backend.c | 36 ++++++++++++++++++++++++------------ refs/refs-internal.h | 27 +++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 12 deletions(-)
refs.c +46 -0
@@ -1350,3 +1350,49 @@ int resolve_gitlink_ref(const char *path, const char *refname, {return the_refs_backend->resolve_gitlink_ref (path, refname, sha1); } + +int for_each_reflog_ent_reverse (const char *refname,each_reflog_ent_fn fn, +void *cb_data) +{ +return the_refs_backend->for_each_reflog_ent_reverse (refname, fn, + cb_data); +} + +int for_each_reflog_ent (const char *refname,each_reflog_ent_fn fn, +void *cb_data) +{ +return the_refs_backend->for_each_reflog_ent (refname, fn, cb_data); +} + +int for_each_reflog (each_ref_fn fn,void *cb_data) +{ +return the_refs_backend->for_each_reflog (fn, cb_data); +} + +int reflog_exists (const char *refname) +{ +return the_refs_backend->reflog_exists (refname); +} + +int safe_create_reflog (const char *refname,int force_create, +struct strbuf *err) +{ +return the_refs_backend->create_reflog (refname, force_create, err); +} + +int delete_reflog (const char *refname) +{ +return the_refs_backend->delete_reflog (refname); +} + +int reflog_expire (const char *refname,const unsigned char *sha1, +unsigned int flags, +reflog_expiry_prepare_fn prepare_fn, +reflog_expiry_should_prune_fn should_prune_fn, +reflog_expiry_cleanup_fn cleanup_fn, +void *policy_cb_data) +{ +return the_refs_backend->reflog_expire (refname, sha1, flags, + prepare_fn, should_prune_fn, + cleanup_fn, policy_cb_data); +}
refs/files-backend.c +24 -12
@@ -2533,7 +2533,8 @@ static int log_ref_setup(const char *refname, struct strbuf *logfile, struct str } -int safe_create_reflog (const char *refname,int force_create,struct strbuf *err) +static int files_create_reflog (const char *refname,int force_create, +struct strbuf *err) {int ret;struct strbuf sb =STRBUF_INIT ;
@@ -2789,7 +2790,7 @@ static int files_create_symref(const char *refname,return ret; } -int reflog_exists (const char *refname) +static int files_reflog_exists (const char *refname) {struct stat st;
@@ -2797,7 +2798,7 @@ int reflog_exists(const char *refname)S_ISREG (st.st_mode); } -int delete_reflog (const char *refname) +static int files_delete_reflog (const char *refname) {return remove_path (git_path ("logs/%s" , refname)); }
@@ -2841,7 +2842,9 @@ static char *find_beginning_of_line(char *bob, char *scan)return scan; } -int for_each_reflog_ent_reverse (const char *refname,each_reflog_ent_fn fn,void *cb_data) +static int files_for_each_reflog_ent_reverse (const char *refname, +each_reflog_ent_fn fn, +void *cb_data) {struct strbuf sb =STRBUF_INIT ;FILE *logfp;
@@ -2943,7 +2946,8 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, voidreturn ret; } -int for_each_reflog_ent (const char *refname,each_reflog_ent_fn fn,void *cb_data) +static int files_for_each_reflog_ent (const char *refname, +each_reflog_ent_fn fn,void *cb_data) {FILE *logfp;struct strbuf sb =STRBUF_INIT ;
@@ -3005,7 +3009,7 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_datareturn retval; } -int for_each_reflog (each_ref_fn fn,void *cb_data) +static int files_for_each_reflog (each_ref_fn fn,void *cb_data) {int retval;struct strbuf name;
@@ -3315,12 +3319,12 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,return 0 ; } -int reflog_expire (const char *refname,const unsigned char *sha1, -unsigned int flags, -reflog_expiry_prepare_fn prepare_fn, -reflog_expiry_should_prune_fn should_prune_fn, -reflog_expiry_cleanup_fn cleanup_fn, -void *policy_cb_data) +static int files_reflog_expire (const char *refname,const unsigned char *sha1, +unsigned int flags, +reflog_expiry_prepare_fn prepare_fn, +reflog_expiry_should_prune_fn should_prune_fn, +reflog_expiry_cleanup_fn cleanup_fn, +void *policy_cb_data) {static struct lock_file reflog_lock;struct expire_reflog_cb cb;
@@ -3425,6 +3429,14 @@ struct ref_storage_be refs_be_files = {"files" , files_transaction_commit, + files_for_each_reflog_ent, + files_for_each_reflog_ent_reverse, + files_for_each_reflog, + files_reflog_exists, + files_create_reflog, + files_delete_reflog, + files_reflog_expire, + files_pack_refs, files_peel_ref, files_create_symref,
refs/refs-internal.h +27 -0
@@ -214,6 +214,25 @@ int do_for_each_per_worktree_ref(const char *submodule, const char *base,typedef int ref_transaction_commit_fn (struct ref_transaction *transaction,struct strbuf *err); +/* reflog functions */ +typedef int for_each_reflog_ent_fn (const char *refname, +each_reflog_ent_fn fn, +void *cb_data); +typedef int for_each_reflog_ent_reverse_fn (const char *refname, +each_reflog_ent_fn fn, +void *cb_data); +typedef int for_each_reflog_fn (each_ref_fn fn,void *cb_data); +typedef int reflog_exists_fn (const char *refname); +typedef int create_reflog_fn (const char *refname,int force_create, +struct strbuf *err); +typedef int delete_reflog_fn (const char *refname); +typedef int reflog_expire_fn (const char *refname,const unsigned char *sha1, +unsigned int flags, +reflog_expiry_prepare_fn prepare_fn, +reflog_expiry_should_prune_fn should_prune_fn, +reflog_expiry_cleanup_fn cleanup_fn, +void *policy_cb_data); +/* misc methods */ typedef int pack_refs_fn (unsigned int flags);typedef int peel_ref_fn (const char *refname,unsigned char *sha1);
@@ -237,6 +256,14 @@ struct ref_storage_be {const char *name;ref_transaction_commit_fn *transaction_commit; +for_each_reflog_ent_fn *for_each_reflog_ent; +for_each_reflog_ent_reverse_fn *for_each_reflog_ent_reverse; +for_each_reflog_fn *for_each_reflog; +reflog_exists_fn *reflog_exists; +create_reflog_fn *create_reflog; +delete_reflog_fn *delete_reflog; +reflog_expire_fn *reflog_expire; +pack_refs_fn *pack_refs;peel_ref_fn *peel_ref;create_symref_fn *create_symref;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 11/32 refs: add method for initial ref transaction commit
In reply to David Turner--- refs.c | 6 ++++++ refs/files-backend.c | 5 +++-- refs/refs-internal.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-)
refs.c +6 -0
@@ -1396,3 +1396,9 @@ int reflog_expire(const char *refname, const unsigned char *sha1, prepare_fn, should_prune_fn, cleanup_fn, policy_cb_data); } + +int initial_ref_transaction_commit (struct ref_transaction *transaction, +struct strbuf *err) +{ +return the_refs_backend->initial_transaction_commit (transaction, err); +}
refs/files-backend.c +3 -2
@@ -3203,8 +3203,8 @@ static int ref_present(const char *refname,return string_list_has_string (affected_refnames, refname); } -int initial_ref_transaction_commit (struct ref_transaction *transaction, -struct strbuf *err) +static int files_initial_transaction_commit (struct ref_transaction *transaction, +struct strbuf *err) {int ret =0 , i;int n = transaction->nr;
@@ -3428,6 +3428,7 @@ struct ref_storage_be refs_be_files = {NULL ,"files" , files_transaction_commit, + files_initial_transaction_commit, files_for_each_reflog_ent, files_for_each_reflog_ent_reverse,
refs/refs-internal.h +1 -0
@@ -255,6 +255,7 @@ struct ref_storage_be {struct ref_storage_be *next;const char *name;ref_transaction_commit_fn *transaction_commit; +ref_transaction_commit_fn *initial_transaction_commit;for_each_reflog_ent_fn *for_each_reflog_ent;for_each_reflog_ent_reverse_fn *for_each_reflog_ent_reverse;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 12/32 refs: add method for delete_refs
In reply to David TurnerIn the file-based backend, delete_refs has some special optimization to deal with packed refs. In other backends, we might be able to make ref deletion faster by putting all deletions into a single transaction. So we need a special backend function for this.
--- refs.c | 5 +++++ refs/files-backend.c | 3 ++- refs/refs-internal.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-)
refs.c +5 -0
@@ -1402,3 +1402,8 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction, {return the_refs_backend->initial_transaction_commit (transaction, err); } + +int delete_refs (struct string_list *refnames) +{ +return the_refs_backend->delete_refs (refnames); +}
refs/files-backend.c +2 -1
@@ -2246,7 +2246,7 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)return 0 ; } -int delete_refs (struct string_list *refnames) +static int files_delete_refs (struct string_list *refnames) {struct strbuf err =STRBUF_INIT ;int i, result =0 ;
@@ -3441,6 +3441,7 @@ struct ref_storage_be refs_be_files = { files_pack_refs, files_peel_ref, files_create_symref, + files_delete_refs, files_read_raw_ref, files_verify_refname_available,
refs/refs-internal.h +2 -0
@@ -239,6 +239,7 @@ typedef int peel_ref_fn(const char *refname, unsigned char *sha1);typedef int create_symref_fn (const char *ref_target,const char *refs_heads_master,const char *logmsg); +typedef int delete_refs_fn (struct string_list *refnames);/* resolution methods */ typedef int read_raw_ref_fn(const char *refname, unsigned char *sha1,
@@ -268,6 +269,7 @@ struct ref_storage_be {pack_refs_fn *pack_refs;peel_ref_fn *peel_ref;create_symref_fn *create_symref; +delete_refs_fn *delete_refs;read_raw_ref_fn *read_raw_ref;verify_refname_available_fn *verify_refname_available;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 13/32 refs: add methods to init refs db
In reply to David TurnerAlternate refs backends might not need the refs/heads directory and so on, so we make ref db initialization part of the backend.
--- builtin/init-db.c | 20 ++++++++++---------- refs.c | 5 +++++ refs.h | 2 ++ refs/files-backend.c | 16 ++++++++++++++++ refs/refs-internal.h | 2 ++ 5 files changed, 35 insertions(+), 10 deletions(-)
builtin/init-db.c +10 -10
@@ -177,13 +177,7 @@ static int create_default_files(const char *template_path)char junk[2 ];int reinit;int filemode; - -/* -* Create .git/refs/{heads,tags} -*/ -safe_create_dir (git_path_buf (&buf,"refs" ),1 ); -safe_create_dir (git_path_buf (&buf,"refs/heads" ),1 ); -safe_create_dir (git_path_buf (&buf,"refs/tags" ),1 ); +struct strbuf err =STRBUF_INIT ;/* Just look for `init.templatedir` */ git_config (git_init_db_config,NULL );
@@ -207,12 +201,18 @@ static int create_default_files(const char *template_path)*/ if (shared_repository) {adjust_shared_perm (get_git_dir ()); -adjust_shared_perm (git_path_buf (&buf,"refs" )); -adjust_shared_perm (git_path_buf (&buf,"refs/heads" )); -adjust_shared_perm (git_path_buf (&buf,"refs/tags" )); }/* +* We need to create a "refs" dir in any case so that older +* versions of git can tell that this is a repository. +*/ +safe_create_dir (git_path ("refs" ),1 ); + +if (refs_init_db (shared_repository, &err)) +die ("failed to set up refs db: %s" , err.buf); + +/* * Create the default symlink from ".git/HEAD" to the "master" * branch, if it does not exist yet. */
refs.c +5 -0
@@ -1316,6 +1316,11 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags, }/* backend functions */ +int refs_init_db (int shared,struct strbuf *err) +{ +return the_refs_backend->init_db (shared, err); +} +int ref_transaction_commit (struct ref_transaction *transaction,struct strbuf *err) {
refs.h +2 -0
@@ -66,6 +66,8 @@ extern int ref_exists(const char *refname);extern int is_branch (const char *refname); +extern int refs_init_db (int shared,struct strbuf *err); +/* * If refname is a non-symbolic reference that refers to a tag object, * and the tag can be (recursively) dereferenced to a non-tag object,
refs/files-backend.c +16 -0
@@ -3424,9 +3424,25 @@ static int files_reflog_expire(const char *refname, const unsigned char *sha1,return -1 ; } +static int files_init_db (int shared,struct strbuf *err) +{ +/* +* Create .git/refs/{heads,tags} +*/ +safe_create_dir (git_path ("refs/heads" ),1 ); +safe_create_dir (git_path ("refs/tags" ),1 ); +if (shared) { +adjust_shared_perm (git_path ("refs" )); +adjust_shared_perm (git_path ("refs/heads" )); +adjust_shared_perm (git_path ("refs/tags" )); + } +return 0 ; +} +struct ref_storage_be refs_be_files = {NULL ,"files" , + files_init_db, files_transaction_commit, files_initial_transaction_commit,
refs/refs-internal.h +2 -0
@@ -211,6 +211,7 @@ int do_for_each_per_worktree_ref(const char *submodule, const char *base, void *cb_data);/* refs backends */ +typedef int ref_init_db_fn (int shared,struct strbuf *err);typedef int ref_transaction_commit_fn (struct ref_transaction *transaction,struct strbuf *err);
@@ -255,6 +256,7 @@ typedef int do_for_each_ref_fn(const char *submodule, const char *base,struct ref_storage_be {struct ref_storage_be *next;const char *name; +ref_init_db_fn *init_db;ref_transaction_commit_fn *transaction_commit;ref_transaction_commit_fn *initial_transaction_commit;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 14/32 refs: add method to rename refs
In reply to David Turner--- refs.c | 5 +++++ refs/files-backend.c | 4 +++- refs/refs-internal.h | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
refs.c +5 -0
@@ -1412,3 +1412,8 @@ int delete_refs(struct string_list *refnames) {return the_refs_backend->delete_refs (refnames); } + +int rename_ref (const char *oldref,const char *newref,const char *logmsg) +{ +return the_refs_backend->rename_ref (oldref, newref, logmsg); +}
refs/files-backend.c +3 -1
@@ -2368,7 +2368,8 @@ static int commit_ref_update(struct ref_lock *lock, const unsigned char *sha1, const char *logmsg, int flags, struct strbuf *err); -int rename_ref (const char *oldrefname,const char *newrefname,const char *logmsg) +static int files_rename_ref (const char *oldrefname,const char *newrefname, +const char *logmsg) {unsigned char sha1[20 ], orig_sha1[20 ];int flag =0 , logmoved =0 ;
@@ -3458,6 +3459,7 @@ struct ref_storage_be refs_be_files = { files_peel_ref, files_create_symref, files_delete_refs, + files_rename_ref, files_read_raw_ref, files_verify_refname_available,
refs/refs-internal.h +8 -0
@@ -195,6 +195,11 @@ const char *find_descendant_ref(const char *dirname,const struct string_list *extras, const struct string_list *skip); +/* +* Check if the new name does not conflict with any existing refs +* (other than possibly the old ref). Return 0 if the ref can be +* renamed to the new name. +*/ int rename_ref_available (const char *oldname,const char *newname);/* We allow "recursive" symbolic refs. Only within reason, though */
@@ -241,6 +246,8 @@ typedef int create_symref_fn(const char *ref_target,const char *refs_heads_master, const char *logmsg);typedef int delete_refs_fn (struct string_list *refnames); +typedef int rename_ref_fn (const char *oldref,const char *newref, +const char *logmsg);/* resolution methods */ typedef int read_raw_ref_fn(const char *refname, unsigned char *sha1,
@@ -272,6 +279,7 @@ struct ref_storage_be {peel_ref_fn *peel_ref;create_symref_fn *create_symref;delete_refs_fn *delete_refs; +rename_ref_fn *rename_ref;read_raw_ref_fn *read_raw_ref;verify_refname_available_fn *verify_refname_available;
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 15/32 refs: handle non-normal ref renames
In reply to David TurnerForbid cross-backend ref renames. This would be pretty weird, but since it will break, we should prevent it.
Also make the files backend deal with all non-normal ref renames.
--- refs.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
refs.c +11 -1
@@ -1415,5 +1415,15 @@ int delete_refs(struct string_list *refnames)int rename_ref (const char *oldref,const char *newref,const char *logmsg) { -return the_refs_backend->rename_ref (oldref, newref, logmsg); +if ((ref_type (oldref) ==REF_TYPE_NORMAL ) != + (ref_type (newref) ==REF_TYPE_NORMAL )) { +return error ( +_ ("Both ref arguments to rename_ref must be normal, " +"or both must be per-worktree/pseudorefs" )); + } +if (ref_type (oldref) ==REF_TYPE_NORMAL ) +/* The files backend always deals with non-normal refs */ +return the_refs_backend->rename_ref (oldref, newref, logmsg); +else +return refs_be_files.rename_ref (oldref, newref, logmsg); }
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 16/32 refs: make lock generic
In reply to David TurnerInstead of using a files-backend-specific struct ref_lock, the generic ref_transaction struct should provide a void pointer that backends can use for their own lock data.
--- refs/files-backend.c | 29 ++++++++++++++++------------- refs/refs-internal.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-)
refs/files-backend.c +16 -13
@@ -3074,11 +3074,12 @@ static int files_transaction_commit(struct ref_transaction *transaction,*/ for (i =0 ; i < n; i++) {struct ref_update *update = updates[i]; +struct ref_lock *lock;if ((update->flags &REF_HAVE_NEW ) &&is_null_sha1 (update->new_sha1)) update->flags |=REF_DELETING ; - update->lock = lock_ref_sha1_basic( + lock = lock_ref_sha1_basic( update->refname, ((update->flags & REF_HAVE_OLD) ? update->old_sha1 : NULL),
@@ -3086,7 +3087,8 @@ static int files_transaction_commit(struct ref_transaction *transaction, update->flags, &update->type, err); -if (!update->lock) { + update->backend_data = lock; +if (!lock) {char *reason; ret = (errno ==ENOTDIR )
@@ -3104,12 +3106,12 @@ static int files_transaction_commit(struct ref_transaction *transaction, (update->flags & REF_NODEREF));if (!overwriting_symref && - !hashcmp (update->lock->old_oid.hash, update->new_sha1)) { + !hashcmp (lock->old_oid.hash, update->new_sha1)) {/* * The reference already has the desired * value, so we don't need to write it. */ - }else if (write_ref_to_lockfile (update->lock, + }else if (write_ref_to_lockfile (lock, update->new_sha1, err)) {char *write_err =strbuf_detach (err,NULL );
@@ -3118,7 +3120,7 @@ static int files_transaction_commit(struct ref_transaction *transaction,* The lock was freed upon failure of * write_ref_to_lockfile(): */ - update->lock =NULL ; + update->backend_data =NULL ;strbuf_addf (err,"cannot update the ref '%s': %s" , update->refname, write_err);
@@ -3134,7 +3136,7 @@ static int files_transaction_commit(struct ref_transaction *transaction,* We didn't have to write anything to the lockfile. * Close it to free up the file descriptor: */ -if (close_ref (update->lock)) { +if (close_ref (lock)) {strbuf_addf (err,"Couldn't close %s.lock" , update->refname); goto cleanup;
@@ -3147,16 +3149,16 @@ static int files_transaction_commit(struct ref_transaction *transaction,struct ref_update *update = updates[i];if (update->flags &REF_NEEDS_COMMIT ) { -if (commit_ref_update (update->lock, +if (commit_ref_update (update->backend_data, update->new_sha1, update->msg, update->flags, err)) {/* freed by commit_ref_update(): */ - update->lock =NULL ; + update->backend_data =NULL ; ret =TRANSACTION_GENERIC_ERROR ; goto cleanup; }else {/* freed by commit_ref_update(): */ - update->lock =NULL ; + update->backend_data =NULL ; } } }
@@ -3164,16 +3166,17 @@ static int files_transaction_commit(struct ref_transaction *transaction,/* Perform deletes now that updates are safely completed */ for (i =0 ; i < n; i++) {struct ref_update *update = updates[i]; +struct ref_lock *lock = update->backend_data;if (update->flags &REF_DELETING ) { -if (delete_ref_loose (update->lock, update->type, err)) { +if (delete_ref_loose (lock, update->type, err)) { ret =TRANSACTION_GENERIC_ERROR ; goto cleanup; }if (!(update->flags &REF_ISPRUNING ))string_list_append (&refs_to_delete, - update->lock->ref_name); + lock->ref_name); } }
@@ -3189,8 +3192,8 @@ cleanup: transaction->state =REF_TRANSACTION_CLOSED ;for (i =0 ; i < n; i++) -if (updates[i]->lock) -unlock_ref (updates[i]->lock); +if (updates[i]->backend_data) +unlock_ref (updates[i]->backend_data);string_list_clear (&refs_to_delete,0 );string_list_clear (&affected_refnames,0 );return ret;
refs/refs-internal.h +1 -1
@@ -144,7 +144,7 @@ struct ref_update {* REF_DELETING, and REF_ISPRUNING: */ unsigned int flags; -struct ref_lock *lock; +void *backend_data;int type;char *msg;const char refname[FLEX_ARRAY ];
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 17/32 refs: move duplicate check to common code
In reply to David TurnerThe check for duplicate refnames in a transaction is needed for all backends, so move it to the common code.
ref_transaction_commit_fn gains a new argument, the sorted string_list of affected refnames.
--- refs.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++-- refs/files-backend.c | 57 ++++--------------------------------------- refs/refs-internal.h | 1 + 3 files changed, 73 insertions(+), 54 deletions(-)
refs.c +67 -2
@@ -1140,6 +1140,36 @@ int head_ref(each_ref_fn fn, void *cb_data) }/* +* Return 1 if there are any duplicate refnames in the updates in +* `transaction`, and fill in err with an appropriate error message. +* Fill in `refnames` with the refnames from the transaction. +*/ +static int get_affected_refnames (struct ref_transaction *transaction, +struct string_list *refnames, +struct strbuf *err) +{ +int i, n = transaction->nr; +struct ref_update **updates; + +assert (err); + + updates = transaction->updates; +/* Fail if a refname appears more than once in the transaction: */ +for (i =0 ; i < n; i++) +string_list_append (refnames, updates[i]->refname); +string_list_sort (refnames); + +for (i =1 ; i < n; i++) +if (!strcmp (refnames->items[i -1 ].string, refnames->items[i].string)) { +strbuf_addf (err, +"Multiple updates for ref '%s' not allowed." , + refnames->items[i].string); +return 1 ; + } +return 0 ; +} + +/* * The common backend for the for_each_*ref* functions */ static int do_for_each_ref(const char *submodule, const char *base,
@@ -1324,7 +1354,29 @@ int refs_init_db(int shared, struct strbuf *err)int ref_transaction_commit (struct ref_transaction *transaction,struct strbuf *err) { -return the_refs_backend->transaction_commit (transaction, err); +int ret =-1 ; +struct string_list affected_refnames =STRING_LIST_INIT_NODUP ; + +assert (err); + +if (transaction->state !=REF_TRANSACTION_OPEN ) +die ("BUG: commit called for transaction that is not open" ); + +if (!transaction->nr) { + transaction->state =REF_TRANSACTION_CLOSED ; +return 0 ; + } + +if (get_affected_refnames (transaction, &affected_refnames, err)) { + ret =TRANSACTION_GENERIC_ERROR ; + goto done; + } + + ret = the_refs_backend->transaction_commit (transaction, + &affected_refnames, err); +done: +string_list_clear (&affected_refnames,0 ); +return ret; } int verify_refname_available(const char *refname, struct string_list *extra,
@@ -1405,7 +1457,20 @@ int reflog_expire(const char *refname, const unsigned char *sha1,int initial_ref_transaction_commit (struct ref_transaction *transaction,struct strbuf *err) { -return the_refs_backend->initial_transaction_commit (transaction, err); +struct string_list affected_refnames =STRING_LIST_INIT_NODUP ; +int ret; + +if (get_affected_refnames (transaction, + &affected_refnames, err)) { + ret =TRANSACTION_GENERIC_ERROR ; + goto done; + } + ret = the_refs_backend->initial_transaction_commit (transaction, + &affected_refnames, + err); +done: +string_list_clear (&affected_refnames,0 ); +return ret; }int delete_refs (struct string_list *refnames)
refs/files-backend.c +5 -52
117 lines not on this page · raw message
refs/refs-internal.h +1 -0
@@ -218,6 +218,7 @@ int do_for_each_per_worktree_ref(const char *submodule, const char *base,/* refs backends */ typedef int ref_init_db_fn (int shared,struct strbuf *err);typedef int ref_transaction_commit_fn (struct ref_transaction *transaction, +struct string_list *affected_refnames,struct strbuf *err);/* reflog functions */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 18/32 refs: allow log-only updates
In reply to David TurnerThe refs infrastructure learns about log-only ref updates, which only update the reflog. Later, we will use this to separate symbolic reference resolution from ref updating.
--- refs/files-backend.c | 15 ++++++++++----- refs/refs-internal.h | 7 +++++++ 2 files changed, 17 insertions(+), 5 deletions(-)
refs/files-backend.c +10 -5
@@ -2711,7 +2711,7 @@ static int commit_ref_update(struct ref_lock *lock, } } } -if (commit_ref (lock)) { +if (!(flags &REF_LOG_ONLY ) &&commit_ref (lock)) {error ("Couldn't set %s" , lock->ref_name);unlock_ref (lock);return -1 ;
@@ -3065,7 +3065,8 @@ static int files_transaction_commit(struct ref_transaction *transaction, goto cleanup; }if ((update->flags &REF_HAVE_NEW ) && - !(update->flags &REF_DELETING )) { + !(update->flags &REF_DELETING ) && + !(update->flags &REF_LOG_ONLY )) {int overwriting_symref = ((update->type &REF_ISSYMREF ) && (update->flags &REF_NODEREF ));
@@ -3095,7 +3096,9 @@ static int files_transaction_commit(struct ref_transaction *transaction, update->flags |=REF_NEEDS_COMMIT ; } } -if (!(update->flags &REF_NEEDS_COMMIT )) { + +if (!(update->flags &REF_LOG_ONLY ) && + !(update->flags &REF_NEEDS_COMMIT )) {/* * We didn't have to write anything to the lockfile. * Close it to free up the file descriptor:
@@ -3112,7 +3115,8 @@ static int files_transaction_commit(struct ref_transaction *transaction,for (i =0 ; i < n; i++) {struct ref_update *update = updates[i]; -if (update->flags &REF_NEEDS_COMMIT ) { +if (update->flags &REF_NEEDS_COMMIT || + update->flags &REF_LOG_ONLY ) {if (commit_ref_update (update->backend_data, update->new_sha1, update->msg, update->flags, err)) {
@@ -3132,7 +3136,8 @@ static int files_transaction_commit(struct ref_transaction *transaction,struct ref_update *update = updates[i];struct ref_lock *lock = update->backend_data; -if (update->flags &REF_DELETING ) { +if (update->flags &REF_DELETING && + !(update->flags &REF_LOG_ONLY )) {if (delete_ref_loose (lock, update->type, err)) { ret =TRANSACTION_GENERIC_ERROR ; goto cleanup;
refs/refs-internal.h +7 -0
@@ -43,6 +43,13 @@*/ /* +* Used as a flag in ref_update::flags when we want to log a ref +* update but not actually perform it. This is used when a symbolic +* ref update is split up. +*/ +#define REF_LOG_ONLY 0x80 + +/* * Return true iff refname is minimally safe. "Safe" here means that * deleting a loose reference by this name will not do any damage, for * example by causing a file that is not a reference to be deleted.
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 19/32 refs: don't dereference on rename
In reply to David TurnerWhen renaming refs, don't dereference either the origin or the destination before renaming.
The origin does not need to be dereferenced because it is presently forbidden to rename symbolic refs.
Not dereferencing the destination fixes a bug where renaming on top of a broken symref would use the pointed-to ref name for the moved reflog.
Add a test for the reflog bug.
--- refs/files-backend.c | 15 +++++++++------ t/t3200-branch.sh | 9 +++++++++ 2 files changed, 18 insertions(+), 6 deletions(-)
refs/files-backend.c +9 -6
@@ -2372,7 +2372,7 @@ static int files_rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg) {unsigned char sha1[20 ], orig_sha1[20 ]; -int flag =0 , logmoved =0 ; +int flag =0 , logmoved =0 , resolve_flags;struct ref_lock *lock;struct stat loginfo;int log = !lstat (git_path ("logs/%s" , oldrefname), &loginfo);
@@ -2382,7 +2382,8 @@ static int files_rename_ref(const char *oldrefname, const char *newrefname,if (log &&S_ISLNK (loginfo.st_mode))return error ("reflog for %s is a symlink" , oldrefname); - symref =resolve_ref_unsafe (oldrefname,RESOLVE_REF_READING , + resolve_flags =RESOLVE_REF_READING |RESOLVE_REF_NO_RECURSE ; + symref =resolve_ref_unsafe (oldrefname, resolve_flags, orig_sha1, &flag);if (flag &REF_ISSYMREF ) return error("refname %s is a symbolic ref, renaming it is not supported",
@@ -2402,8 +2403,8 @@ static int files_rename_ref(const char *oldrefname, const char *newrefname, goto rollback; } -if (!read_ref_full (newrefname,RESOLVE_REF_READING , sha1,NULL ) && -delete_ref (newrefname, sha1,REF_NODEREF )) { +if (!read_ref_full (newrefname, resolve_flags, sha1,NULL ) && +delete_ref (newrefname,NULL ,REF_NODEREF )) {if (errno==EISDIR ) {struct strbuf path =STRBUF_INIT ;int result;
@@ -2427,7 +2428,8 @@ static int files_rename_ref(const char *oldrefname, const char *newrefname, logmoved = log; - lock =lock_ref_sha1_basic (newrefname,NULL ,NULL ,NULL ,0 ,NULL , &err); + lock =lock_ref_sha1_basic (newrefname,NULL ,NULL ,NULL ,REF_NODEREF , +NULL , &err);if (!lock) {error ("unable to rename '%s' to '%s': %s" , oldrefname, newrefname, err.buf);strbuf_release (&err);
@@ -2445,7 +2447,8 @@ static int files_rename_ref(const char *oldrefname, const char *newrefname,return 0 ; rollback: - lock =lock_ref_sha1_basic (oldrefname,NULL ,NULL ,NULL ,0 ,NULL , &err); + lock =lock_ref_sha1_basic (oldrefname,NULL ,NULL ,NULL ,REF_NODEREF , +NULL , &err);if (!lock) {error ("unable to lock %s for rollback: %s" , oldrefname, err.buf);strbuf_release (&err);
t/t3200-branch.sh +9 -0
@@ -79,6 +79,15 @@ test_expect_success 'git branch -m dumps usage' ' test_i18ngrep "branch name required" err ' +test_expect_success 'git branch -m m broken_symref should work' ' + test_when_finished "git branch -D broken_symref" && + git branch -l m && + git symbolic-ref refs/heads/broken_symref refs/heads/i_am_broken && + git branch -m m broken_symref && + git reflog exists refs/heads/broken_symref && + test_must_fail git reflog exists refs/heads/i_am_broken +' + test_expect_success 'git branch -m m m/m should work' ' git branch -l m && git branch -m m m/m &&
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 20/32 refs: on symref reflog expire, lock symref not referrent
In reply to David TurnerWhen locking a symbolic ref to expire a reflog, lock the symbolic ref (using REF_NODEREF) instead of its referent.
Add a test for this.
--- refs/files-backend.c | 3 ++- t/t1410-reflog.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-)
refs/files-backend.c +2 -1
@@ -3309,7 +3309,8 @@ static int files_reflog_expire(const char *refname, const unsigned char *sha1,* reference itself, plus we might need to update the * reference if --updateref was specified: */ - lock =lock_ref_sha1_basic (refname, sha1,NULL ,NULL ,0 , &type, &err); + lock =lock_ref_sha1_basic (refname, sha1,NULL ,NULL ,REF_NODEREF , + &type, &err);if (!lock) {error ("cannot lock ref '%s': %s" , refname, err.buf);strbuf_release (&err);
t/t1410-reflog.sh +10 -0
@@ -338,4 +338,14 @@ test_expect_failure 'reflog with non-commit entries displays all entries' ' test_line_count = 3 actual ' +test_expect_success 'reflog expire operates on symref not referrent' ' + git branch -l the_symref && + git branch -l referrent && + git update-ref referrent HEAD && + git symbolic-ref refs/heads/the_symref refs/heads/referrent && + test_when_finished "rm -f .git/refs/heads/referrent.lock" && + touch .git/refs/heads/referrent.lock && + git reflog expire --expire=all the_symref +' + test_done
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 21/32 refs: resolve symbolic refs first
In reply to David TurnerBefore committing ref updates, split symbolic ref updates into two
parts: an update to the underlying ref, and a log-only update to the symbolic ref. This ensures that both references are locked correctly while their reflogs are updated.
It is still possible to confuse git by concurrent updates, since the splitting of symbolic refs does not happen under lock. So a symbolic ref could be replaced by a plain ref in the middle of this operation, which would lead to reflog discontinuities and missed old-ref checks.
All callers to lock_ref_sha1_basic outside of ref_transaction_commit now set REF_NODEREF. And ref_transaction_commit only happens on already-derefernced refs. So we can assume REF_NODEREF when resolving inside this function.
--- refs.c | 69 ++++++++++++++++++++++++++ refs/files-backend.c | 137 ++++++++++++++++++++++++++------------------------- refs/refs-internal.h | 8 +++ 3 files changed, 148 insertions(+), 66 deletions(-)
refs.c +69 -0
@@ -1351,6 +1351,71 @@ int refs_init_db(int shared, struct strbuf *err)return the_refs_backend->init_db (shared, err); } +/* +* Special case for symbolic refs when REF_NODEREF is not turned on. +* Dereference them here, mark them REF_LOG_ONLY, and add an update +* for the underlying ref. +*/ +static int dereference_symrefs (struct ref_transaction *transaction, +struct strbuf *err) +{ +int i; +int nr = transaction->nr; + +for (i =0 ; i < nr; i++) { +struct ref_update *update = transaction->updates[i]; +const char *resolved; +unsigned char sha1[20 ]; +int resolve_flags =0 ; +int mustexist = update->flags &REF_HAVE_OLD && + !is_null_sha1 (update->old_sha1); +int deleting = (update->flags &REF_HAVE_NEW ) && +is_null_sha1 (update->new_sha1); + +if (mustexist) + resolve_flags |=RESOLVE_REF_READING ; +if (deleting) + resolve_flags |=RESOLVE_REF_ALLOW_BAD_NAME | +RESOLVE_REF_NO_RECURSE ; + +if (strcmp (update->refname,"HEAD" )) + update->flags |=REF_IS_NOT_HEAD ; + + resolved =resolve_ref_unsafe (update->refname, resolve_flags, + sha1, &update->type); +if (!resolved) { +/* +* We may notice this breakage later and die +* with a sensible error message +*/ + update->type |=REF_ISBROKEN ; +continue ; + } + +hashcpy (update->read_sha1, sha1); + +if (update->flags &REF_NODEREF || + !(update->type &REF_ISSYMREF )) +continue ; + +/* Create a new transaction for the underlying ref */ +if (ref_transaction_update (transaction, + resolved, + update->new_sha1, + (update->flags &REF_HAVE_OLD ) ? + update->old_sha1 :NULL , + update->flags & ~REF_IS_NOT_HEAD , + update->msg, err)) +return -1 ; + +/* Make the symbolic ref update non-recursive */ + update->flags |=REF_LOG_ONLY |REF_NODEREF ; + update->flags &= ~REF_HAVE_OLD ; + } + +return 0 ; +} +int ref_transaction_commit (struct ref_transaction *transaction,struct strbuf *err) {
@@ -1367,6 +1432,10 @@ int ref_transaction_commit(struct ref_transaction *transaction,return 0 ; } + ret =dereference_symrefs (transaction, err); +if (ret) + goto done; +if (get_affected_refnames (transaction, &affected_refnames, err)) { ret =TRANSACTION_GENERIC_ERROR ; goto done;
refs/files-backend.c +71 -66
237 lines not on this page · raw message
refs/refs-internal.h +8 -0
@@ -49,6 +49,8 @@*/ #define REF_LOG_ONLY 0x80 +#define REF_IS_NOT_HEAD 0x100 +/* * Return true iff refname is minimally safe. "Safe" here means that * deleting a loose reference by this name will not do any damage, for
@@ -147,6 +149,12 @@ struct ref_update {*/ unsigned char old_sha1[20 ];/* +* During the symbolic ref split stage, we resolve refs. +* We'll re-resolve non-symbolic refs once they are locked, +* but we store this to avoid re-resolving symbolic refs. +*/ +unsigned char read_sha1[20 ]; +/* * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF, * REF_DELETING, and REF_ISPRUNING: */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 22/32 refs: always handle non-normal refs in files backend
In reply to David TurnerAlways handle non-normal (per-worktree or pseudo) refs in the files backend instead of alternate backends.
Sometimes a ref transaction will update both a per-worktree ref and a normal ref. For instance, an ordinary commit might update refs/heads/master and HEAD (or at least HEAD's reflog).
Updates to normal refs continue to go through the chosen backend.
Updates to non-normal refs are moved to a separate files backend transaction.
--- refs.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 20 deletions(-)
refs.c +90 -20
@@ -9,6 +9,11 @@#include "object.h" #include "tag.h" +static const char split_transaction_fail_warning[] =N_ ( +"A ref transaction was split across two refs backends. Part of the " +"transaction succeeded, but then the update to the per-worktree refs " +"failed. Your repository may be in an inconsistent state." ); +/* * We always have a files backend and it is the default. */
@@ -791,6 +796,13 @@ void ref_transaction_free(struct ref_transaction *transaction)free (transaction); } +static void add_update_obj (struct ref_transaction *transaction, +struct ref_update *update) +{ +ALLOC_GROW (transaction->updates, transaction->nr +1 , transaction->alloc); + transaction->updates[transaction->nr++] = update; +} +static struct ref_update *add_update (struct ref_transaction *transaction,const char *refname) {
@@ -798,8 +810,7 @@ static struct ref_update *add_update(struct ref_transaction *transaction,struct ref_update *update =xcalloc (1 ,sizeof (*update) + len);memcpy ((char *)update->refname, refname, len);/* includes NUL */ -ALLOC_GROW (transaction->updates, transaction->nr +1 , transaction->alloc); - transaction->updates[transaction->nr++] = update; +add_update_obj (transaction, update);return update; }
@@ -1416,11 +1427,37 @@ static int dereference_symrefs(struct ref_transaction *transaction,return 0 ; } -int ref_transaction_commit (struct ref_transaction *transaction, -struct strbuf *err) +/* +* Move all non-normal ref updates into a specially-created +* files-backend transaction +*/ +static int move_abnormal_ref_updates (struct ref_transaction *transaction, +struct ref_transaction *files_transaction, +struct strbuf *err) +{ +int i, normal_nr =0 ; + +for (i =0 ; i < transaction->nr; i++) { +struct ref_update *update = transaction->updates[i]; + +if (ref_type (update->refname) ==REF_TYPE_NORMAL ) + transaction->updates[normal_nr++] = update; +else +add_update_obj (files_transaction, update); + } + + transaction->nr = normal_nr; +return 0 ; +} + +static int do_ref_transaction_commit (struct ref_transaction *transaction, +struct strbuf *err, +ref_transaction_commit_fn *commit_fn) {int ret =-1 ;struct string_list affected_refnames =STRING_LIST_INIT_NODUP ; +struct string_list files_affected_refnames =STRING_LIST_INIT_NODUP ; +struct ref_transaction *files_transaction =NULL ;assert (err);
@@ -1436,18 +1473,60 @@ int ref_transaction_commit(struct ref_transaction *transaction,if (ret) goto done; +if (the_refs_backend != &refs_be_files) { + files_transaction =ref_transaction_begin (err); +if (!files_transaction) + goto done; + + ret =move_abnormal_ref_updates (transaction, files_transaction, + err); +if (ret) + goto done; + +/* files backend commit */ +if (get_affected_refnames (files_transaction, + &files_affected_refnames, + err)) { + ret =TRANSACTION_GENERIC_ERROR ; + goto done; + } + } + +/* main backend commit */ if (get_affected_refnames (transaction, &affected_refnames, err)) { ret =TRANSACTION_GENERIC_ERROR ; goto done; } - ret = the_refs_backend->transaction_commit (transaction, - &affected_refnames, err); + ret =commit_fn (transaction, &affected_refnames, err); +if (ret) + goto done; + +if (files_transaction) { + ret = refs_be_files.transaction_commit (files_transaction, + &files_affected_refnames, + err); +if (ret) { +warning (split_transaction_fail_warning); + goto done; + } + } + done:string_list_clear (&affected_refnames,0 ); +string_list_clear (&files_affected_refnames,0 ); +if (files_transaction) +ref_transaction_free (files_transaction);return ret; } +int ref_transaction_commit (struct ref_transaction *transaction, +struct strbuf *err) +{ +return do_ref_transaction_commit (transaction, err, + the_refs_backend->transaction_commit); +} +int verify_refname_available (const char *refname,struct string_list *extra,struct string_list *skip,struct strbuf *err) {
@@ -1467,6 +1546,9 @@ int peel_ref(const char *refname, unsigned char *sha1)int create_symref (const char *ref_target,const char *refs_heads_master,const char *logmsg) { +if (ref_type (ref_target) !=REF_TYPE_NORMAL ) +return refs_be_files.create_symref (ref_target, refs_heads_master, + logmsg);return the_refs_backend->create_symref (ref_target, refs_heads_master, logmsg); }
@@ -1526,20 +1608,8 @@ int reflog_expire(const char *refname, const unsigned char *sha1,int initial_ref_transaction_commit (struct ref_transaction *transaction,struct strbuf *err) { -struct string_list affected_refnames =STRING_LIST_INIT_NODUP ; -int ret; - -if (get_affected_refnames (transaction, - &affected_refnames, err)) { - ret =TRANSACTION_GENERIC_ERROR ; - goto done; - } - ret = the_refs_backend->initial_transaction_commit (transaction, - &affected_refnames, - err); -done: -string_list_clear (&affected_refnames,0 ); -return ret; +return do_ref_transaction_commit (transaction, err, + the_refs_backend->initial_transaction_commit); }int delete_refs (struct string_list *refnames)
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 23/32 init: allow alternate ref strorage to be set for new repos
In reply to David Turnergit init learns a new argument --ref-storage. Presently, only "files" is supported, but later we will add other storage backends.
When this argument is used, the repository's extensions.refStorage configuration value is set (as well as core.repositoryformatversion), and the ref storage backend's initdb function is used to set up the ref database.
--- Documentation/git-init-db.txt | 2 +- Documentation/git-init.txt | 7 +++++- builtin/init-db.c | 44 +++++++++++++++++++++++++++------- cache.h | 2 ++ contrib/completion/git-completion.bash | 3 ++- path.c | 29 ++++++++++++++++++++-- refs.c | 2 ++ refs.h | 5 ++++ setup.c | 12 ++++++++++ t/t0001-init.sh | 25 +++++++++++++++++++ 10 files changed, 118 insertions(+), 13 deletions(-)
Documentation/git-init-db.txt +1 -1
@@ -9,7 +9,7 @@ git-init-db - Creates an empty Git repository SYNOPSIS -------- [verse] -'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir <git dir>] [--shared[=<permissions>]] +'git init-db' [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir <git dir>] [--shared[=<permissions>]] [--ref-storage=<name>] DESCRIPTION
Documentation/git-init.txt +6 -1
@@ -12,7 +12,7 @@ SYNOPSIS 'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir <git dir>] [--shared[=<permissions>]] [directory] - + [--ref-storage=<name>] DESCRIPTION -----------
@@ -113,6 +113,11 @@ does not exist, it will be created. -- +--ref-storage=<name>:: +Type of refs storage backend. Default is to use the original "files" +storage, which stores ref data in files in `$GIT_DIR/refs` and +`$GIT_DIR/packed-refs`. + TEMPLATE DIRECTORY ------------------
builtin/init-db.c +36 -8
85 lines not on this page · raw message
cache.h +2 -0
@@ -734,6 +734,8 @@ extern enum object_creation_mode object_creation_mode;extern char *notes_ref_name; +extern const char *ref_storage_backend; +extern int grafts_replace_parents;/*
contrib/completion/git-completion.bash +2 -1
@@ -1362,7 +1362,8 @@ _git_init () return ;; --*) - __gitcomp "--quiet --bare --template= --shared --shared=" + __gitcomp "--quiet --bare --template= --shared --shared= + --ref-storage=" return ;; esac
path.c +27 -2
@@ -2,6 +2,7 @@* Utilities for paths and pathnames */ #include "cache.h" +#include "refs.h" #include "strbuf.h" #include "string-list.h" #include "dir.h"
@@ -511,8 +512,32 @@ int validate_headref(const char *path)int fd;ssize_t len; -if (lstat (path, &st) <0 ) -return -1 ; +if (lstat (path, &st) <0 ) { +int backend_type_set; +struct strbuf config_path =STRBUF_INIT ; +char *pathdup =xstrdup (path); +char *git_dir =dirname (pathdup); +char *storage =NULL ; + +strbuf_addf (&config_path,"%s/%s" , git_dir,"config" ); +free (pathdup); + +if (git_config_from_file (ref_storage_backend_config, + config_path.buf, &storage)) { +strbuf_release (&config_path); +return -1 ; + } + + backend_type_set = !!storage; +free ((void *)storage); +strbuf_release (&config_path); +/* +* Alternate backends are assumed to keep HEAD +* in a valid state, so there's no need to do +* further validation. +*/ +return backend_type_set ?0 :-1 ; + }/* Make sure it is a "refs/.." symlink */ if (S_ISLNK (st.st_mode)) {
refs.c +2 -0
@@ -23,6 +23,8 @@ static struct ref_storage_be *the_refs_backend = &refs_be_files;*/ static struct ref_storage_be *refs_backends = &refs_be_files; +const char *ref_storage_backend ="files" ; +int set_ref_storage_backend (const char *name) {struct ref_storage_be *be;
refs.h +5 -0
@@ -511,6 +511,11 @@ extern int reflog_expire(const char *refname, const unsigned char *sha1, void *policy_cb_data);/* +* Read the refdb storage backend name out of the config file +*/ +int ref_storage_backend_config (const char *var,const char *value,void *ptr); + +/* * Switch to an alternate ref storage backend. */ int set_ref_storage_backend (const char *name);
setup.c +12 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "dir.h" +#include "refs.h" #include "string-list.h" static int inside_git_dir =-1 ;
@@ -263,6 +264,15 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)return ret; } +int ref_storage_backend_config (const char *var,const char *value,void *ptr) +{ +char **cdata = ptr; + +if (!strcmp (var,"extensions.refstorage" )) + *cdata =xstrdup (value); +return 0 ; +} +/* * Test if it looks like we're at a git directory. * We want to see:
@@ -390,6 +400,8 @@ static int check_repo_format(const char *var, const char *value, void *cb) ; else if (!strcmp(ext, "preciousobjects")) repository_format_precious_objects =git_config_bool (var, value); + else if (!strcmp(ext, "refstorage")) + ref_storage_backend =xstrdup (value); else string_list_append(&unknown_extensions, ext); }
t/t0001-init.sh +25 -0
@@ -174,6 +174,31 @@ test_expect_success 'reinit' ' test_i18ncmp again/empty again/err2 ' +test_expect_success 'init with bogus storage backend fails' ' + + ( + mkdir again2 && + cd again2 && + test_must_fail git init --ref-storage=test >out2 2>err2 && + test_i18ngrep "Unknown ref storage backend test" err2 + ) +' + +test_expect_failure 'reinit with changed storage backend fails' ' + + ( + mkdir again3 && + cd again3 && + git init >out1 2>err1 && + git init --ref-storage=test >out2 2>err2 + ) && + test_i18ngrep "Initialized empty" again3/out1 && + test_i18ngrep "Reinitialized existing" again3/out2 && + >again3/empty && + test_i18ncmp again3/empty again3/err1 && + test_i18ncmp again3/empty again3/err2 +' + test_expect_success 'init with --template' ' mkdir template-source && echo content >template-source/file &&
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 24/32 refs: check submodules' ref storage config
In reply to David TurnerAll submodules must have the same ref storage (for now). Confirm that this is so before attempting to do anything with submodule refs.
--- refs.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ refs.h | 2 +- refs/files-backend.c | 8 ++------ 3 files changed, 57 insertions(+), 7 deletions(-)
refs.c +54 -0
@@ -302,6 +302,54 @@ int for_each_tag_ref(each_ref_fn fn, void *cb_data)return for_each_ref_in ("refs/tags/" , fn, cb_data); } +static int submodule_backend (const char *key,const char *value,void *data) +{ +const char **path = data; +char **old_path = data; +if (!strcmp (key,"extensions.refstorage" ) && + !git_config_string (path, key,"extensions.refstorage" )) +free (*old_path); + +return 0 ; +} + +/* +* Check that a submodule exists. If its ref storage backend differs +* from the current backend, die. If the submodule exists, return +* 0. Else return -1. +*/ +static int check_submodule_backend (const char *submodule) +{ +struct strbuf sb =STRBUF_INIT ; +char *submodule_storage_backend; +int result =-1 ; + +if (!submodule) +return 0 ; + + submodule_storage_backend =xstrdup ("files" ); + +strbuf_addstr (&sb, submodule); +if (!is_nonbare_repository_dir (&sb)) + goto done; + +strbuf_reset (&sb); +strbuf_git_path_submodule (&sb, submodule,"config" ); + +git_config_from_file (submodule_backend, sb.buf, + &submodule_storage_backend); +if (strcmp (submodule_storage_backend, ref_storage_backend)) +die (_ ("Ref storage '%s' for submodule '%s' does not match our storage, '%s'" ), + submodule_storage_backend, submodule, ref_storage_backend); + + result =0 ; +done: +free (submodule_storage_backend); +strbuf_release (&sb); + +return result; +} +int for_each_tag_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data) {return for_each_ref_in_submodule (submodule,"refs/tags/" , fn, cb_data);
@@ -314,6 +362,7 @@ int for_each_branch_ref(each_ref_fn fn, void *cb_data)int for_each_branch_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data) { +check_submodule_backend (submodule);return for_each_ref_in_submodule (submodule,"refs/heads/" , fn, cb_data); }
@@ -324,6 +373,7 @@ int for_each_remote_ref(each_ref_fn fn, void *cb_data)int for_each_remote_ref_submodule (const char *submodule,each_ref_fn fn,void *cb_data) { +check_submodule_backend (submodule);return for_each_ref_in_submodule (submodule,"refs/remotes/" , fn, cb_data); }
@@ -1135,6 +1185,7 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)int flag;if (submodule) { +check_submodule_backend (submodule);if (resolve_gitlink_ref (submodule,"HEAD" , oid.hash) ==0 )return fn ("HEAD" , &oid,0 , cb_data);
@@ -1558,6 +1609,9 @@ int create_symref(const char *ref_target, const char *refs_heads_master,int resolve_gitlink_ref (const char *path,const char *refname,unsigned char *sha1) { +if (check_submodule_backend (path)) +return -1 ; +return the_refs_backend->resolve_gitlink_ref (path, refname, sha1); }
refs.h +1 -1
@@ -511,7 +511,7 @@ extern int reflog_expire(const char *refname, const unsigned char *sha1, void *policy_cb_data);/* -* Read the refdb storage backend name out of the config file +* Read the ref storage backend name out of the config file */ int ref_storage_backend_config (const char *var,const char *value,void *ptr);
refs/files-backend.c +2 -6
@@ -1355,13 +1355,9 @@ static int files_resolve_gitlink_ref(const char *path, const char *refname,strbuf_add (&submodule, path, len); refs =lookup_ref_cache (submodule.buf); -if (!refs) { -if (!is_nonbare_repository_dir (&submodule)) { -strbuf_release (&submodule); -return -1 ; - } +if (!refs) refs =create_ref_cache (submodule.buf); - } +strbuf_release (&submodule); retval =resolve_gitlink_ref_recursive (refs, refname, sha1,0 );
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 25/32 clone: allow ref storage backend to be set for clone
In reply to David TurnerAdd a new option, --ref-storage, to allow the ref storage backend to be set on new clones.
Submodules must use the same ref storage as the parent repository, so we also pass the --ref-storage option option when cloning submodules.
--- Documentation/git-clone.txt | 5 +++++ builtin/clone.c | 5 +++++ builtin/submodule--helper.c | 2 +- contrib/completion/git-completion.bash | 1 + git-submodule.sh | 13 +++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-)
Documentation/git-clone.txt +5 -0
@@ -14,6 +14,7 @@ SYNOPSIS [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>] [--dissociate] [--separate-git-dir <git dir>] [--depth <depth>] [--[no-]single-branch] + [--ref-storage=<name>] [--recursive | --recurse-submodules] [--jobs <n>] [--] <repository> [<directory>]
@@ -224,6 +225,10 @@ objects from the source repository into a pack in the cloned repository. The number of submodules fetched at the same time. Defaults to the `submodule.fetchJobs` option. +--ref-storage=<name>:: + Type of ref storage backend. Default is to use the original files + based ref storage. + <repository>:: The (possibly remote) repository to clone from. See the <<URLS,URLS>> section below for more information on specifying
builtin/clone.c +5 -0
@@ -95,6 +95,8 @@ static struct option builtin_clone_options[] = { N_("separate git dir from working tree")),OPT_STRING_LIST ('c' ,"config" , &option_config,N_ ("key=value" ),N_ ("set config inside the new repository" )), +OPT_STRING (0 ,"ref-storage" , &ref_storage_backend, +N_ ("name" ),N_ ("name of backend type to use" )), OPT_END() };
@@ -733,6 +735,9 @@ static int checkout(void)if (max_jobs !=-1 )argv_array_pushf (&args,"--jobs=%d" , max_jobs); +argv_array_pushl (&args,"--ref-storage" , + ref_storage_backend,NULL ); + err =run_command_v_opt (args.argv,RUN_GIT_CMD );argv_array_clear (&args); }
builtin/submodule--helper.c +1 -1
@@ -457,7 +457,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *urlargv_array_pushl (&cp.args,"--reference" , reference,NULL );if (gitdir && *gitdir)argv_array_pushl (&cp.args,"--separate-git-dir" , gitdir,NULL ); - +argv_array_pushl (&cp.args,"--ref-storage" , ref_storage_backend,NULL );argv_array_push (&cp.args, url);argv_array_push (&cp.args, path);
contrib/completion/git-completion.bash +1 -0
@@ -1092,6 +1092,7 @@ _git_clone () --depth --single-branch --branch + --ref-storage= " return ;;
git-submodule.sh +13 -0
@@ -527,6 +527,14 @@ cmd_update() --checkout) update="checkout" ;; + --ref-storage=*) + ref_storage="$1" + ;; + --ref-storage) + case "$2" in '') usage ;; esac + ref_storage="$2" + shift + ;; --depth) case "$2" in '') usage ;; esac depth="--depth=$2"
@@ -560,6 +568,11 @@ cmd_update() if test -n "$init" then cmd_init "--" "$@" || return + else + if test -n "$ref_storage" + then + usage + fi fi git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 26/32 svn: learn ref-storage argument
In reply to David Turnergit svn learns to pass the ref-storage command-line argument (to init and clone) through to git init.
--- contrib/completion/git-completion.bash | 2 +- git-svn.perl | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-)
contrib/completion/git-completion.bash +1 -1
@@ -2477,7 +2477,7 @@ _git_svn () --branches= --stdlayout --minimize-url --no-metadata --use-svm-props --use-svnsync-props --rewrite-root= --prefix= --use-log-author - --add-author-from $remote_opts + --add-author-from --ref-storage= $remote_opts " local cmt_opts=" --edit --rmdir --find-copies-harder --copy-similarity=
git-svn.perl +5 -1
@@ -141,7 +141,7 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent, 'localtime' => \$Git::SVN::_localtime, %remote_opts ); -my ($_trunk, @_tags, @_branches, $_stdlayout); +my ($_trunk, @_tags, @_branches, $_stdlayout, $_ref_storage); my %icv; my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared, 'trunk|T=s' => \$_trunk, 'tags|t=s@' => \@_tags,
@@ -153,6 +153,7 @@ my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared, 'use-svnsync-props' => sub { $icv{useSvnsyncProps} = 1 }, 'rewrite-root=s' => sub { $icv{rewriteRoot} = $_[1] }, 'rewrite-uuid=s' => sub { $icv{rewriteUUID} = $_[1] }, + 'ref-storage=s' => \$_ref_storage, %remote_opts ); my %cmt_opts = ( 'edit|e' => \$_edit, 'rmdir' => \$Git::SVN::Editor::_rmdir,
@@ -469,6 +470,9 @@ sub do_git_init_db { push @init_db, "--shared"; } } + if (defined $_ref_storage) { + push @init_db, "--ref-storage=" . $_ref_storage; + } command_noisy(@init_db); $_repository = Git->repository(Repository => ".git"); }
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 27/32 refs: register ref storage backends
In reply to David TurnerAdd new function register_ref_storage_backends(). This new function registers all known ref storage backends... once there are any other than the default. For now, it just registers the files backend.
Call the function before calling set_ref_storage_backend.
--- builtin/init-db.c | 3 +++ refs.c | 22 ++++++++++++++++++---- refs.h | 2 ++ 3 files changed, 23 insertions(+), 4 deletions(-)
builtin/init-db.c +3 -0
@@ -220,6 +220,7 @@ static int create_default_files(const char *template_path) requested_ref_storage_backend); } +register_ref_storage_backends ();if (requested_ref_storage_backend) ref_storage_backend = requested_ref_storage_backend;if (strcmp (ref_storage_backend,"files" )) {
@@ -502,6 +503,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, init_db_options, init_db_usage,0 ); +register_ref_storage_backends (); +if (requested_ref_storage_backend && !ref_storage_backend_exists (requested_ref_storage_backend)) die(_("Unknown ref storage backend %s"),
refs.c +18 -4
@@ -14,14 +14,11 @@ static const char split_transaction_fail_warning[] = N_("transaction succeeded, but then the update to the per-worktree refs " "failed. Your repository may be in an inconsistent state."); -/* -* We always have a files backend and it is the default. -*/ static struct ref_storage_be *the_refs_backend = &refs_be_files;/* * List of all available backends */ -static struct ref_storage_be *refs_backends = &refs_be_files; +static struct ref_storage_be *refs_backends =NULL ;const char *ref_storage_backend ="files" ;
@@ -49,6 +46,23 @@ int ref_storage_backend_exists(const char *name)return 0 ; } +void register_ref_storage_backend (struct ref_storage_be *be) +{ + be->next = refs_backends; + refs_backends = be; +} + +void register_ref_storage_backends (void ) +{ +if (refs_backends) +return ; +/* +* Add register_ref_storage_backend(ptr-to-backend) +* entries below when you add a new backend. +*/ +register_ref_storage_backend (&refs_be_files); +} +/* * How to handle various characters in refnames: * 0: An acceptable character for refs
refs.h +2 -0
@@ -522,4 +522,6 @@ int set_ref_storage_backend(const char *name);int ref_storage_backend_exists (const char *name); +void register_ref_storage_backends (void ); +#endif /* REFS_H */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 28/32 config: read ref storage config on startup
In reply to David TurnerThis sets up the existing backend early, so that other code which reads refs is reading from the right place.
--- config.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
config.c +24 -0
@@ -11,6 +11,7 @@#include "strbuf.h" #include "quote.h" #include "hashmap.h" +#include "refs.h" #include "string-list.h" #include "utf8.h"
@@ -1207,6 +1208,29 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) }if (repo_config && !access_or_die (repo_config,R_OK ,0 )) { +char *storage =NULL ; + +/* +* make sure we always read the ref storage config +* from the extensions section on startup +*/ + ret +=git_config_from_file (ref_storage_backend_config, + repo_config, &storage); + +register_ref_storage_backends (); +if (!storage) + storage =xstrdup ("" ); + +if (!*storage || + !strcmp (storage,"files" )) { +/* default backend, nothing to do */ +free (storage); + }else { +if (set_ref_storage_backend (ref_storage_backend)) +die (_ ("Unknown ref storage backend %s" ), + ref_storage_backend); + } + ret +=git_config_from_file (fn, repo_config, data); found +=1 ; }
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 29/32 refs: break out resolve_ref_unsafe_submodule
In reply to David TurnerIt will soon be useful for resolve_ref_unsafe to support submodules. But since it is called from so many places, changing it would have been painful. Fortunately, it's just a thin wrapper around (the former) resolve_ref_1. So now resolve_ref_1 becomes resolve_ref_unsafe_submodule, and it passes its submodule argument through to read_raw_ref.
The files backend doesn't need this functionality, but it doesn't hurt.
--- refs.c | 41 +++++++++++++++++++++++++---------------- refs/files-backend.c | 8 ++++++-- refs/refs-internal.h | 19 ++++++++++++++++--- 3 files changed, 47 insertions(+), 21 deletions(-)
refs.c +25 -16
@@ -61,6 +61,9 @@ void register_ref_storage_backends(void)* entries below when you add a new backend. */ register_ref_storage_backend (&refs_be_files); +#ifdef USE_LIBLMDB +register_ref_storage_backend (&refs_be_lmdb); +#endif }/*
@@ -321,8 +324,10 @@ static int submodule_backend(const char *key, const char *value, void *data)const char **path = data;char **old_path = data;if (!strcmp (key,"extensions.refstorage" ) && - !git_config_string (path, key,"extensions.refstorage" )) -free (*old_path); + !git_config_string (path, key,"extensions.refstorage" )) { +free (*old_path); + *path =xstrdup (value); + }return 0 ; }
@@ -1310,21 +1315,22 @@ int for_each_rawref(each_ref_fn fn, void *cb_data) DO_FOR_EACH_INCLUDE_BROKEN, cb_data); } -static int read_raw_ref (const char *refname,unsigned char *sha1, -struct strbuf *symref,struct strbuf *sb_path, -unsigned int *flags) +static int read_raw_ref (const char *submodule,const char *refname, +unsigned char *sha1,struct strbuf *symref, +struct strbuf *sb_path,unsigned int *flags) { -return the_refs_backend->read_raw_ref (refname, sha1, symref, sb_path, - flags); +return the_refs_backend->read_raw_ref (submodule, refname, sha1, + symref, sb_path, flags); }/* This function needs to return a meaningful errno on failure */ -static const char *resolve_ref_1 (const char *refname, -int resolve_flags, -unsigned char *sha1, -int *flags, -struct strbuf *sb_refname, -struct strbuf *sb_path) +const char *resolve_ref_unsafe_submodule (const char *submodule, +const char *refname, +int resolve_flags, +unsigned char *sha1, +int *flags, +struct strbuf *sb_refname, +struct strbuf *sb_path) {int bad_name =0 ;int symref_count;
@@ -1355,7 +1361,8 @@ static const char *resolve_ref_1(const char *refname,for (symref_count =0 ; symref_count <SYMREF_MAXDEPTH ; symref_count++) {int read_flags =0 ; -if (read_raw_ref (refname, sha1, sb_refname, sb_path, &read_flags)) { +if (read_raw_ref (submodule, refname, sha1, sb_refname, sb_path, + &read_flags)) {int saved_errno = errno;if (flags) *flags |= read_flags;
@@ -1416,8 +1423,8 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,struct strbuf sb_path =STRBUF_INIT ;const char *ret; - ret =resolve_ref_1 (refname, resolve_flags, sha1, flags, - &sb_refname, &sb_path); + ret =resolve_ref_unsafe_submodule (NULL , refname, resolve_flags, sha1, + flags, &sb_refname, &sb_path);strbuf_release (&sb_path);return ret;
@@ -1660,6 +1667,8 @@ int safe_create_reflog(const char *refname, int force_create,int delete_reflog (const char *refname) { +if (ref_type (refname) !=REF_TYPE_NORMAL ) +return refs_be_files.delete_reflog (refname);return the_refs_backend->delete_reflog (refname); }
refs/files-backend.c +6 -2
@@ -1421,7 +1421,8 @@ static int resolve_missing_loose_ref(const char *refname,* * sb_path is workspace: the caller should allocate and free it. */ -static int files_read_raw_ref (const char *refname,unsigned char *sha1, +static int files_read_raw_ref (const char *submodule, +const char *refname,unsigned char *sha1,struct strbuf *symref,struct strbuf *sb_path,unsigned int *flags) {
@@ -1431,7 +1432,10 @@ static int files_read_raw_ref(const char *refname, unsigned char *sha1,const char *buf;strbuf_reset (sb_path); -strbuf_git_path (sb_path,"%s" , refname); +if (submodule) +strbuf_git_path_submodule (sb_path, submodule,"%s" , refname); +else +strbuf_git_path (sb_path,"%s" , refname); path = sb_path->buf;for (;;) {
refs/refs-internal.h +16 -3
@@ -230,6 +230,15 @@ int do_for_each_per_worktree_ref(const char *submodule, const char *base, each_ref_fn fn, int trim, int flags, void *cb_data); + +const char *resolve_ref_unsafe_submodule (const char *submodule, +const char *refname, +int resolve_flags, +unsigned char *sha1, +int *flags, +struct strbuf *sb_refname, +struct strbuf *sb_path); +/* refs backends */ typedef int ref_init_db_fn (int shared,struct strbuf *err); typedef int ref_transaction_commit_fn(struct ref_transaction *transaction,
@@ -266,9 +275,9 @@ typedef int rename_ref_fn(const char *oldref, const char *newref, const char *logmsg);/* resolution methods */ -typedef int read_raw_ref_fn (const char *refname,unsigned char *sha1, -struct strbuf *symref,struct strbuf *sb_path, -unsigned int *flags); +typedef int read_raw_ref_fn (const char *submodule,const char *refname, +unsigned char *sha1,struct strbuf *symref, +struct strbuf *sb_path,unsigned int *flags);typedef int verify_refname_available_fn (const char *refname,struct string_list *extra,struct string_list *skip,struct strbuf *err);typedef int resolve_gitlink_ref_fn (const char *path,const char *refname,unsigned char *sha1);
@@ -305,4 +314,8 @@ struct ref_storage_be { };extern struct ref_storage_be refs_be_files; + +#ifdef USE_LIBLMDB +extern struct ref_storage_be refs_be_lmdb; +#endif #endif /* REFS_REFS_INTERNAL_H */
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 30/32 refs: add LMDB refs storage backend
In reply to David TurnerAdd a database backend for refs using LMDB. This backend runs git for-each-ref about 30% faster than the files backend with fully-packed refs on a repo with ~120k refs. It's also about 4x faster than using fully-unpacked refs. In addition, and perhaps more importantly, it avoids case-conflict issues on OS X.
LMDB has a few features that make it suitable for usage in git:
1. It is licensed under the OpenLDAP Public License, which is GPL-compatible [1].
[1] http://www.gnu.org/licenses/license-list.en.html#newOpenLDAP
2. It is relatively lightweight; it requires only one header file, and the library code takes under 64k at runtime.
3. It is well-tested: it's been used in OpenLDAP for years.
4. It's very fast. LMDB's benchmarks show that it is among the fastest key-value stores.
5. It has a relatively simple concurrency story; readers don't block writers and writers don't block readers.
Ronnie Sahlberg's original version of this patchset used tdb. The major disadvantage of tdb is that tdb is hard to build on OS X. It's also not in homebrew. So lmdb seemed simpler.
To test this backend's correctness, I added support to the test suite to run under LMDB. Dozens of tests use manual ref/reflog reading/writing, or create submodules without passing --ref-storage to git init. If those tests are changed to use the update-ref machinery or test-refs-lmdb-backend (or, in the case of packed-refs, corrupt refs, and dumb fetch tests, are skipped), the only remaining failing tests are the git-new-workdir tests. Later, we'll add this support to the test suite.
--- .gitignore | 1 + Documentation/config.txt | 9 + Documentation/git-clone.txt | 3 +- Documentation/git-init.txt | 3 +- Documentation/technical/refs-lmdb-backend.txt | 61 + Documentation/technical/repository-version.txt | 7 + Makefile | 12 + configure.ac | 33 + contrib/workdir/git-new-workdir | 3 + path.c | 1 + refs/lmdb-backend.c | 1886 ++++++++++++++++++++++++ test-refs-lmdb-backend.c | 65 + 12 files changed, 2082 insertions(+), 2 deletions(-) create mode 100644 Documentation/technical/refs-lmdb-backend.txt create mode 100644 refs/lmdb-backend.c create mode 100644 test-refs-lmdb-backend.c
.gitignore +1 -0
@@ -199,6 +199,7 @@ /test-path-utils /test-prio-queue /test-read-cache +/test-refs-lmdb-backend /test-regex /test-revision-walking /test-run-command
Documentation/config.txt +9 -0
@@ -1153,6 +1153,15 @@ difftool.<tool>.cmd:: difftool.prompt:: Prompt before each invocation of the diff tool. +extensions.refStorage:: + Type of ref storage backend. Default is to use the original + files based ref storage. When set to "lmdb", refs are stored + in an LMDB database. This setting reflects the refs storage + backend that was chosen via the --ref-storage option when the + repository was originally created. It is currently not + possible to change the refs storage backend of an existing + repository. + fetch.recurseSubmodules:: This option can be either set to a boolean value or to 'on-demand'. Setting it to a boolean changes the behavior of fetch and pull to
Documentation/git-clone.txt +2 -1
@@ -227,7 +227,8 @@ objects from the source repository into a pack in the cloned repository. --ref-storage=<name>:: Type of ref storage backend. Default is to use the original files - based ref storage. + based ref storage. Set to "lmdb" to store refs in the LMDB database + backend. <repository>:: The (possibly remote) repository to clone from. See the
Documentation/git-init.txt +2 -1
@@ -116,7 +116,8 @@ does not exist, it will be created. --ref-storage=<name>:: Type of refs storage backend. Default is to use the original "files" storage, which stores ref data in files in `$GIT_DIR/refs` and -`$GIT_DIR/packed-refs`. +`$GIT_DIR/packed-refs`. Set to "lmdb" to activate the LMDB storage +backend. TEMPLATE DIRECTORY ------------------
Documentation/technical/refs-lmdb-backend.txt new file +61 -0
61 lines not on this page · raw message
Documentation/technical/repository-version.txt +7 -0
@@ -86,3 +86,10 @@ for testing format-1 compatibility. When the config key `extensions.preciousObjects` is set to `true`, objects in the repository MUST NOT be deleted (e.g., by `git-prune` or `git repack -d`). + +`refStorage` +~~~~~~~~~~~~ +This extension allows the use of alternate ref storage backends. The +only defined values are `lmdb`, `files`, and the empty string (meaning +`files`). The latter two values should never be used, because the +files backend is the default and does not need repository version 1.
Makefile +12 -0
@@ -1042,6 +1042,17 @@ ifdef USE_LIBPCRE EXTLIBS += -lpcre endif +ifdef USE_LIBLMDB + BASIC_CFLAGS += -DUSE_LIBLMDB + ifdef LIBLMDBDIR + BASIC_CFLAGS += -I$(LIBLMDBDIR)/include + EXTLIBS += -L$(LIBLMDBDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBLMDBDIR)/$(lib) + endif + EXTLIBS += -llmdb + LIB_OBJS += refs/lmdb-backend.o + TEST_PROGRAMS_NEED_X += test-refs-lmdb-backend +endif + ifdef HAVE_ALLOCA_H BASIC_CFLAGS += -DHAVE_ALLOCA_H endif
@@ -2140,6 +2151,7 @@ GIT-BUILD-OPTIONS: FORCE @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@+ @echo NO_EXPAT=\''$(subst ','\'',$(subst ','\'',$(NO_EXPAT)))'\' >>$@+ @echo USE_LIBPCRE=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE)))'\' >>$@+ + @echo USE_LIBLMDB=\''$(subst ','\'',$(subst ','\'',$(USE_LIBLMDB)))'\' >>$@+ @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@+ @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+ @echo NO_UNIX_SOCKETS=\''$(subst ','\'',$(subst ','\'',$(NO_UNIX_SOCKETS)))'\' >>$@+
configure.ac +33 -0
@@ -271,6 +271,24 @@ AS_HELP_STRING([], [ARG can be also prefix for libpcre library and hea dnl it yet. GIT_CONF_SUBST([LIBPCREDIR]) fi) + +USE_LIBLMDB=YesPlease +AC_ARG_WITH(liblmdb, +AS_HELP_STRING([--with-liblmdb],[support lmdb (default is YES]) +AS_HELP_STRING([], [ARG can be also prefix for liblmdb library and headers]), + if test "$withval" = "no"; then + USE_LIBLMDB= + elif test "$withval" = "yes"; then + USE_LIBLMDB=YesPlease + else + USE_LIBLMDB=YesPlease + LIBLMDBDIR=$withval + AC_MSG_NOTICE([Setting LIBLMDBDIR to $LIBLMDBDIR]) + dnl USE_LIBLMDB can still be modified below, so don't substitute + dnl it yet. + GIT_CONF_SUBST([LIBLMDBDIR]) + fi) + # # Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header. AC_FUNC_ALLOCA
@@ -510,6 +528,21 @@ GIT_CONF_SUBST([USE_LIBPCRE]) fi +if test -n "$USE_LIBLMDB"; then + +GIT_STASH_FLAGS($LIBLMDBDIR) + +AC_CHECK_LIB([lmdb], [mdb_env_open], +[USE_LIBLMDB=YesPlease], +[USE_LIBLMDB=]) + +GIT_UNSTASH_FLAGS($LIBLMDBDIR) + +GIT_CONF_SUBST([USE_LIBLMDB]) + +fi + + # # Define NO_CURL if you do not have libcurl installed. git-http-pull and # git-http-push are not built, and you cannot use http:// and https://
contrib/workdir/git-new-workdir +3 -0
@@ -28,6 +28,9 @@ git_dir=$(cd "$orig_git" 2>/dev/null && git rev-parse --git-dir 2>/dev/null) || die "Not a git repository: \"$orig_git\"" +ref_storage=$(git config extensions.refstorage || echo "files") +test "$ref_storage" != "files" && die "git-new-workdir is incompatible with ref storage other than 'files'" + case "$git_dir" in .git) git_dir="$orig_git/.git"
path.c +1 -0
@@ -112,6 +112,7 @@ static struct common_dir common_list[] = { { 0, 1, 0, "lost-found" }, { 0, 1, 0, "objects" }, { 0, 1, 0, "refs" }, + { 0, 1, 0, "refs.lmdb" }, { 0, 1, 1, "refs/bisect" }, { 0, 1, 0, "remotes" }, { 0, 1, 0, "worktrees" },
refs/lmdb-backend.c new file +1886 -0
1,886 lines not on this page · raw message
test-refs-lmdb-backend.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 31/32 refs: tests for lmdb backend
In reply to David TurnerAdd tests for the database backend.
--- t/t1460-refs-lmdb-backend.sh | 1109 +++++++++++++++++++++++++++++++++++ t/t1470-refs-lmdb-backend-reflog.sh | 359 ++++++++++++ t/t1480-refs-lmdb-submodule.sh | 85 +++ t/test-lib.sh | 1 + 4 files changed, 1554 insertions(+) create mode 100755 t/t1460-refs-lmdb-backend.sh create mode 100755 t/t1470-refs-lmdb-backend-reflog.sh create mode 100755 t/t1480-refs-lmdb-submodule.sh
t/t1460-refs-lmdb-backend.sh new file +1109 -0
@@ -0,0 +1,1109 @@ +#!/bin/sh +# +# Copyright (c) 2015 Twitter, Inc +# Copyright (c) 2006 Shawn Pearce +# This test is based on t1400-update-ref.sh +# + +test_description='Test lmdb refs backend' +TEST_NO_CREATE_REPO=1 +. ./test-lib.sh + +if ! test_have_prereq LMDB +then + skip_all="Skipping lmdb refs backend tests, lmdb backend not built" + test_done +fi + +raw_ref() { + test-refs-lmdb-backend "$1" +} + +delete_ref() { + test-refs-lmdb-backend -d "$1" +} + +write_ref() { + test-refs-lmdb-backend "$1" "$2" +} + +raw_reflog() { + test-refs-lmdb-backend -l "$1" +} + +delete_all_reflogs() { + test-refs-lmdb-backend -c +} + +append_reflog() { + test-refs-lmdb-backend -a "$1" +} + +Z=$_z40 + +test_expect_success setup ' + git init --ref-storage=lmdb && + for name in A B C D E F + do + test_tick && + T=$(git write-tree) && + sha1=$(echo $name | git commit-tree $T) && + eval $name=$sha1 + done +' + +m=refs/heads/master +n_dir=refs/heads/gu +n=$n_dir/fixes + +test_expect_success \ + "create $m" \ + "git update-ref $m $A && + test $A"' = $(raw_ref '"$m"')' +test_expect_success \ + "create $m" \ + "git update-ref $m $B $A && + test $B"' = $(raw_ref '"$m"')' +test_expect_success "fail to delete $m with stale ref" ' + test_must_fail git update-ref -d $m $A && + test $B = "$(raw_ref $m)" +' +test_expect_success "delete $m" ' + git update-ref -d $m $B && + ! raw_ref $m +' +delete_ref $m + +test_expect_success "delete $m without oldvalue verification" " + git update-ref $m $A && + test $A = \$(raw_ref $m) && + git update-ref -d $m && + ! raw_ref $m +" +delete_ref $m + +test_expect_success \ + "fail to create $n" \ + "git update-ref $n_dir $A && + test_must_fail git update-ref $n $A >out 2>err" + +delete_ref $n_dir +rm -f out err + +test_expect_success \ + "create $m (by HEAD)" \ + "git update-ref HEAD $A && + test $A"' = $(raw_ref '"$m"')' +test_expect_success \ + "create $m (by HEAD)" \ + "git update-ref HEAD $B $A && + test $B"' = $(raw_ref '"$m"')' +test_expect_success "fail to delete $m (by HEAD) with stale ref" ' + test_must_fail git update-ref -d HEAD $A && + test $B = $(raw_ref '"$m"') +' +test_expect_success "delete $m (by HEAD)" ' + git update-ref -d HEAD $B && + ! raw_ref $m +' +delete_ref $m + +test_expect_success \ + "create $m (by HEAD)" \ + "git update-ref HEAD $A && + test $A"' = $(raw_ref '"$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"' = $(raw_ref '"$m"')' +test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" ' + git update-ref -d HEAD $B && + ! raw_ref $m +' +delete_ref $m + +OLD_HEAD=$(raw_ref HEAD) +test_expect_success "delete symref without dereference" ' + git update-ref --no-deref -d HEAD && + ! raw_ref HEAD +' +write_ref HEAD "$OLD_HEAD" + +test_expect_success "delete symref without dereference when the referred ref is packed" ' + echo foo >foo.c && + git add foo.c && + git commit -m foo && + git pack-refs --all && + git update-ref --no-deref -d HEAD && + ! raw_ref HEAD +' +write_ref HEAD "$OLD_HEAD" +delete_ref $m + +test_expect_success 'update-ref -d is not confused by self-reference' ' + git symbolic-ref refs/heads/self refs/heads/self && + test_when_finished "delete_ref refs/heads/self" && + test_must_fail git update-ref -d refs/heads/self +' + +test_expect_success 'update-ref --no-deref -d can delete self-reference' ' + git symbolic-ref refs/heads/self refs/heads/self && + test_when_finished "delete_ref refs/heads/self" && + git update-ref --no-deref -d refs/heads/self +' + +test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' ' + test-refs-lmdb-backend refs/heads/bad "" && + test_when_finished "delete_ref refs/heads/bad" && + git symbolic-ref refs/heads/ref-to-bad refs/heads/bad && + test_when_finished "delete_ref refs/heads/ref-to-bad" && + raw_ref refs/heads/ref-to-bad && + git update-ref --no-deref -d refs/heads/ref-to-bad && + ! raw_ref refs/heads/ref-to-bad +' + +test_expect_success '(not) create HEAD with old sha1' " + test_must_fail git update-ref HEAD $A $B +" +test_expect_success "(not) prior created .git/$m" " + ! raw_ref $m +" +delete_ref $m + +test_expect_success \ + "create HEAD" \ + "git update-ref HEAD $A" +test_expect_success '(not) change HEAD with wrong SHA1' " + test_must_fail git update-ref HEAD $B $Z +" +test_expect_success "(not) changed .git/$m" " + ! test $B"' = $(raw_ref '"$m"') +' + +: a repository with working tree always has reflog these days... +delete_all_reflogs +: | append_reflog $m +delete_ref $m + +test_expect_success \ + "create $m (logged by touch)" \ + 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ + git update-ref HEAD '"$A"' -m "Initial Creation" && + test '"$A"' = $(raw_ref '"$m"')' +test_expect_success \ + "update $m (logged by touch)" \ + 'GIT_COMMITTER_DATE="2005-05-26 23:31" \ + git update-ref HEAD'" $B $A "'-m "Switch" && + test '"$B"' = $(raw_ref '"$m"')' +test_expect_success \ + "set $m (logged by touch)" \ + 'GIT_COMMITTER_DATE="2005-05-26 23:41" \ + git update-ref HEAD'" $A && + test $A"' = $(raw_ref '"$m"')' + +cat >expect <<EOF +$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation +$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch +$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 +EOF +test_expect_success \ + "verifying $m's log" \ + "raw_reflog $m >actual && + test_cmp expect actual" +delete_ref $m +delete_all_reflogs +: | append_reflog $m +rm -f actual expect + +test_expect_success \ + 'enable core.logAllRefUpdates' \ + 'git config core.logAllRefUpdates true && + test true = $(git config --bool --get core.logAllRefUpdates)' + +test_expect_success \ + "create $m (logged by config)" \ + 'GIT_COMMITTER_DATE="2005-05-26 23:32" \ + git update-ref HEAD'" $A "'-m "Initial Creation" && + test '"$A"' = $(raw_ref '"$m"')' +test_expect_success \ + "update $m (logged by config)" \ + 'GIT_COMMITTER_DATE="2005-05-26 23:33" \ + git update-ref HEAD'" $B $A "'-m "Switch" && + test '"$B"' = $(raw_ref '"$m"')' +test_expect_success \ + "set $m (logged by config)" \ + 'GIT_COMMITTER_DATE="2005-05-26 23:43" \ + git update-ref HEAD '"$A && + test $A"' = $(raw_ref '"$m"')' + +cat >expect <<EOF +$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation +$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch +$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000 +EOF +test_expect_success \ + "verifying $m's log" \ + 'raw_reflog $m >actual && + test_cmp expect actual' +delete_ref $m +rm -f expect + +git update-ref $m $D +git reflog expire --expire=all $m + +append_reflog $m <<EOF +0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500 +$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500 +$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500 +$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500 +$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500 +EOF + +ed="Thu, 26 May 2005 18:32:00 -0500" +gd="Thu, 26 May 2005 18:33:00 -0500" +ld="Thu, 26 May 2005 18:43:00 -0500" +test_expect_success \ + 'Query "master@{May 25 2005}" (before history)' \ + 'rm -f o e && + git rev-parse --verify "master@{May 25 2005}" >o 2>e && + test '"$C"' = $(cat o) && + test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"' +test_expect_success \ + "Query master@{2005-05-25} (before history)" \ + 'rm -f o e && + git rev-parse --verify master@{2005-05-25} >o 2>e && + test '"$C"' = $(cat o) && + echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"' +test_expect_success \ + 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \ + 'rm -f o e && + git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e && + test '"$C"' = $(cat o) && + test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"' +test_expect_success \ + 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \ + 'rm -f o e && + git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e && + test '"$C"' = $(cat o) && + test "" = "$(cat e)"' +test_expect_success \ + 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \ + 'rm -f o e && + git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e && + test '"$A"' = $(cat o) && + test "" = "$(cat e)"' +test_expect_success \ + 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \ + 'rm -f o e && + git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e && + test '"$B"' = $(cat o) && + test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"' +test_expect_success \ + 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \ + 'rm -f o e && + git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e && + test '"$Z"' = $(cat o) && + test "" = "$(cat e)"' +test_expect_success \ + 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \ + 'rm -f o e && + git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e && + test '"$E"' = $(cat o) && + test "" = "$(cat e)"' +test_expect_success \ + 'Query "master@{2005-05-28}" (past end of history)' \ + 'rm -f o e && + git rev-parse --verify "master@{2005-05-28}" >o 2>e && + test '"$D"' = $(cat o) && + test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"' + + +git reflog expire --expire=all $m +delete_ref $m + +test_expect_success \ + 'creating initial files' \ + 'echo TEST >F && + git add F && + GIT_AUTHOR_DATE="2005-05-26 23:30" \ + GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a && + h_TEST=$(git rev-parse --verify HEAD) && + echo The other day this did not work. >M && + echo And then Bob told me how to fix it. >>M && + echo OTHER >F && + GIT_AUTHOR_DATE="2005-05-26 23:41" \ + GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a && + h_OTHER=$(git rev-parse --verify HEAD) && + GIT_AUTHOR_DATE="2005-05-26 23:44" \ + GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend && + h_FIXED=$(git rev-parse --verify HEAD) && + echo Merged initial commit and a later commit. >M && + echo $h_TEST >.git/MERGE_HEAD && + GIT_AUTHOR_DATE="2005-05-26 23:45" \ + GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M && + h_MERGED=$(git rev-parse --verify HEAD) && + rm -f M' + +cat >expect <<EOF +$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add +$h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work. +$h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work. +$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit. +EOF +test_expect_success \ + 'git commit logged updates' \ + "raw_reflog $m >actual && + test_cmp expect actual" +unset h_TEST h_OTHER h_FIXED h_MERGED + +test_expect_success \ + 'git cat-file blob master:F (expect OTHER)' \ + 'test OTHER = $(git cat-file blob master:F)' +test_expect_success \ + 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \ + 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")' +test_expect_success \ + 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \ + 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")' + +a=refs/heads/a +b=refs/heads/b +c=refs/heads/c +E='""' +F='%s\0' +pws='path with space' + +test_expect_success 'stdin test setup' ' + echo "$pws" >"$pws" && + git add -- "$pws" && + git commit -m "$pws" +' + +test_expect_success '-z fails without --stdin' ' + test_must_fail git update-ref -z $m $m $m 2>err && + grep "usage: git update-ref" err +' + +test_expect_success 'stdin works with no input' ' + >stdin && + git update-ref --stdin <stdin && + git rev-parse --verify -q $m +' + +test_expect_success 'stdin fails on empty line' ' + echo "" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: empty command in input" err +' + +test_expect_success 'stdin fails on only whitespace' ' + echo " " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: whitespace before command: " err +' + +test_expect_success 'stdin fails on leading whitespace' ' + echo " create $a $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: whitespace before command: create $a $m" err +' + +test_expect_success 'stdin fails on unknown command' ' + echo "unknown $a" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: unknown command: unknown $a" err +' + +test_expect_success 'stdin fails on unbalanced quotes' ' + echo "create $a \"master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: badly quoted argument: \\\"master" err +' + +test_expect_success 'stdin fails on invalid escape' ' + echo "create $a \"ma\zter\"" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err +' + +test_expect_success 'stdin fails on junk after quoted argument' ' + echo "create \"$a\"master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err +' + +test_expect_success 'stdin fails create with no ref' ' + echo "create " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create: missing <ref>" err +' + +test_expect_success 'stdin fails create with no new value' ' + echo "create $a" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create $a: missing <newvalue>" err +' + +test_expect_success 'stdin fails create with too many arguments' ' + echo "create $a $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create $a: extra input: $m" err +' + +test_expect_success 'stdin fails update with no ref' ' + echo "update " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: update: missing <ref>" err +' + +test_expect_success 'stdin fails update with no new value' ' + echo "update $a" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: update $a: missing <newvalue>" err +' + +test_expect_success 'stdin fails update with too many arguments' ' + echo "update $a $m $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: update $a: extra input: $m" err +' + +test_expect_success 'stdin fails delete with no ref' ' + echo "delete " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: delete: missing <ref>" err +' + +test_expect_success 'stdin fails delete with too many arguments' ' + echo "delete $a $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: delete $a: extra input: $m" err +' + +test_expect_success 'stdin fails verify with too many arguments' ' + echo "verify $a $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: verify $a: extra input: $m" err +' + +test_expect_success 'stdin fails option with unknown name' ' + echo "option unknown" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: option unknown: unknown" err +' + +test_expect_success 'stdin fails with duplicate refs' ' + cat >stdin <<-EOF && + create $a $m + create $b $m + create $a $m + EOF + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err +' + +test_expect_success 'stdin create ref works' ' + echo "create $a $m" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin succeeds with quoted argument' ' + git update-ref -d $a && + echo "create $a \"$m\"" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin succeeds with escaped character' ' + git update-ref -d $a && + echo "create $a \"ma\\163ter\"" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin update ref creates with zero old value' ' + echo "update $b $m $Z" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual && + git update-ref -d $b +' + +test_expect_success 'stdin update ref creates with empty old value' ' + echo "update $b $m $E" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin create ref works with path with space to blob' ' + echo "create refs/blobs/pws \"$m:$pws\"" >stdin && + git update-ref --stdin <stdin && + git rev-parse "$m:$pws" >expect && + git rev-parse refs/blobs/pws >actual && + test_cmp expect actual && + git update-ref -d refs/blobs/pws +' + +test_expect_success 'stdin update ref fails with wrong old value' ' + echo "update $c $m $m~1" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: cannot lock the ref '"'"'$c'"'"'" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update ref fails with bad old value' ' + echo "update $c $m does-not-exist" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin create ref fails with bad new value' ' + echo "create $c does-not-exist" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create $c: invalid <newvalue>: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin create ref fails with zero new value' ' + echo "create $c " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create $c: zero <newvalue>" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update ref works with right old value' ' + echo "update $b $m~1 $m" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref fails with wrong old value' ' + echo "delete $a $m~1" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: cannot lock the ref '"'"'$a'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref fails with zero old value' ' + echo "delete $a " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: delete $a: zero <oldvalue>" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin update symref works option no-deref' ' + git symbolic-ref refs/TESTSYMREF $b && + cat >stdin <<-EOF && + option no-deref + update refs/TESTSYMREF $a $b + EOF + git update-ref --stdin <stdin && + git rev-parse refs/TESTSYMREF >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete symref works option no-deref' ' + git symbolic-ref refs/TESTSYMREF $b && + cat >stdin <<-EOF && + option no-deref + delete refs/TESTSYMREF $b + EOF + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q refs/TESTSYMREF && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref works with right old value' ' + echo "delete $b $m~1" >stdin && + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q $b +' + +test_expect_success 'stdin update/create/verify combination works' ' + cat >stdin <<-EOF && + update $a $m + create $b $m + verify $c + EOF + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin verify succeeds for correct value' ' + git rev-parse $m >expect && + echo "verify $m $m" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin verify succeeds for missing reference' ' + echo "verify refs/heads/missing $Z" >stdin && + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q refs/heads/missing +' + +test_expect_success 'stdin verify treats no value as missing' ' + echo "verify refs/heads/missing" >stdin && + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q refs/heads/missing +' + +test_expect_success 'stdin verify fails for wrong value' ' + git rev-parse $m >expect && + echo "verify $m $m~1" >stdin && + test_must_fail git update-ref --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin verify fails for mistaken null value' ' + git rev-parse $m >expect && + echo "verify $m $Z" >stdin && + test_must_fail git update-ref --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin verify fails for mistaken empty value' ' + M=$(git rev-parse $m) && + test_when_finished "git update-ref $m $M" && + git rev-parse $m >expect && + echo "verify $m" >stdin && + test_must_fail git update-ref --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin update refs works with identity updates' ' + cat >stdin <<-EOF && + update $a $m $m + update $b $m $m + update $c $Z $E + EOF + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update refs fails with wrong old value' ' + git update-ref $c $m && + cat >stdin <<-EOF && + update $a $m $m + update $b $m $m + update $c '' + EOF + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: cannot lock the ref '"'"'$c'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + git rev-parse $c >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete refs works with packed and loose refs' ' + git pack-refs --all && + git update-ref $c $m~1 && + cat >stdin <<-EOF && + delete $a $m + update $b $Z $m + update $c $E $m~1 + EOF + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q $a && + test_must_fail git rev-parse --verify -q $b && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z works on empty input' ' + >stdin && + git update-ref -z --stdin <stdin && + git rev-parse --verify -q $m +' + +test_expect_success 'stdin -z fails on empty line' ' + echo "" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: whitespace before command: " err +' + +test_expect_success 'stdin -z fails on empty command' ' + printf $F "" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: empty command in input" err +' + +test_expect_success 'stdin -z fails on only whitespace' ' + printf $F " " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: whitespace before command: " err +' + +test_expect_success 'stdin -z fails on leading whitespace' ' + printf $F " create $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: whitespace before command: create $a" err +' + +test_expect_success 'stdin -z fails on unknown command' ' + printf $F "unknown $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: unknown $a" err +' + +test_expect_success 'stdin -z fails create with no ref' ' + printf $F "create " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: create: missing <ref>" err +' + +test_expect_success 'stdin -z fails create with no new value' ' + printf $F "create $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: create $a: unexpected end of input when reading <newvalue>" err +' + +test_expect_success 'stdin -z fails create with too many arguments' ' + printf $F "create $a" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails update with no ref' ' + printf $F "update " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update: missing <ref>" err +' + +test_expect_success 'stdin -z fails update with too few args' ' + printf $F "update $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err +' + +test_expect_success 'stdin -z emits warning with empty new value' ' + git update-ref $a $m && + printf $F "update $a" "" "" >stdin && + git update-ref -z --stdin <stdin 2>err && + grep "warning: update $a: missing <newvalue>, treating as zero" err && + test_must_fail git rev-parse --verify -q $a +' + +test_expect_success 'stdin -z fails update with no new value' ' + printf $F "update $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update $a: unexpected end of input when reading <newvalue>" err +' + +test_expect_success 'stdin -z fails update with no old value' ' + printf $F "update $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err +' + +test_expect_success 'stdin -z fails update with too many arguments' ' + printf $F "update $m" "$m" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails delete with no ref' ' + printf $F "delete " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: delete: missing <ref>" err +' + +test_expect_success 'stdin -z fails delete with no old value' ' + printf $F "delete $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err +' + +test_expect_success 'stdin -z fails delete with too many arguments' ' + printf $F "delete $m" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails verify with too many arguments' ' + printf $F "verify $m" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails verify with no old value' ' + printf $F "verify $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err +' + +test_expect_success 'stdin -z fails option with unknown name' ' + printf $F "option unknown" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: option unknown: unknown" err +' + +test_expect_success 'stdin -z fails with duplicate refs' ' + printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err +' + +test_expect_success 'stdin -z create ref works' ' + printf $F "create $a" "$m" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z update ref creates with zero old value' ' + printf $F "update $b" "$m" "$Z" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual && + git update-ref -d $b +' + +test_expect_success 'stdin -z update ref creates with empty old value' ' + printf $F "update $b" "$m" "" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z create ref works with path with space to blob' ' + printf $F "create refs/blobs/pws" "$m:$pws" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse "$m:$pws" >expect && + git rev-parse refs/blobs/pws >actual && + test_cmp expect actual && + git update-ref -d refs/blobs/pws +' + +test_expect_success 'stdin -z update ref fails with wrong old value' ' + printf $F "update $c" "$m" "$m~1" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: cannot lock the ref '"'"'$c'"'"'" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z update ref fails with bad old value' ' + printf $F "update $c" "$m" "does-not-exist" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z create ref fails when ref exists' ' + git update-ref $c $m && + git rev-parse "$c" >expect && + printf $F "create $c" "$m~1" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: cannot lock the ref '"'"'$c'"'"'" err && + git rev-parse "$c" >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z create ref fails with bad new value' ' + git update-ref -d "$c" && + printf $F "create $c" "does-not-exist" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: create $c: invalid <newvalue>: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z create ref fails with empty new value' ' + printf $F "create $c" "" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: create $c: missing <newvalue>" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z update ref works with right old value' ' + printf $F "update $b" "$m~1" "$m" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete ref fails with wrong old value' ' + printf $F "delete $a" "$m~1" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: cannot lock the ref '"'"'$a'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete ref fails with zero old value' ' + printf $F "delete $a" "$Z" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: delete $a: zero <oldvalue>" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z update symref works option no-deref' ' + git symbolic-ref refs/TESTSYMREF $b && + printf $F "option no-deref" "update refs/TESTSYMREF" "$a" "$b" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse refs/TESTSYMREF >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete symref works option no-deref' ' + git symbolic-ref refs/TESTSYMREF $b && + printf $F "option no-deref" "delete refs/TESTSYMREF" "$b" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q refs/TESTSYMREF && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete ref works with right old value' ' + printf $F "delete $b" "$m~1" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q $b +' + +test_expect_success 'stdin -z update/create/verify combination works' ' + printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z verify succeeds for correct value' ' + git rev-parse $m >expect && + printf $F "verify $m" "$m" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z verify succeeds for missing reference' ' + printf $F "verify refs/heads/missing" "$Z" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q refs/heads/missing +' + +test_expect_success 'stdin -z verify treats no value as missing' ' + printf $F "verify refs/heads/missing" "" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q refs/heads/missing +' + +test_expect_success 'stdin -z verify fails for wrong value' ' + git rev-parse $m >expect && + printf $F "verify $m" "$m~1" >stdin && + test_must_fail git update-ref -z --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z verify fails for mistaken null value' ' + git rev-parse $m >expect && + printf $F "verify $m" "$Z" >stdin && + test_must_fail git update-ref -z --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z verify fails for mistaken empty value' ' + M=$(git rev-parse $m) && + test_when_finished "git update-ref $m $M" && + git rev-parse $m >expect && + printf $F "verify $m" "" >stdin && + test_must_fail git update-ref -z --stdin <stdin && + git rev-parse $m >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z update refs works with identity updates' ' + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z update refs fails with wrong old value' ' + git update-ref $c $m && + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: cannot lock the ref '"'"'$c'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + git rev-parse $c >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete refs works with packed and loose refs' ' + git pack-refs --all && + git update-ref $c $m~1 && + printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q $a && + test_must_fail git rev-parse --verify -q $b && + test_must_fail git rev-parse --verify -q $c +' + +test_done
t/t1470-refs-lmdb-backend-reflog.sh new file +359 -0
359 lines not on this page · raw message
t/t1480-refs-lmdb-submodule.sh new file +85 -0
85 lines not on this page · raw message
t/test-lib.sh +1 -0
@@ -960,6 +960,7 @@ test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PYTHON" && test_set_prereq PYTHON test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE test -z "$NO_GETTEXT" && test_set_prereq GETTEXT +test -n "$USE_LIBLMDB" && test_set_prereq LMDB # Can we rely on git's output in the C locale? if test -n "$GETTEXT_POISON"
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
PATCH v6 32/32 tests: add ref-storage argument
In reply to David TurnerAdd a --ref-storage argument to make it easy to test alternate ref storage backends. This means that every test that calls git init or git clone must use the new ref storage argument.
Modify many tests to work under alternate ref storage backends.
Introduce abstractions for raw ref/reflog reading/writing in tests instead of directly frobbing the filesystem.
Conditionally skip tests that are not expected to succeed under this condition. Most of this is straightforward. Of particular note are the following test changes:
* The rearrangement of commands in t1401 is because without HEAD in the right place, git doesn't recognized the trash dir as a git repo, so no git commands work.
* t1430-bad-ref-name specifically blocks lmdb because other alternate backends might want to keep this test.
--- t/README | 6 +++ t/lib-submodule-update.sh | 15 +++++-- t/lib-t6000.sh | 7 ++- t/t0008-ignores.sh | 2 +- t/t0062-revision-walking.sh | 6 +++ t/t1021-rerere-in-workdir.sh | 6 +++ t/t1200-tutorial.sh | 8 +++- t/t1302-repo-version.sh | 6 +++ t/t1305-config-include.sh | 17 ++++++-- t/t1400-update-ref.sh | 6 +++ t/t1401-symbolic-ref.sh | 17 +++++--- t/t1404-update-ref-df-conflicts.sh | 8 +++- t/t1410-reflog.sh | 6 +++ t/t1430-bad-ref-name.sh | 6 +++ t/t1450-fsck.sh | 12 ++--- t/t1506-rev-parse-diagnosis.sh | 4 +- t/t2013-checkout-submodule.sh | 2 +- t/t2105-update-index-gitfile.sh | 4 +- t/t2107-update-index-basic.sh | 6 +-- t/t2201-add-update-typechange.sh | 4 +- t/t3001-ls-files-others-exclude.sh | 2 +- t/t3010-ls-files-killed-modified.sh | 4 +- t/t3040-subprojects-basic.sh | 4 +- t/t3050-subprojects-fetch.sh | 2 +- t/t3200-branch.sh | 75 ++++++++++++++++++-------------- t/t3210-pack-refs.sh | 7 +++ t/t3211-peel-ref.sh | 6 +++ t/t3308-notes-merge.sh | 2 +- t/t3404-rebase-interactive.sh | 2 +- t/t3600-rm.sh | 2 +- t/t3800-mktag.sh | 4 +- t/t3903-stash.sh | 2 +- t/t4010-diff-pathspec.sh | 2 +- t/t4020-diff-external.sh | 2 +- t/t4027-diff-submodule.sh | 2 +- t/t4035-diff-quiet.sh | 2 +- t/t4255-am-submodule.sh | 2 +- t/t5000-tar-tree.sh | 3 +- t/t5304-prune.sh | 2 +- t/t5312-prune-corruption.sh | 11 ++++- t/t5500-fetch-pack.sh | 10 ++--- t/t5510-fetch.sh | 30 ++++++------- t/t5526-fetch-submodules.sh | 4 +- t/t5527-fetch-odd-refs.sh | 7 +++ t/t5537-fetch-shallow.sh | 7 +++ t/t5700-clone-reference.sh | 42 +++++++++--------- t/t6001-rev-list-graft.sh | 3 +- t/t6010-merge-base.sh | 2 +- t/t6050-replace.sh | 4 +- t/t6120-describe.sh | 6 ++- t/t6301-for-each-ref-errors.sh | 12 ++--- t/t7201-co.sh | 2 +- t/t7300-clean.sh | 25 ++++++----- t/t7400-submodule-basic.sh | 18 ++++---- t/t7402-submodule-rebase.sh | 2 +- t/t7405-submodule-merge.sh | 10 ++--- t/t9104-git-svn-follow-parent.sh | 3 +- t/t9115-git-svn-dcommit-funky-renames.sh | 2 +- t/t9350-fast-export.sh | 6 +-- t/t9902-completion.sh | 3 +- t/t9903-bash-prompt.sh | 1 + t/test-lib-functions.sh | 53 +++++++++++++++++++++- t/test-lib.sh | 11 +++++ 63 files changed, 368 insertions(+), 181 deletions(-)
t/README +6 -0
@@ -178,6 +178,12 @@ appropriately before running "make". this feature by setting the GIT_TEST_CHAIN_LINT environment variable to "1" or "0", respectively. +--ref-storage=<backend>:: + If --ref-storage is set, run tests under an alternate ref + backend. Tests that rely on the original files backend will + be skipped. You may also enable or disable this feature by + setting the GIT_TEST_REF_STORAGE environment variable + You can also set the GIT_TEST_INSTALLED environment variable to the bindir of an existing git installation to test that installation. You still need to have built this git sandbox, from which various
t/lib-submodule-update.sh +12 -3
@@ -32,7 +32,7 @@ # invalid_sub1 # create_lib_submodule_repo () { - git init submodule_update_repo && + git init $ref_storage_arg submodule_update_repo && ( cd submodule_update_repo && echo "expect" >>.gitignore &&
@@ -125,7 +125,16 @@ test_git_directory_is_unchanged () { # "$1/.git/config" lacks it... git config --unset core.worktree ) && - diff -r ".git/modules/$1" "$1/.git" && + if test "$ref_storage" = "lmdb" + then + diff -x refs.lmdb -r ".git/modules/$1" "$1/.git" && + mdb_dump -p ".git/modules/$1/refs.lmdb" >one && + mdb_dump -p "$1/.git/refs.lmdb" >two && + diff one two && + rm one two + else + diff -r ".git/modules/$1" "$1/.git" + fi ( # ... and then restore. cd ".git/modules/$1" &&
@@ -147,7 +156,7 @@ prolog () { # should be updated to an existing commit. reset_work_tree_to () { rm -rf submodule_update && - git clone submodule_update_repo submodule_update && + git clone $ref_storage_arg submodule_update_repo submodule_update && ( cd submodule_update && rm -rf sub1 &&
t/lib-t6000.sh +3 -4
@@ -4,11 +4,10 @@ mkdir -p .git/refs/tags >sed.script -# Answer the sha1 has associated with the tag. The tag must exist in .git/refs/tags +# Answer the sha1 has associated with the tag. The tag must exist under refs/tags tag () { _tag=$1 - test -f ".git/refs/tags/$_tag" || error "tag: \"$_tag\" does not exist" - cat ".git/refs/tags/$_tag" + git rev-parse --verify "refs/tags/$_tag" || error "tag: \"$_tag\" does not exist" } # Generate a commit using the text specified to make it unique and the tree
@@ -26,7 +25,7 @@ save_tag () { _tag=$1 test -n "$_tag" || error "usage: save_tag tag commit-args ..." shift 1 - "$@" >".git/refs/tags/$_tag" + write_ref "refs/tags/$_tag" $("$@") echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp cat sed.script >>sed.script.tmp
t/t0008-ignores.sh +1 -1
@@ -184,7 +184,7 @@ test_expect_success 'setup' ' fi && ( cd a/submodule && - git init && + git init $ref_storage_arg && echo a >a && git add a && git commit -m"commit in submodule"
t/t0062-revision-walking.sh +6 -0
@@ -7,6 +7,12 @@ test_description='Test revision walking api' . ./test-lib.sh +if test "$ref_storage" != "files" +then + skip_all="Alternate storage doesn't do test-revision-walking" + test_done +fi + cat >run_twice_expected <<-EOF 1st > add b
t/t1021-rerere-in-workdir.sh +6 -0
@@ -3,6 +3,12 @@ test_description='rerere run in a workdir' . ./test-lib.sh +if test "$ref_storage" != "files" +then + skip_all="Workdirs don't support alternate ref backends" + test_done +fi + test_expect_success SYMLINKS setup ' git config rerere.enabled true && >world &&
t/t1200-tutorial.sh +6 -2
@@ -93,12 +93,16 @@ test_expect_success 'git whatchanged -p --root' ' test_expect_success 'git tag my-first-tag' ' git tag my-first-tag && - test_cmp .git/refs/heads/master .git/refs/tags/my-first-tag + git rev-parse --verify refs/heads/master >expect && + git rev-parse --verify refs/tags/my-first-tag >actual && + test_cmp expect actual ' test_expect_success 'git checkout -b mybranch' ' git checkout -b mybranch && - test_cmp .git/refs/heads/master .git/refs/heads/mybranch + git rev-parse --verify refs/heads/master >expect && + git rev-parse --verify refs/heads/mybranch >actual && + test_cmp expect actual ' cat > branch.expect <<EOF
t/t1302-repo-version.sh +6 -0
@@ -7,6 +7,12 @@ test_description='Test repository version check' . ./test-lib.sh +if test "$ref_storage" != "files" +then + skip_all="Alternate ref storage sets core.repositoryformatversion=1" + test_done +fi + test_expect_success 'setup' ' cat >test.patch <<-\EOF && diff --git a/test.txt b/test.txt
t/t1305-config-include.sh +13 -4
@@ -45,14 +45,23 @@ test_expect_success 'include options can still be examined' ' test_cmp expect actual ' -test_expect_success 'listing includes option and expansion' ' - echo "[test]one = 1" >one && - echo "[include]path = one" >.gitconfig && - cat >expect <<-\EOF && +write_expected_config() +{ + cat <<-\EOF && include.path=one test.one=1 EOF + if test "$ref_storage" != "files" + then + echo "extensions.refstorage=$ref_storage" + fi +} + +test_expect_success 'listing includes option and expansion' ' + echo "[test]one = 1" >one && + echo "[include]path = one" >.gitconfig && git config --list >actual.full && + write_expected_config >expect && grep -v ^core actual.full >actual && test_cmp expect actual '
t/t1400-update-ref.sh +6 -0
@@ -6,6 +6,12 @@ test_description='Test git update-ref and basic ref logging' . ./test-lib.sh +if test "$ref_storage" != "files" +then + skip_all="This test is ref storage backend-specific" + test_done +fi + Z=$_z40 test_expect_success setup '
t/t1401-symbolic-ref.sh +12 -5
@@ -35,15 +35,16 @@ reset_to_sane test_expect_success 'symbolic-ref deletes HEAD' ' git symbolic-ref -d HEAD && - test_path_is_file .git/refs/heads/foo && - test_path_is_missing .git/HEAD + test_path_is_missing .git/HEAD && + reset_to_sane && + git rev-parse --verify refs/heads/foo ' reset_to_sane test_expect_success 'symbolic-ref deletes dangling HEAD' ' git symbolic-ref HEAD refs/heads/missing && git symbolic-ref -d HEAD && - test_path_is_missing .git/refs/heads/missing && + test_must_fail git rev-parse --verify refs/heads/missing && test_path_is_missing .git/HEAD ' reset_to_sane
@@ -58,7 +59,7 @@ reset_to_sane test_expect_success 'symbolic-ref fails to delete real ref' ' echo "fatal: Cannot delete refs/heads/foo, not a symbolic ref" >expect && test_must_fail git symbolic-ref -d refs/heads/foo >actual 2>&1 && - test_path_is_file .git/refs/heads/foo && + git rev-parse --verify refs/heads/foo && test_cmp expect actual ' reset_to_sane
@@ -114,7 +115,13 @@ test_expect_success 'symbolic-ref writes reflog entry' ' test_cmp expect actual ' -test_expect_success 'symbolic-ref does not create ref d/f conflicts' ' +if test "$ref_storage" = "files" +then + test_cmd=test_expect_success +else + test_cmd=test_expect_failure +fi +$test_cmd 'symbolic-ref does not create ref d/f conflicts' ' git checkout -b df && test_commit df && test_must_fail git symbolic-ref refs/heads/df/conflict refs/heads/df &&
t/t1404-update-ref-df-conflicts.sh +7 -1
@@ -96,7 +96,13 @@ test_expect_success 'new ref is a deeper prefix of existing packed' ' ' -test_expect_success 'one new ref is a simple prefix of another' ' +expect=test_expect_success +if test "$ref_storage" != "files" +then + expect=test_expect_failure +fi + +$expect 'one new ref is a simple prefix of another' ' prefix=refs/5 && test_update_rejected $prefix "a e" false "b c c/x d" \
t/t1410-reflog.sh +6 -0
@@ -6,6 +6,12 @@ test_description='Test prune and reflog expiration' . ./test-lib.sh +if test "$ref_storage" != "files" +then + skip_all="This test is ref storage backend-specific" + test_done +fi + check_have () { gaah= && for N in "$@"
t/t1430-bad-ref-name.sh +6 -0
@@ -3,6 +3,12 @@ test_description='Test handling of ref names that check-ref-format rejects' . ./test-lib.sh +if test "$ref_storage" = "lmdb" +then + skip_all="The lmdb backend refuses to save refs with bad names" + test_done +fi + test_expect_success setup ' test_commit one && test_commit two
t/t1450-fsck.sh +6 -6
@@ -75,7 +75,7 @@ test_expect_success 'object with bad sha1' ' ' test_expect_success 'branch pointing to non-commit' ' - git rev-parse HEAD^{tree} >.git/refs/heads/invalid && + write_ref refs/heads/invalid $(git rev-parse HEAD^{tree}) && test_when_finished "git update-ref -d refs/heads/invalid" && test_must_fail git fsck 2>out && cat out &&
@@ -220,7 +220,7 @@ test_expect_success 'tag pointing to nonexistent' ' tag=$(git hash-object -t tag -w --stdin <invalid-tag) && test_when_finished "remove_object $tag" && - echo $tag >.git/refs/tags/invalid && + write_ref refs/tags/invalid $tag && test_when_finished "git update-ref -d refs/tags/invalid" && test_must_fail git fsck --tags >out && cat out &&
@@ -241,7 +241,7 @@ test_expect_success 'tag pointing to something else than its type' ' tag=$(git hash-object -t tag -w --stdin <wrong-tag) && test_when_finished "remove_object $tag" && - echo $tag >.git/refs/tags/wrong && + write_ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && test_must_fail git fsck --tags '
@@ -258,7 +258,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' tag=$(git hash-object -t tag -w --stdin <wrong-tag) && test_when_finished "remove_object $tag" && - echo $tag >.git/refs/tags/wrong && + write_ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && git fsck --tags 2>out &&
@@ -282,7 +282,7 @@ test_expect_success 'tag with bad tagger' ' tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) && test_when_finished "remove_object $tag" && - echo $tag >.git/refs/tags/wrong && + write_ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && test_must_fail git fsck --tags 2>out && grep "error in tag .*: invalid author/committer" out
@@ -301,7 +301,7 @@ test_expect_success 'tag with NUL in header' ' tag=$(git hash-object --literally -t tag -w --stdin <tag-NUL-header) && test_when_finished "remove_object $tag" && - echo $tag >.git/refs/tags/wrong && + write_ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && test_must_fail git fsck --tags 2>out && cat out &&
t/t1506-rev-parse-diagnosis.sh +2 -2
@@ -167,7 +167,7 @@ test_expect_success 'relative path when cwd is outside worktree' ' ' test_expect_success 'relative path when startup_info is NULL' ' - test_must_fail test-match-trees HEAD:./file.txt HEAD:./file.txt 2>error && + test_must_fail test-match-trees $(git rev-parse HEAD):./file.txt $(git rev-parse HEAD):./file.txt 2>error && grep "BUG: startup_info struct is not initialized." error '
@@ -213,7 +213,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 && + raw_ref refs/heads/foobar && printf "%s\n" -- } >expect && git rev-parse foobar -- >actual &&
t/t2013-checkout-submodule.sh +1 -1
@@ -8,7 +8,7 @@ test_description='checkout can handle submodules' test_expect_success 'setup' ' mkdir submodule && (cd submodule && - git init && + git init $ref_storage_arg && test_commit first) && git add submodule && test_tick &&
t/t2105-update-index-gitfile.sh +2 -2
@@ -11,7 +11,7 @@ test_description='git update-index for gitlink to .git file. test_expect_success 'submodule with absolute .git file' ' mkdir sub1 && (cd sub1 && - git init && + git init $ref_storage_arg && REAL="$(pwd)/.real" && mv .git "$REAL" && echo "gitdir: $REAL" >.git &&
@@ -25,7 +25,7 @@ test_expect_success 'add gitlink to absolute .git file' ' test_expect_success 'submodule with relative .git file' ' mkdir sub2 && (cd sub2 && - git init && + git init $ref_storage_arg && mv .git .real && echo "gitdir: .real" >.git && test_commit first)
t/t2107-update-index-basic.sh +3 -3
@@ -22,7 +22,7 @@ test_expect_success 'update-index -h with corrupt index' ' mkdir broken && ( cd broken && - git init && + git init $ref_storage_arg && >.git/index && test_expect_code 129 git update-index -h >usage 2>&1 ) &&
@@ -43,7 +43,7 @@ test_expect_success '--cacheinfo does not accept blob null sha1' ' ' test_expect_success '--cacheinfo does not accept gitlink null sha1' ' - git init submodule && + git init submodule $ref_storage_arg && (cd submodule && test_commit foo) && git add submodule && git rev-parse :submodule >expect &&
@@ -70,7 +70,7 @@ test_expect_success '.lock files cleaned up' ' ( cd cleanup && mkdir worktree && - git init repo && + git init $ref_storage_arg repo && cd repo && git config core.worktree ../../worktree && # --refresh triggers late setup_work_tree,
t/t2201-add-update-typechange.sh +2 -2
@@ -46,7 +46,7 @@ test_expect_success modify ' >yomin/yomin && ( cd yomin && - git init && + git init $ref_storage_arg && git add yomin && git commit -m "sub initial" ) &&
@@ -60,7 +60,7 @@ test_expect_success modify ' >yonk/yonk && ( cd yonk && - git init && + git init $ref_storage_arg && git add yonk && git commit -m "sub initial" ) &&
t/t3001-ls-files-others-exclude.sh +1 -1
@@ -197,7 +197,7 @@ test_expect_success 'subdirectory ignore (setup)' ' mkdir -p top/l1/l2 && ( cd top && - git init && + git init $ref_storage_arg && echo /.gitignore >.gitignore && echo l1 >>.gitignore && echo l2 >l1/.gitignore &&
t/t3010-ls-files-killed-modified.sh +2 -2
@@ -55,9 +55,9 @@ test_expect_success 'git update-index --add to add various paths.' ' : >path9 && date >path10 && git update-index --add -- path0 path?/file? pathx/ju path7 path8 path9 path10 && - git init submod1 && + git init $ref_storage_arg submod1 && git -C submod1 commit --allow-empty -m "empty 1" && - git init submod2 && + git init $ref_storage_arg submod2 && git -C submod2 commit --allow-empty -m "empty 2" && git update-index --add submod[12] && (
t/t3040-subprojects-basic.sh +2 -2
@@ -11,10 +11,10 @@ test_expect_success 'setup: create superproject' ' test_expect_success 'setup: create subprojects' ' mkdir sub1 && - ( cd sub1 && git init && : >Makefile && git add * && + ( cd sub1 && git init $ref_storage_arg && : >Makefile && git add * && git commit -q -m "subproject 1" ) && mkdir sub2 && - ( cd sub2 && git init && : >Makefile && git add * && + ( cd sub2 && git init $ref_storage_arg && : >Makefile && git add * && git commit -q -m "subproject 2" ) && git update-index --add sub1 && git add sub2 &&
t/t3050-subprojects-fetch.sh +1 -1
@@ -8,7 +8,7 @@ test_expect_success setup ' test_tick && mkdir -p sub && ( cd sub && - git init && + git init $ref_storage_arg && >subfile && git add subfile && git commit -m "subproject commit #1"
t/t3200-branch.sh +42 -33
203 lines not on this page · raw message
t/t3210-pack-refs.sh +7 -0
@@ -11,6 +11,13 @@ semantic is still the same. ' . ./test-lib.sh +backend=$ref_storage +if test "$backend" = "lmdb" +then + skip_all="The lmdb ref storage doesn't pack refs" + test_done +fi + test_expect_success 'enable reflogs' ' git config core.logallrefupdates true '
t/t3211-peel-ref.sh +6 -0
@@ -3,6 +3,12 @@ test_description='tests for the peel_ref optimization of packed-refs' . ./test-lib.sh +if test "$ref_storage" = "lmdb" +then + skip_all="The lmdb ref storage doesn't pack refs" + test_done +fi + test_expect_success 'create annotated tag in refs/tags' ' test_commit base && git tag -m annotated foo
t/t3308-notes-merge.sh +1 -1
@@ -79,7 +79,7 @@ test_expect_success 'fail to merge empty notes ref into empty notes ref (z => y) test_expect_success 'fail to merge into various non-notes refs' ' test_must_fail git -c "core.notesRef=refs/notes" notes merge x && test_must_fail git -c "core.notesRef=refs/notes/" notes merge x && - mkdir -p .git/refs/notes/dir && + git update-ref refs/notes/dir/test HEAD && test_must_fail git -c "core.notesRef=refs/notes/dir" notes merge x && test_must_fail git -c "core.notesRef=refs/notes/dir/" notes merge x && test_must_fail git -c "core.notesRef=refs/heads/master" notes merge x &&
t/t3404-rebase-interactive.sh +1 -1
@@ -608,7 +608,7 @@ test_expect_success 'submodule rebase setup' ' git checkout A && mkdir sub && ( - cd sub && git init && >elif && + cd sub && git init $ref_storage_arg && >elif && git add elif && git commit -m "submodule initial" ) && echo 1 >file1 &&
t/t3600-rm.sh +1 -1
@@ -220,7 +220,7 @@ test_expect_success 'Remove nonexistent file returns nonzero exit status' ' test_expect_success 'Call "rm" from outside the work tree' ' mkdir repo && (cd repo && - git init && + git init $ref_storage_arg && echo something > somefile && git add somefile && git commit -m "add a file" &&
t/t3800-mktag.sh +2 -2
@@ -224,7 +224,7 @@ EOF test_expect_success \ 'allow empty tag email' \ - 'git mktag <tag.sig >.git/refs/tags/mytag 2>message' + 'write_ref refs/tags/mytag $(git mktag <tag.sig 2>message)' ############################################################ # 16. disallow spaces in tag email
@@ -352,7 +352,7 @@ EOF test_expect_success \ 'create valid tag' \ - 'git mktag <tag.sig >.git/refs/tags/mytag 2>message' + 'write_ref refs/tags/mytag $(git mktag <tag.sig 2>message)' ############################################################ # 25. check mytag
t/t3903-stash.sh +1 -1
@@ -671,7 +671,7 @@ test_expect_success 'store updates stash ref and reflog' ' git reset --hard && ! grep quux bazzy && git stash store -m quuxery $STASH_ID && - test $(cat .git/refs/stash) = $STASH_ID && + test $(git rev-parse stash) = $STASH_ID && git reflog --format=%H stash| grep $STASH_ID && git stash pop && grep quux bazzy
t/t4010-diff-pathspec.sh +1 -1
@@ -112,7 +112,7 @@ test_expect_success 'diff-tree -r with wildcard' ' test_expect_success 'setup submodules' ' test_tick && - git init submod && + git init $ref_storage_arg submod && ( cd submod && test_commit first; ) && git add submod && git commit -m first &&
t/t4020-diff-external.sh +1 -1
@@ -247,7 +247,7 @@ test_expect_success 'clean up crlf leftovers' ' ' test_expect_success 'submodule diff' ' - git init sub && + git init $ref_storage_arg sub && ( cd sub && test_commit sub1 ) && git add sub && test_tick &&
t/t4027-diff-submodule.sh +1 -1
@@ -344,7 +344,7 @@ test_expect_success 'combined (empty submodule)' ' test_expect_success 'combined (with submodule)' ' rm -fr sub && - git clone --no-checkout . sub && + git clone $ref_storage_arg --no-checkout . sub && git diff >actual && test_cmp expect.withsub actual '
t/t4035-diff-quiet.sh +1 -1
@@ -13,7 +13,7 @@ test_expect_success 'setup' ' git commit -a -m second && mkdir -p test-outside/repo && ( cd test-outside/repo && - git init && + git init $ref_storage_arg && echo "1 1" >a && git add . && git commit -m 1
t/t4255-am-submodule.sh +1 -1
@@ -22,7 +22,7 @@ test_expect_success 'setup diff.submodule' ' test_commit one && INITIAL=$(git rev-parse HEAD) && - git init submodule && + git init $ref_storage_arg submodule && ( cd submodule && test_commit two &&
t/t5000-tar-tree.sh +2 -1
@@ -190,7 +190,8 @@ test_expect_success \ test_expect_success \ 'git get-tar-commit-id' \ 'git get-tar-commit-id <b.tar >b.commitid && - test_cmp .git/$(git symbolic-ref HEAD) b.commitid' + raw_ref $(git symbolic-ref HEAD) > expect && + test_cmp expect b.commitid' test_expect_success 'git archive with --output, override inferred format' ' git archive --format=tar --output=d4.zip HEAD &&
t/t5304-prune.sh +1 -1
@@ -93,7 +93,7 @@ test_expect_success 'prune: prune nonsense parameters' ' test_expect_success 'prune: prune unreachable heads' ' git config core.logAllRefUpdates false && - mv .git/logs .git/logs.old && + delete_all_reflogs && : > file2 && git add file2 && git commit -m temporary &&
t/t5312-prune-corruption.sh +9 -2
@@ -21,7 +21,7 @@ test_expect_success 'create history reachable only from a bogus-named ref' ' test_tick && git commit --allow-empty -m bogus && bogus=$(git rev-parse HEAD) && git cat-file commit $bogus >saved && - echo $bogus >.git/refs/heads/bogus..name && + write_ref refs/heads/bogus..name $bogus && git reset --hard HEAD^ '
@@ -47,7 +47,7 @@ test_expect_success 'destructive repack keeps packed object' ' # subsequent tests will have different corruptions test_expect_success 'clean up bogus ref' ' - rm .git/refs/heads/bogus..name + delete_ref refs/heads/bogus..name ' # We create two new objects here, "one" and "two". Our
@@ -85,6 +85,13 @@ test_expect_success 'pack-refs does not silently delete broken loose ref' ' test_cmp expect actual ' +backend=$ref_storage +if test "$backend" = "lmdb" +then + skip="The lmdb backend doesn't write a packed-refs file" + test_done +fi + # we do not want to count on running pack-refs to # actually pack it, as it is perfectly reasonable to # skip processing a broken ref
t/t5500-fetch-pack.sh +5 -5
@@ -30,7 +30,7 @@ add () { test_tick && commit=$(echo "$text" | git commit-tree $tree $parents) && eval "$name=$commit; export $name" && - echo $commit > .git/refs/heads/$branch && + git update-ref refs/heads/$branch $commit && eval ${branch}TIP=$commit }
@@ -45,10 +45,10 @@ pull_to_client () { case "$heads" in *A*) - echo $ATIP > .git/refs/heads/A;; + git update-ref refs/heads/A $ATIP;; esac && case "$heads" in *B*) - echo $BTIP > .git/refs/heads/B;; + git update-ref refs/heads/B $BTIP;; esac && git symbolic-ref HEAD refs/heads/$(echo $heads \ | sed -e "s/^\(.\).*$/\1/") &&
@@ -92,8 +92,8 @@ test_expect_success 'setup' ' cur=$(($cur+1)) done && add B1 $A1 && - echo $ATIP > .git/refs/heads/A && - echo $BTIP > .git/refs/heads/B && + git update-ref refs/heads/A $ATIP && + git update-ref refs/heads/B $BTIP && git symbolic-ref HEAD refs/heads/B '
t/t5510-fetch.sh +15 -15
@@ -28,20 +28,20 @@ test_expect_success setup ' git commit -a -m original' test_expect_success "clone and setup child repos" ' - git clone . one && + git clone $ref_storage_arg . one && ( cd one && echo >file updated by one && git commit -a -m "updated by one" ) && - git clone . two && + git clone $ref_storage_arg . two && ( cd two && git config branch.master.remote one && git config remote.one.url ../one/.git/ && git config remote.one.fetch refs/heads/master:refs/heads/one ) && - git clone . three && + git clone $ref_storage_arg . three && ( cd three && git config branch.master.remote two &&
@@ -53,8 +53,8 @@ test_expect_success "clone and setup child repos" ' echo "Pull: refs/heads/one:refs/heads/one" } >.git/remotes/two ) && - git clone . bundle && - git clone . seven + git clone $ref_storage_arg . bundle && + git clone $ref_storage_arg . seven ' test_expect_success "fetch test" '
@@ -63,7 +63,7 @@ test_expect_success "fetch test" ' git commit -a -m "updated by origin" && cd two && git fetch && - test -f .git/refs/heads/one && + git rev-parse --verify refs/heads/one && mine=$(git rev-parse refs/heads/one) && his=$(cd ../one && git rev-parse refs/heads/master) && test "z$mine" = "z$his"
@@ -73,8 +73,8 @@ test_expect_success "fetch test for-merge" ' cd "$D" && cd three && git fetch && - test -f .git/refs/heads/two && - test -f .git/refs/heads/one && + git rev-parse --verify refs/heads/two && + git rev-parse --verify refs/heads/one && master_in_two=$(cd ../two && git rev-parse master) && one_in_two=$(cd ../two && git rev-parse one) && {
@@ -180,7 +180,7 @@ test_expect_success 'fetch tags when there is no tags' ' mkdir notags && cd notags && - git init && + git init $ref_storage_arg && git fetch -t ..
@@ -194,7 +194,7 @@ test_expect_success 'fetch following tags' ' mkdir four && cd four && - git init && + git init $ref_storage_arg && git fetch .. :track && git show-ref --verify refs/tags/anno &&
@@ -204,7 +204,7 @@ test_expect_success 'fetch following tags' ' test_expect_success 'fetch uses remote ref names to describe new refs' ' cd "$D" && - git init descriptive && + git init $ref_storage_arg descriptive && ( cd descriptive && git config remote.o.url .. &&
@@ -238,7 +238,7 @@ test_expect_success 'fetch must not resolve short tag name' ' mkdir five && cd five && - git init && + git init $ref_storage_arg && test_must_fail git fetch .. anno:five
@@ -251,7 +251,7 @@ test_expect_success 'fetch can now resolve short remote name' ' mkdir six && cd six && - git init && + git init $ref_storage_arg && git fetch .. six:six '
@@ -529,7 +529,7 @@ test_expect_success "should be able to fetch with duplicate refspecs" ' mkdir dups && ( cd dups && - git init && + git init $ref_storage_arg && git config branch.master.remote three && git config remote.three.url ../three/.git && git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
@@ -665,7 +665,7 @@ test_expect_success 'fetching a one-level ref works' ' test_commit extra && git reset --hard HEAD^ && git update-ref refs/foo extra && - git init one-level && + git init $ref_storage_arg one-level && ( cd one-level && git fetch .. HEAD refs/foo
t/t5526-fetch-submodules.sh +2 -2
@@ -38,7 +38,7 @@ test_expect_success setup ' mkdir deepsubmodule && ( cd deepsubmodule && - git init && + git init $ref_storage_arg && echo deepsubcontent > deepsubfile && git add deepsubfile && git commit -m new deepsubfile
@@ -46,7 +46,7 @@ test_expect_success setup ' mkdir submodule && ( cd submodule && - git init && + git init $ref_storage_arg && echo subcontent > subfile && git add subfile && git submodule add "$pwd/deepsubmodule" subdir/deepsubmodule &&
t/t5527-fetch-odd-refs.sh +7 -0
@@ -26,6 +26,13 @@ test_expect_success 'suffix ref is ignored during fetch' ' test_cmp expect actual ' +backend=$ref_storage +if test "$backend" = "lmdb" +then + skip="The lmdb backend doesn't do crazy-long refs" + test_done +fi + test_expect_success 'try to create repo with absurdly long refname' ' ref240=$_z40/$_z40/$_z40/$_z40/$_z40/$_z40 && ref1440=$ref240/$ref240/$ref240/$ref240/$ref240/$ref240 &&
t/t5537-fetch-shallow.sh +7 -0
@@ -173,6 +173,13 @@ EOF ) ' +backend=$ref_storage +if test "$backend" = "lmdb" +then + skip="The lmdb backend needs write access for its locks" + test_done +fi + test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' ' cp -R .git read-only.git && find read-only.git -print | xargs chmod -w &&
t/t5700-clone-reference.sh +21 -21
132 lines not on this page · raw message
t/t6001-rev-list-graft.sh +2 -1
@@ -20,7 +20,8 @@ test_expect_success setup ' git commit -a -m "Third in one history." && A2=$(git rev-parse --verify HEAD) && - rm -f .git/refs/heads/master .git/index && + delete_ref refs/heads/master && + rm -f .git/index && echo >fileA fileA again && echo >subdir/fileB fileB again &&
t/t6010-merge-base.sh +1 -1
@@ -34,7 +34,7 @@ doit () { commit=$(echo $NAME | git commit-tree $T $PARENTS) && - echo $commit >.git/refs/tags/$NAME && + git update-ref refs/tags/$NAME $commit && echo $commit }
t/t6050-replace.sh +2 -2
@@ -124,13 +124,13 @@ tagger T A Gger <> 0 +0000 EOF test_expect_success 'tag replaced commit' ' - git mktag <tag.sig >.git/refs/tags/mytag 2>message + write_ref refs/tags/mytag $(git mktag <tag.sig 2>message) ' test_expect_success '"git fsck" works' ' git fsck master >fsck_master.out && grep "dangling commit $R" fsck_master.out && - grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && + grep "dangling tag $(raw_ref refs/tags/mytag)" fsck_master.out && test -z "$(git fsck)" '
t/t6120-describe.sh +4 -2
@@ -128,7 +128,8 @@ test_expect_success 'no warning was displayed for A' ' ' test_expect_success 'rename tag A to Q locally' ' - mv .git/refs/tags/A .git/refs/tags/Q + write_ref refs/tags/Q $(raw_ref refs/tags/A) && + delete_ref refs/tags/A ' cat - >err.expect <<EOF warning: tag 'A' is really 'Q' here
@@ -138,7 +139,8 @@ test_expect_success 'warning was displayed for Q' ' test_i18ncmp err.expect err.actual ' test_expect_success 'rename tag Q back to A' ' - mv .git/refs/tags/Q .git/refs/tags/A + write_ref refs/tags/A $(raw_ref refs/tags/Q) && + delete_ref refs/tags/Q ' test_expect_success 'pack tag refs' 'git pack-refs'
t/t6301-for-each-ref-errors.sh +6 -6
@@ -16,8 +16,8 @@ test_expect_success setup ' test_expect_success 'Broken refs are reported correctly' ' r=refs/heads/bogus && - : >.git/$r && - test_when_finished "rm -f .git/$r" && + write_ref $r '' && + test_when_finished "delete_ref $r" && echo "warning: ignoring broken ref $r" >broken-err && git for-each-ref >out 2>err && test_cmp full-list out &&
@@ -26,8 +26,8 @@ test_expect_success 'Broken refs are reported correctly' ' test_expect_success 'NULL_SHA1 refs are reported correctly' ' r=refs/heads/zeros && - echo $ZEROS >.git/$r && - test_when_finished "rm -f .git/$r" && + write_ref $r $ZEROS && + test_when_finished "delete_ref $r" && echo "warning: ignoring broken ref $r" >zeros-err && git for-each-ref >out 2>err && test_cmp full-list out &&
@@ -39,8 +39,8 @@ test_expect_success 'NULL_SHA1 refs are reported correctly' ' test_expect_success 'Missing objects are reported correctly' ' r=refs/heads/missing && - echo $MISSING >.git/$r && - test_when_finished "rm -f .git/$r" && + write_ref $r $MISSING && + test_when_finished "delete_ref $r" && echo "fatal: missing object $MISSING for $r" >missing-err && test_must_fail git for-each-ref 2>err && test_cmp missing-err err &&
t/t7201-co.sh +1 -1
@@ -65,7 +65,7 @@ test_expect_success setup ' test_expect_success "checkout from non-existing branch" ' git checkout -b delete-me master && - rm .git/refs/heads/delete-me && + git update-ref -d --no-deref refs/heads/delete-me && test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && git checkout master && test refs/heads/master = "$(git symbolic-ref HEAD)"
t/t7300-clean.sh +13 -12
@@ -431,7 +431,7 @@ test_expect_success 'nested git work tree' ' mkdir -p foo bar baz/boo && ( cd foo && - git init && + git init $ref_storage_arg && test_commit nested hello.world ) && (
@@ -440,7 +440,7 @@ test_expect_success 'nested git work tree' ' ) && ( cd baz/boo && - git init && + git init $ref_storage_arg && test_commit deeply.nested deeper.world ) && git clean -f -d &&
@@ -455,6 +455,7 @@ test_expect_success 'should clean things that almost look like git but are not' rm -fr almost_git almost_bare_git almost_submodule && mkdir -p almost_git/.git/objects && mkdir -p almost_git/.git/refs && + mkdir -p almost_git/.git/refs.lmdb && cat >almost_git/.git/HEAD <<-\EOF && garbage EOF
@@ -475,7 +476,7 @@ test_expect_success 'should not clean submodules' ' mkdir repo to_clean && ( cd repo && - git init && + git init $ref_storage_arg && test_commit msg hello.world ) && git submodule add ./repo/.git sub1 &&
@@ -511,7 +512,7 @@ test_expect_success POSIXPERM 'should avoid cleaning possible submodules' ' test_expect_success 'nested (empty) git should be kept' ' rm -fr empty_repo to_clean && - git init empty_repo && + git init $ref_storage_arg empty_repo && mkdir to_clean && >to_clean/should_clean.this && git clean -f -d &&
@@ -521,7 +522,7 @@ test_expect_success 'nested (empty) git should be kept' ' test_expect_success 'nested bare repositories should be cleaned' ' rm -fr bare1 bare2 subdir && - git init --bare bare1 && + git init $ref_storage_arg --bare bare1 && git clone --local --bare . bare2 && mkdir subdir && cp -r bare2 subdir/bare3 &&
@@ -534,7 +535,7 @@ test_expect_success 'nested bare repositories should be cleaned' ' test_expect_failure 'nested (empty) bare repositories should be cleaned even when in .git' ' rm -fr strange_bare && mkdir strange_bare && - git init --bare strange_bare/.git && + git init $ref_storage_arg --bare strange_bare/.git && git clean -f -d && test_path_is_missing strange_bare '
@@ -552,7 +553,7 @@ test_expect_success 'giving path in nested git work tree will remove it' ' mkdir repo && ( cd repo && - git init && + git init $ref_storage_arg && mkdir -p bar/baz && test_commit msg bar/baz/hello.world ) &&
@@ -567,7 +568,7 @@ test_expect_success 'giving path to nested .git will not remove it' ' mkdir repo untracked && ( cd repo && - git init && + git init $ref_storage_arg && test_commit msg hello.world ) && git clean -f -d repo/.git &&
@@ -582,7 +583,7 @@ test_expect_success 'giving path to nested .git/ will remove contents' ' mkdir repo untracked && ( cd repo && - git init && + git init $ref_storage_arg && test_commit msg hello.world ) && git clean -f -d repo/.git/ &&
@@ -596,7 +597,7 @@ test_expect_success 'force removal of nested git work tree' ' mkdir -p foo bar baz/boo && ( cd foo && - git init && + git init $ref_storage_arg && test_commit nested hello.world ) && (
@@ -605,7 +606,7 @@ test_expect_success 'force removal of nested git work tree' ' ) && ( cd baz/boo && - git init && + git init $ref_storage_arg && test_commit deeply.nested deeper.world ) && git clean -f -f -d &&
@@ -619,7 +620,7 @@ test_expect_success 'git clean -e' ' mkdir repo && ( cd repo && - git init && + git init $ref_storage_arg && touch known 1 2 3 && git add known && git clean -f -e 1 -e 2 &&
t/t7400-submodule-basic.sh +9 -9
@@ -32,7 +32,7 @@ test_expect_success 'setup - repository in init subdirectory' ' mkdir init && ( cd init && - git init && + git init $ref_storage_arg && echo a >a && git add a && git commit -m "submodule commit 1" &&
@@ -52,8 +52,8 @@ test_expect_success 'setup - hide init subdirectory' ' ' test_expect_success 'setup - repository to add submodules to' ' - git init addtest && - git init addtest-ignore + git init $ref_storage_arg addtest && + git init $ref_storage_arg addtest-ignore ' # The 'submodule add' tests need some repository to add as a submodule.
@@ -540,7 +540,7 @@ test_expect_success 'add submodules without specifying an explicit path' ' mkdir repo && ( cd repo && - git init && + git init $ref_storage_arg && echo r >r && git add r && git commit -m "repo commit 1"
@@ -585,11 +585,11 @@ test_expect_success 'set up for relative path tests' ' mkdir reltest && ( cd reltest && - git init && + git init $ref_storage_arg && mkdir sub && ( cd sub && - git init && + git init $ref_storage_arg && test_commit foo ) && git add sub &&
@@ -754,7 +754,7 @@ test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.gi cp pristine-.git-config .git/config && cp pristine-.gitmodules .gitmodules && mkdir -p a/b/c && - (cd a/b/c; git init) && + (cd a/b/c; git init $ref_storage_arg) && git config remote.origin.url ../foo/bar.git && git submodule add ../bar/a/b/c ./a/b/c && git submodule init &&
@@ -975,7 +975,7 @@ test_expect_success 'submodule with UTF-8 name' ' mkdir "$svname" && ( cd "$svname" && - git init && + git init $ref_storage_arg && >sub && git add sub && git commit -m "init sub"
@@ -990,7 +990,7 @@ test_expect_success 'submodule add clone shallow submodule' ' pwd=$(pwd) && ( cd super && - git init && + git init $ref_storage_arg && git submodule add --depth=1 file://"$pwd"/example2 submodule && ( cd submodule &&
t/t7402-submodule-rebase.sh +1 -1
@@ -13,7 +13,7 @@ test_expect_success setup ' git add file && test_tick && git commit -m initial && - git clone . submodule && + git clone $ref_storage_arg . submodule && git add submodule && test_tick && git commit -m submodule &&
t/t7405-submodule-merge.sh +5 -5
@@ -18,7 +18,7 @@ test_expect_success setup ' mkdir sub && (cd sub && - git init && + git init $ref_storage_arg && echo original > file && git add file && test_tick &&
@@ -68,10 +68,10 @@ test_expect_success setup ' test_expect_success 'setup for merge search' ' mkdir merge-search && (cd merge-search && - git init && + git init $ref_storage_arg && mkdir sub && (cd sub && - git init && + git init $ref_storage_arg && echo "file-a" > file-a && git add file-a && git commit -m "sub-a" &&
@@ -232,10 +232,10 @@ test_expect_success 'merging with a modify/modify conflict between merge bases' test_expect_success 'setup for recursive merge with submodule' ' mkdir merge-recursive && (cd merge-recursive && - git init && + git init $ref_storage_arg && mkdir sub && (cd sub && - git init && + git init $ref_storage_arg && test_commit a && git checkout -b sub-b master && test_commit b &&
t/t9104-git-svn-follow-parent.sh +2 -1
@@ -213,7 +213,8 @@ test_expect_success "multi-fetch continues to work" " " test_expect_success "multi-fetch works off a 'clean' repository" ' - rm -r "$GIT_DIR/svn" "$GIT_DIR/refs/remotes" "$GIT_DIR/logs" && + rm -rf "$GIT_DIR/svn" "$GIT_DIR/refs/remotes" && + git reflog expire --all --expire=all && mkdir "$GIT_DIR/svn" && git svn multi-fetch '
t/t9115-git-svn-dcommit-funky-renames.sh +1 -1
@@ -60,7 +60,7 @@ test_expect_success 'add a file with plus signs' ' ' test_expect_success 'clone the repository to test rebase' ' - git svn clone "$svnrepo" test-rebase && + git svn clone $ref_storage_arg "$svnrepo" test-rebase && ( cd test-rebase && echo test-rebase >test-rebase &&
t/t9350-fast-export.sh +3 -3
@@ -42,7 +42,7 @@ test_expect_success 'fast-export | fast-import' ' WER=$(git rev-parse --verify wer) && MUSS=$(git rev-parse --verify muss) && mkdir new && - git --git-dir=new/.git init && + git --git-dir=new/.git init $ref_storage_arg && git fast-export --all | (cd new && git fast-import &&
@@ -158,7 +158,7 @@ test_expect_success 'setup submodule' ' mkdir sub && ( cd sub && - git init && + git init $ref_storage_arg && echo test file > file && git add file && git commit -m sub_initial
@@ -183,7 +183,7 @@ test_expect_success 'submodule fast-export | fast-import' ' SUBENT2=$(git ls-tree master sub) && rm -rf new && mkdir new && - git --git-dir=new/.git init && + git --git-dir=new/.git init $ref_storage_arg && git fast-export --signed-tags=strip --all | (cd new && git fast-import &&
t/t9902-completion.sh +2 -1
@@ -126,7 +126,7 @@ actual="$TRASH_DIRECTORY/actual" test_expect_success 'setup for __gitdir tests' ' mkdir -p subdir/subsubdir && - git init otherrepo + git init $ref_storage_arg otherrepo ' test_expect_success '__gitdir - from command line (through $__git_dir)' '
@@ -177,6 +177,7 @@ test_expect_success '__gitdir - cwd is a .git directory' ' test_expect_success '__gitdir - parent is a .git directory' ' echo "$(pwd -P)/.git" >expected && ( + mkdir -p .git/refs/heads && cd .git/refs/heads && __gitdir >"$actual" ) &&
t/t9903-bash-prompt.sh +1 -0
@@ -148,6 +148,7 @@ test_expect_success 'prompt - inside .git directory' ' test_expect_success 'prompt - deep inside .git directory' ' printf " (GIT_DIR!)" >expected && ( + mkdir -p .git/refs/heads && cd .git/refs/heads && __git_ps1 >"$actual" ) &&
t/test-lib-functions.sh +51 -2
62 lines not on this page · raw message
t/test-lib.sh +11 -0
@@ -186,6 +186,8 @@ test "x$TERM" != "xdumb" && ( ) && color=t +ref_storage="files" +ref_storage_arg= while test "$#" -ne 0 do case "$1" in
@@ -201,6 +203,9 @@ do exit 1; } run_list=$1; shift ;; + --ref-storage=*) + GIT_TEST_REF_STORAGE=$(expr "z$1" : 'z[^=]*=\(.*\)'); shift + ;; --run=*) run_list=$(expr "z$1" : 'z[^=]*=\(.*\)'); shift ;; -h|--h|--he|--hel|--help)
@@ -247,6 +252,12 @@ do esac done +if test -n "$GIT_TEST_REF_STORAGE" +then + ref_storage=$GIT_TEST_REF_STORAGE + ref_storage_arg="--ref-storage=$ref_storage" +fi + if test -n "$valgrind_only" then test -z "$valgrind" && valgrind=memcheck
Signature · 1 line
2.4.2.767.g62658d5-twtrsrc
Re: [PATCH v6 03/32] files-backend: break out ref reading
In reply to David TurnerQuoted 21 lines · David Turner
Refactor
resolve_ref_1in terms of a new functionread_raw_ref, which is responsible for reading ref data from the ref storage.Later, we will make
read_raw_refa pluggable backend function, and makeresolve_ref_unsafecommon.Testing done: Hacked in code to run both old and new version of
resolve_ref_1and compare all outputs, failing dramatically if outputs differed. Ran test suite.Signed-off-by David Turner <[email protected]>Helped-by Duy Nguyen <[email protected]>--- refs/files-backend.c | 265 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 159 insertions(+), 106 deletions(-)refs/files-backend.c +0
-0
refs/files-backend.c static struct ref_entry *get_packed_ref(const char *refname) · line 1384
Quoted 10 lines
refs/files-backend.c +1
-2@@ -1377,10 +1377,9 @@ static struct ref_entry *get_packed_ref(const char *refname)/* * A loose ref file doesn't exist; check for a packed ref. The -* options are forwarded from resolve_safe_unsafe(). +* options are forwarded from resolve_ref_unsafe(). */ static int resolve_missing_loose_ref (const char *refname, -int resolve_flags,unsigned char *sha1,int *flags)
The last parameter must be made "unsigned int *flags" ...
refs/files-backend.c static int resolve_missing_loose_ref(const char *refname, · line 1429
Quoted 4 lines
refs/files-backend.c +3
-0+static int read_raw_ref (const char *refname,unsigned char *sha1, +struct strbuf *symref,struct strbuf *sb_path, +unsigned int *flags) {
... because the last parameter here is "unsigned int *flags", and you later pass the same variable to both.
refs/files-backend.c static int resolve_missing_loose_ref(const char *refname, · line 1439
Quoted 3 lines
refs/files-backend.c +1
-2-for (;;) { -const char *path; +for (;;) {
This is an unwelcome change.
refs/files-backend.c static const char *resolve_ref_1(const char *refname, · line 1455
Quoted 2 lines
refs/files-backend.c +2
-0+break ; +if (resolve_missing_loose_ref (refname, sha1, flags))
This line has a trailing whitespace.
refs/files-backend.c static const char *resolve_ref_1(const char *refname, · line 1581
Quoted 2 lines
refs/files-backend.c +2
-0+for (symref_count =0 ; symref_count <MAXDEPTH ; symref_count++) { +int read_flags =0 ;
... and this must be "unsigned read_flags = 0".
You can of course standardize on signed int, but because this is a collection of flag bits, there is no reason not to choose unsigned.
I _think_ I can fix everything up before pushing out, so please check what will appear on 'pu' before rerolling.
Thanks.
Re: [PATCH v6 03/32] files-backend: break out ref reading
Quoted 6 lines · Junio C Hamano
...
You can of course standardize on signed int, but because this is a collection of flag bits, there is no reason not to choose unsigned.I _think_ I can fix everything up before pushing out, so please check what will appear on 'pu' before rerolling.
I managed to whip them into shape enough to pass my compilation test ;-) Other things I had to tweak were small things like whitespace issues, initializing statics to 0 or NULL, etc.
Thanks.
Re: [PATCH v6 04/32] refs: move resolve_ref_unsafe into common code
In reply to David Turnerrefs.c int for_each_rawref(each_ref_fn fn, void *cb_data) · line 1195
Quoted 2 lines · David Turner
refs.c +2
-0+for (symref_count =0 ; symref_count <SYMREF_MAXDEPTH ; symref_count++) { +int read_flags =0 ;
Continuing from the previous one, this becomes "unsigned int".
Quoted 56 lines · David Turner
This version incorporates fixes for function scope from Ramsay Jones.
It breaks patches down a bit more, to make them easier to review and understand. Michael Haggerty had some suggestions here.
As suggested by Duy Nguyen, it replaces the
resolve_ref_unsafebackend method withread_raw_ref, movingresolve_ref_unsafeto the common code.It adds support for running tests under alternate ref backends.
It fixes two indentation errors, one reported by Eric Wong.
It updates the documentation to include info about a few more limitations on the LMDB backend. It incorporates other LMDB-related suggestions from Duy Nguyen, e.g. using
MDB_NOSUBDIR.There's a fix for non-normal ref renames, also from Duy Nguyen.
Symbolic ref splitting has a bug fix, suggested by Michael Haggerty.
There are other, more minor changes suggested by Michael Haggerty and Duy Nguyen.
David Turner (29):
refs: move head_ref{,_submodule} to the common code
refs: move for_each_*ref* functions into common code
files-backend: break out ref reading
refs: moveresolve_ref_unsafeinto common code
refs: add method fordo_for_each_ref
refs: adddo_for_each_per_worktree_ref
refs: add methods for reflog
refs: add method for initial ref transaction commit
refs: add method fordelete_refs
refs: add methods to init refs db
refs: add method to rename refs
refs: handle non-normal ref renames
refs: make lock generic
refs: move duplicate check to common code
refs: allow log-only updates
refs: don't dereference on rename
refs: on symref reflog expire, lock symref not referrent
refs: resolve symbolic refs first
refs: always handle non-normal refs in files backend
init: allow alternate ref strorage to be set for new repos
refs: check submodules' ref storage config
clone: allow ref storage backend to be set for clone
svn: learn ref-storage argument
refs: register ref storage backends
config: read ref storage config on startup
refs: break outresolve_ref_unsafe_submodule
refs: add LMDB refs storage backend
refs: tests for lmdb backend
tests: add ref-storage argument
Quoted 2 lines
Ramsay Jones (1):
refs: reduce the visibility ofdo_for_each_ref()
Ah, sorry if it wasn't clear, but there is no need to keep this as a separate patch - it should simply be squashed into the relevant patch in your series.
ATB,
Ramsay Jones
Re: [PATCH v6 03/32] files-backend: break out ref reading
In reply to Junio C HamanoQuoted 6 lines · Junio C Hamano
Quoted 4 lines · Junio C Hamano
...
You can of course standardize on signed int, but because this is a collection of flag bits, there is no reason not to choose unsigned.
Quoted 6 lines
Quoted 2 lines
I _think_ I can fix everything up before pushing out, so please check what will appear on 'pu' before rerolling.
I managed to whip them into shape enough to pass my compilation test ;-) Other things I had to tweak were small things like whitespace issues, initializing statics to 0 or NULL, etc.
Got it, thanks.
Is there some standard workflow here? I just rebased your version of my series (bd412fa) on top of the prior commit in pu (9db66d9), fixing the few conflicts. (I think there is in general something I'm missing about how to maintain a patch set under the git.git workflow).
Re: [PATCH v6 03/32] files-backend: break out ref reading
Quoted 4 lines · David Turner
Is there some standard workflow here? I just rebased your version of my series (bd412fa) on top of the prior commit in pu (9db66d9), fixing the few conflicts. (I think there is in general something I'm missing about how to maintain a patch set under the git.git workflow).
We usually do not see multiple large topics stomping on each other's toes, so it would be fair to say that we are still learning to find some standard workflow. The topic overlaps with what Stefan's submodule-parallel-update topic touches, and both topics are constantly rerolled, so I've been doing:
* Pick a commit on 'master' as a stable base, and do not change this unless absolutely necessary.
* Merge the tip of Stefan's series to it.
* Apply your series on top (if you didn't rebase, but Stefan rerolled, this will be cherry-pick of your latest round).
to rebuild dt/refs-backend-lmdb topic every time either one of you rerolled.
Quoted 9 lines · Ramsay Jones
Quoted 2 lines
Ramsay Jones (1):
refs: reduce the visibility ofdo_for_each_ref()Ah, sorry if it wasn't clear, but there is no need to keep this as a separate patch - it should simply be squashed into the relevant patch in your series.
ATB,
Ramsay Jones
It actually seemed cleaner to do it this way for some reason.
A couple of build warnings I found, haven't really read the code yet. These two can easily be fixed
refs/lmdb-backend.c: In function 'lmdb_read_raw_ref':refs/lmdb-backend.c:554:16: warning: unused variable 'err' [-Wunused-variable]
struct strbuf err = STRBUF_INIT;
^
refs/lmdb-backend.c: In function 'lmdb_do_for_each_ref':
refs/lmdb-backend.c:1625:15: warning: unused variable 'c' [-Wunused-variable]
const char *c = resolve_ref_unsafe_submodule(submodule, refname, 0, oid.hash,
^-Wshadow also gives a bunch of warnings, mostly about "transaction" and "env". Whether you want to fix them is really up to you. --
Duy
Quoted 13 lines · Duy Nguyen
A couple of build warnings I found, haven't really read the code yet. These two can easily be fixed
refs/lmdb-backend.c: In function 'lmdb_read_raw_ref':refs/lmdb-backend.c:554:16: warning: unused variable 'err' [-Wunused -variable]struct strbuf err = STRBUF_INIT; ^
refs/lmdb-backend.c: In function 'lmdb_do_for_each_ref':refs/lmdb-backend.c:1625:15: warning: unused variable 'c' [-Wunused -variable]
const char *c = resolve_ref_unsafe_submodule(submodule, refname,
0, oid.hash,
Quoted 6 lines
^-Wshadow also gives a bunch of warnings, mostly about "transaction" and "env". Whether you want to fix them is really up to you. --
Duy
Will fix these, thanks. I've now configured my config.mak to do -Wall again, but -Wshadow produces a ton of complaints on the rest of git's
code. We should probably fix those.
Quoted 16 lines · David Turner
Quoted 15 lines · Duy Nguyen
A couple of build warnings I found, haven't really read the code yet. These two can easily be fixed
refs/lmdb-backend.c: In function 'lmdb_read_raw_ref':refs/lmdb-backend.c:554:16: warning: unused variable 'err' [-Wunused -variable]struct strbuf err = STRBUF_INIT; ^
refs/lmdb-backend.c: In function 'lmdb_do_for_each_ref':refs/lmdb-backend.c:1625:15: warning: unused variable 'c' [-Wunused -variable]
const char *c = resolve_ref_unsafe_submodule(submodule, refname,
0, oid.hash,^
Quoted 8 lines
Quoted 4 lines
-Wshadow also gives a bunch of warnings, mostly about "transaction" and "env". Whether you want to fix them is really up to you. --
DuyWill fix these, thanks. I've now configured my config.mak to do -Wall again, but -Wshadow produces a ton of complaints on the rest of git's
code. We should probably fix those.
It is a proposal for the GSoC microprojects to fix all -Wshadow problems in say one file. Maybe we'll see some activity there :)
Quoted 2 lines · David Turner
but -Wshadow produces a ton of complaints on the rest of git's
code. We should probably fix those.
I know, but what I wrote was meant for new code only (e.g. make refs/lmdb-backend.o CFLAGS=-Wshadow is clean). I think renaming the global env and transaction to the_env and the_transaction probably does the trick. Again, this is controversial whether it's a good thing to do. So your choice.
Signature · 1 line
Duy
Re: [PATCH v6 05/32] refs: add a backend method structure with transaction functions
In reply to David Turnerrefs.c line 31
Quoted 11 lines · David Turner
refs.c +11
-0+int set_ref_storage_backend (const char *name) +{ +struct ref_storage_be *be; + +for (be = refs_backends; be; be = be->next) +if (!strcmp (be->name, name)) { + the_refs_backend = be; +return 0 ; + } +return 1 ; +}
So we search through the list and assign the_refs_backend if we find something, returning 0 for success, and 1 if we found nothing. OK (though our usual convention is that if 0 is success, -1 is the error case).
refs.c line 43
Quoted 11 lines
refs.c +11
-0+int ref_storage_backend_exists (const char *name) +{ +struct ref_storage_be *be; + +for (be = refs_backends; be; be = be->next) +if (!strcmp (be->name, name)) { + the_refs_backend = be; +return 1 ; + } +return 0 ; +}
Here we do the same thing, but we get "1" for exists, and "0" otherwise. That makes sense if this is about querying for existence. But why does the query function still set the_refs_backend?
I'm guessing the assignment in the second one is just copy-pasta, but maybe the whole thing would be simpler if they could share the implementation, like:
struct ref_storage_be *find_ref_storage_backend(const char *name)
{
struct ref_storage *be;
for (be = refs_backends; be; be = be->next)
if (!strcmp(be->name, name))
return be;
return NULL;}
int set_ref_storage_backend(const char *name)
{
struct ref_storage *be = find_ref_storage_backend(name);
if (!be)
return -1;
the_refs_backend = be;
return 0;}
You don't really need an "exists", as you can check that "find" doesn't return NULL, but you could wrap it, of course.
-Peff
Re: [PATCH v6 28/32] config: read ref storage config on startup
In reply to David TurnerQuoted 17 lines · David Turner
config.c +13
-0@@ -1207,6 +1208,29 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) }if (repo_config && !access_or_die (repo_config,R_OK ,0 )) { +char *storage =NULL ; + +/* +* make sure we always read the ref storage config +* from the extensions section on startup +*/ + ret +=git_config_from_file (ref_storage_backend_config, + repo_config, &storage); + +register_ref_storage_backends (); +if (!storage) + storage =xstrdup ("" ); +
config.c int git_config_early(config_fn_t fn, void *data, const char *repo_config) · line 1233
Quoted 10 lines
config.c +10
-0+if (!*storage || + !strcmp (storage,"files" )) { +/* default backend, nothing to do */ +free (storage); + }else { +if (set_ref_storage_backend (ref_storage_backend)) +die (_ ("Unknown ref storage backend %s" ), + ref_storage_backend); + } +
Coverity complains that "storage" leaks here, and I think it does in the case that we non-default storage, and we successfully set up the backend. That's a pretty minor point.
However, after looking at this code, I'm rather confused about a few things.
One is that we read the config and use ref_storage_backend_config[1] to store the string value in "storage", and then we check whether that is non-default, and if it is, I'd expect us to feed it to set_ref_storage_backend. But we don't; we feed ref_storage_backend instead!
What is that value? It looks like it is the string we set in check_repo_format when we load the extensions list there. So why are we re-reading the config here at all? Couldn't we just use ref_storage_backend in the first place?
My second confusion is why this is happening in git_config_early(). That function is called during the setup of check_repository_format_gently(), which is why I think you wanted to put the code here. But it's _also_ called as part of a regular git_config(). Which means we're parsing the repo config and setting the ref backend all over again, every time we look at config for other reasons.
So I think this setup probably should be in check_repository_format_gently(), and should be able to trigger off of the existing ref_storage_backend string we've already saved (and we should bail immediately there if we don't know about the backend, as it means we _don't_ match the repo's extensions and cannot proceed).
-Peff
[1] The ref_storage_backend_config function uses xstrdup(), which I think will segfault for a value-less boolean config, like:
[extensions]
# notice no "=" sign!
refstorage
The same bug is in check_repo_format, where we assigned ref_storage_backend. The normal way to do this is to use:
return git_config_string(var, value, &ref_backend_storage);
which checks for the boolean case and complains.
Re: [PATCH v6 28/32] config: read ref storage config on startup
Quoted 7 lines · Jeff King
My second confusion is why this is happening in
git_config_early(). That function is called during the setup ofcheck_repository_format_gently(), which is why I think you wanted to put the code here. But it's _also_ called as part of a regulargit_config(). Which means we're parsing the repo config and setting the ref backend all over again, every time we look at config for other reasons.
Quoted 5 lines
So I think this setup probably should be in
check_repository_format_gently(), and should be able to trigger off of the existingref_storage_backendstring we've already saved (and we should bail immediately there if we don't know about the backend, as it means we _don't_ match the repo's extensions and cannot proceed).
By the way, I notice that the default value for the_refs_backend is "&refs_be_files". It might be safer to make this NULL (or some &refs_be_null that fills the vtable, but just returns an error for each call).
Then in check_repository_format_gently(), do:
if (!ref_storage_backend || !*ref_storage_backend)
refs_backend_storage = "files";
set_ref_storage_backend(ref_storage_backend);
That way you could be sure that the backend has been initialized from the config, and never blindly falls back to the "files" backend. If there is any code path where we try to access refs but the_refs_backend is null, that's a bug that needs fixing. But it's a lot easier to find such bugs if we die loudly in that case rather than silently using "files".
-Peff
Re: [PATCH v6 05/32] refs: add a backend method structure with transaction functions
In reply to Jeff KingQuoted 18 lines · Jeff King
refs.c line 31
Quoted 11 lines · David Turner
refs.c +11
-0+int set_ref_storage_backend (const char *name) +{ +struct ref_storage_be *be; + +for (be = refs_backends; be; be = be->next) +if (!strcmp (be->name, name)) { + the_refs_backend = be; +return 0 ; + } +return 1 ; +}So we search through the list and assign
the_refs_backendif we find something, returning 0 for success, and 1 if we found nothing. OK (though our usual convention is that if 0 is success, -1 is the error case).
Will fix.
Quoted 8 lines
Quoted 8 lines
refs.c +8
-0+int ref_storage_backend_exists (const char *name) +{ +struct ref_storage_be *be; + +for (be = refs_backends; be; be = be->next) +if (!strcmp (be->name, name)) { + the_refs_backend = be; +return 1 ;
Quoted 8 lines
refs.c line 43
Quoted 3 lines
refs.c +3
-0+ } +return 0 ; +}Here we do the same thing, but we get "1" for exists, and "0" otherwise. That makes sense if this is about querying for existence. But
why does the query function still setthe_refs_backend?
Yeah, that's wrong.
Quoted 20 lines
I'm guessing the assignment in the second one is just copy-pasta, but maybe the whole thing would be simpler if they could share the implementation, like:
struct
ref_storage_be*find_ref_storage_backend(const char *name){ struct ref_storage *be; for (be = refs_backends; be; be = be->next) if (!strcmp(be->name, name)) return be; return NULL;}
int
set_ref_storage_backend(const char *name){ struct ref_storage *be = find_ref_storage_backend(name); if (!be) return -1; the_refs_backend = be; return 0;
Quoted 5 lines
}
You don't really need an "exists", as you can check that "find" doesn't
return NULL, but you could wrap it, of course.
I'd rather wrap it to keep the backends firmly inside the refs-internal barrier.
Thanks.
Re: [PATCH v6 28/32] config: read ref storage config on startup
In reply to Jeff KingQuoted 22 lines · Jeff King
Quoted 12 lines · Jeff King
My second confusion is why this is happening in
git_config_early(). That
function is called during the setup ofcheck_repository_format_gently(),
which is why I think you wanted to put the code here. But it's _also_
called as part of a regulargit_config(). Which means we're parsing the
repo config and setting the ref backend all over again, every time we
look at config for other reasons.Quoted 7 lines
So I think this setup probably should be in
check_repository_format_gently(), and should be able to trigger off of
the existingref_storage_backendstring we've already saved (and we should bail immediately there if we don't know about the backend, as it
means we _don't_ match the repo's extensions and cannot proceed).
Quoted 5 lines
By the way, I notice that the default value for
the_refs_backendis "&refs_be_files". It might be safer to make this NULL (or some&refs_be_nullthat fills the vtable, but just returns an error for each
call).
In 'refs: register ref storage backends', I do make this change. I don't do it earlier because we don't have this config stuff in place yet.
Re: [PATCH v6 28/32] config: read ref storage config on startup
Quoted 9 lines · David Turner
Quoted 5 lines
By the way, I notice that the default value for
the_refs_backendis "&refs_be_files". It might be safer to make this NULL (or some&refs_be_nullthat fills the vtable, but just returns an error for each
call).In 'refs: register ref storage backends', I do make this change. I don't do it earlier because we don't have this config stuff in place yet.
Ah, OK. I was that we did register the files backend as a normal one, but I missed the assignment to NULL (I do wonder if we want a refs_be_null to smoke out problem cases with a die("BUG") rather than segfaulting, but in theory nobody should be doing that).
-Peff
Re: [PATCH v6 28/32] config: read ref storage config on startup
In reply to Jeff KingQuoted 66 lines · Jeff King
Quoted 29 lines · David Turner
config.c +19
-0@@ -1207,6 +1208,29 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) }if (repo_config && !access_or_die (repo_config,R_OK ,0 )) { +char *storage =NULL ; + +/* +* make sure we always read the ref storage config +* from the extensions section on startup +*/ + ret +=git_config_from_file (ref_storage_backend_config, + repo_config, &storage); + +register_ref_storage_backends (); +if (!storage) + storage =xstrdup ("" ); + +if (!*storage || + !strcmp (storage,"files" )) { +/* default backend, nothing to do */ +free (storage); + }else { + if(
set_ref_storage_backend(ref_storage_backend))(quoted diff) +1
-0+ die(_("Unknown ref storage backend%s"),
config.c int git_config_early(config_fn_t fn, void *data, const char *repo_config) · line 1233
Quoted 3 lines
config.c +3
-0+ ref_storage_backend); + } +Coverity complains that "storage" leaks here, and I think it does in the
case that we non-default storage, and we successfully set up the backend. That's a pretty minor point.However, after looking at this code, I'm rather confused about a few things.
One is that we read the config and use ref_storage_backend_config[1] to
store the string value in "storage", and then we check whether that is
non-default, and if it is, I'd expect us to feed it toset_ref_storage_backend. But we don't; we feedref_storage_backendinstead!What is that value? It looks like it is the string we set in
check_repo_formatwhen we load the extensions list there. So why are we re-reading the config here at all? Couldn't we just useref_storage_backendin the first place?My second confusion is why this is happening in
git_config_early(). That
function is called during the setup ofcheck_repository_format_gently(),
which is why I think you wanted to put the code here. But it's _also_ called as part of a regulargit_config(). Which means we're parsing the
repo config and setting the ref backend all over again, every time we look at config for other reasons.
Quoted 7 lines
So I think this setup probably should be in
check_repository_format_gently(), and should be able to trigger off of
the existingref_storage_backendstring we've already saved (and we should bail immediately there if we don't know about the backend, as it
means we _don't_ match the repo's extensions and cannot proceed).
We apparently don't always call check_repo_format before calling git_config_early -- or, more to the point, before doing ref operations. So I think we need this in git_config_early.
I'll fix up the memory safety/leak issues tho.
Re: [PATCH v6 28/32] config: read ref storage config on startup
Quoted 11 lines · David Turner
Quoted 7 lines
So I think this setup probably should be in
check_repository_format_gently(), and should be able to trigger off of
the existingref_storage_backendstring we've already saved (and we should bail immediately there if we don't know about the backend, as it
means we _don't_ match the repo's extensions and cannot proceed).We apparently don't always call
check_repo_formatbefore callinggit_config_early-- or, more to the point, before doing ref operations. So I think we need this ingit_config_early.
That seems horribly broken, though. If a program is accessing refs without calling check_repository_format, isn't it bypassing all of our regular version and extension checks?
I think we should be smoking out such cases (e.g., by setting a null refs-backend, as I mentioned earlier) and fixing them, rather than working around them by putting the backend setup in the wrong place.
-Peff
Re: [PATCH v6 28/32] config: read ref storage config on startup
Quoted 4 lines · Jeff King
Quoted 3 lines
We apparently don't always call
check_repo_formatbefore callinggit_config_early-- or, more to the point, before doing ref operations. So I think we need this ingit_config_early.
Quoted 8 lines
That seems horribly broken, though. If a program is accessing refs without calling
check_repository_format, isn't it bypassing all of our regular version and extension checks?I think we should be smoking out such cases (e.g., by setting a null refs-backend, as I mentioned earlier) and fixing them, rather than working around them by putting the backend setup in the wrong place.
So even without your series, this isn't too bad to instrument, like the patch below.
It does reveal a handful of failures in the test suite. I haven't dug yet, but I strongly suspect those are all bugs that should be fixed.
cache.h +1 -0
@@ -639,6 +639,7 @@ extern int hold_locked_index(struct lock_file *, int);extern void set_alternate_index_output (const char *);/* Environment bits from configuration mechanism */ +extern int repo_initialized;extern int trust_executable_bit;extern int trust_ctime;extern int check_stat;
environment.c +1 -0
@@ -12,6 +12,7 @@#include "fmt-merge-msg.h" #include "commit.h" +int repo_initialized;int trust_executable_bit =1 ;int trust_ctime =1 ;int check_stat =1 ;
refs/files-backend.c +6 -0
@@ -947,6 +947,9 @@ static struct ref_cache *lookup_ref_cache(const char *submodule) {struct ref_cache *refs; +if (!repo_initialized) +die ("BUG: lookup_ref_cache called without initializing repo" ); +if (!submodule || !*submodule)return &ref_cache;
@@ -1414,6 +1417,9 @@ static const char *resolve_ref_1(const char *refname,int depth =MAXDEPTH ;int bad_name =0 ; +if (!repo_initialized) +die ("BUG: resolve_ref called without initializing repo" ); +if (flags) *flags =0 ;
setup.c +3 -0
@@ -446,6 +446,9 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok) ret =-1 ; } +if (ret ==0 ) + repo_initialized =1 ; +strbuf_release (&sb);return ret; }
Re: [PATCH v6 28/32] config: read ref storage config on startup
Quoted 18 lines · Jeff King
Quoted 10 lines · Jeff King
Quoted 4 lines
We apparently don't always call
check_repo_formatbefore callinggit_config_early-- or, more to the point, before doing ref operations.
So I think we need this ingit_config_early.That seems horribly broken, though. If a program is accessing refs without calling
check_repository_format, isn't it bypassing all of our
regular version and extension checks?Quoted 5 lines
I think we should be smoking out such cases (e.g., by setting a null refs-backend, as I mentioned earlier) and fixing them, rather
than working around them by putting the backend setup in the wrong place.
Quoted 6 lines
So even without your series, this isn't too bad to instrument, like the
patch below.It does reveal a handful of failures in the test suite. I haven't dug yet, but I strongly suspect those are all bugs that should be fixed.
I'll try to add a patch for these cases.
Re: [PATCH v6 32/32] tests: add ref-storage argument
In reply to David TurnerHi,
Quoted 26 lines
t/t9902-completion.sh +2
-1@@ -126,7 +126,7 @@ actual="$TRASH_DIRECTORY/actual" test_expect_success 'setup for __gitdir tests' ' mkdir -p subdir/subsubdir && - git init otherrepo + git init $ref_storage_arg otherrepo ' test_expect_success '__gitdir - from command line (through $__git_dir)' '@@ -177,6 +177,7 @@ test_expect_success '__gitdir - cwd is a .git directory' ' test_expect_success '__gitdir - parent is a .git directory' ' echo "$(pwd -P)/.git" >expected && ( + mkdir -p .git/refs/heads && cd .git/refs/heads && __gitdir >"$actual" ) &&t/t9903-bash-prompt.sh +0
-0
t/t9903-bash-prompt.sh test_expect_success 'prompt - inside .git directory' ' · line 154
Quoted 7 lines
t/t9903-bash-prompt.sh +1
-0@@ -148,6 +148,7 @@ test_expect_success 'prompt - inside .git directory' ' test_expect_success 'prompt - deep inside .git directory' ' printf " (GIT_DIR!)" >expected && ( + mkdir -p .git/refs/heads && cd .git/refs/heads && __git_ps1 >"$actual" ) &&
As far as these tests are concerned any subdirectory under .git/ would do, it doesn't have to be .git/refs/heads. How about cd-ing into a different directory instead of creating the missing ones?
---- >8 ----
Subject: [PATCH] fixup! tests: add ref-storage argument
--- t/t9902-completion.sh | 3 +-- t/t9903-bash-prompt.sh | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
t/t9902-completion.sh +1 -2
@@ -177,8 +177,7 @@ test_expect_success '__gitdir - cwd is a .git directory' ' test_expect_success '__gitdir - parent is a .git directory' ' echo "$(pwd -P)/.git" >expected && ( - mkdir -p .git/refs/heads && - cd .git/refs/heads && + cd .git/objects && __gitdir >"$actual" ) && test_cmp expected "$actual"
t/t9903-bash-prompt.sh +1 -2
@@ -148,8 +148,7 @@ test_expect_success 'prompt - inside .git directory' ' test_expect_success 'prompt - deep inside .git directory' ' printf " (GIT_DIR!)" >expected && ( - mkdir -p .git/refs/heads && - cd .git/refs/heads && + cd .git/objects && __git_ps1 >"$actual" ) && test_cmp expected "$actual"
Signature · 1 line
2.7.2.410.g92cb358
Re: [PATCH v6 32/32] tests: add ref-storage argument
Quoted 4 lines · SZEDER Gábor
As far as these tests are concerned any subdirectory under .git/ would
do, it doesn't have to be .git/refs/heads. How about cd-ing into a different directory instead of creating the missing ones?
Good idea, thanks.