Remove special casing for PSEUDOREF updates
cover Remove special casing for PSEUDOREF updates
This gets rid of the special casing code for pseudorefs in refs.c
This is in preparation for reftable.
Han-Wen Nienhuys (2):
Modify pseudo refs through ref backend storage
Make HEAD a PSEUDOREF rather than PER_WORKTREE.
refs.c | 127 ++++-------------------------------------- refs/files-backend.c | 11 ++-- t/t1400-update-ref.sh | 6 +- 3 files changed, 20 insertions(+), 124 deletions(-)
base-commit: a08a83db2bf27f015bec9a435f6d73e223c21c5e
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-673%2Fhanwen%2Fpseudoref-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-673/hanwen/pseudoref-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/673
Signature · 1 line
gitgitgadget
PATCH 1/2 Modify pseudo refs through ref backend storage
From: Han-Wen Nienhuys <[email protected]>
The previous behavior was introduced in commit 74ec19d4be ("pseudorefs: create and use pseudoref update and delete functions", Jul 31, 2015), with the justification "alternate ref backends still need to store pseudorefs in GIT_DIR".
Refs such as REBASE_HEAD are read through the ref backend. This can only work consistently if they are written through the ref backend as well. Tooling that works directly on files under .git should be updated to use git commands to read refs instead.
This needs the following fixes
* Only write log for HEAD pseudo ref. Fixes t1400 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD'
* t1400: change hard coded error messages to check for.
* don't deref non-HEAD pseudoref symrefs. This fixes t1405. Without this, a deleting a FOO symref pointing to refs/heads/master will remove master too.
--- refs.c | 120 +++--------------------------------------- refs/files-backend.c | 11 ++-- t/t1400-update-ref.sh | 6 +-- 3 files changed, 17 insertions(+), 120 deletions(-)
refs.c +7 -113
@@ -739,102 +739,6 @@ long get_files_ref_lock_timeout_ms(void)return timeout_ms; } -static int write_pseudoref (const char *pseudoref,const struct object_id *oid, -const struct object_id *old_oid,struct strbuf *err) -{ -const char *filename; -int fd; -struct lock_file lock =LOCK_INIT ; -struct strbuf buf =STRBUF_INIT ; -int ret =-1 ; - -if (!oid) -return 0 ; - -strbuf_addf (&buf,"%s\n" ,oid_to_hex (oid)); - - filename =git_path ("%s" , pseudoref); - fd =hold_lock_file_for_update_timeout (&lock, filename,0 , -get_files_ref_lock_timeout_ms ()); -if (fd <0 ) { -strbuf_addf (err,_ ("could not open '%s' for writing: %s" ), - filename,strerror (errno)); - goto done; - } - -if (old_oid) { -struct object_id actual_old_oid; - -if (read_ref (pseudoref, &actual_old_oid)) { -if (!is_null_oid (old_oid)) { -strbuf_addf (err,_ ("could not read ref '%s'" ), - pseudoref); -rollback_lock_file (&lock); - goto done; - } - }else if (is_null_oid (old_oid)) { -strbuf_addf (err,_ ("ref '%s' already exists" ), - pseudoref); -rollback_lock_file (&lock); - goto done; - }else if (!oideq (&actual_old_oid, old_oid)) { -strbuf_addf (err,_ ("unexpected object ID when writing '%s'" ), - pseudoref); -rollback_lock_file (&lock); - goto done; - } - } - -if (write_in_full (fd, buf.buf, buf.len) <0 ) { -strbuf_addf (err,_ ("could not write to '%s'" ), filename); -rollback_lock_file (&lock); - goto done; - } - -commit_lock_file (&lock); - ret =0 ; -done: -strbuf_release (&buf); -return ret; -} - -static int delete_pseudoref (const char *pseudoref,const struct object_id *old_oid) -{ -const char *filename; - - filename =git_path ("%s" , pseudoref); - -if (old_oid && !is_null_oid (old_oid)) { -struct lock_file lock =LOCK_INIT ; -int fd; -struct object_id actual_old_oid; - - fd =hold_lock_file_for_update_timeout ( - &lock, filename,0 , -get_files_ref_lock_timeout_ms ()); -if (fd <0 ) { -error_errno (_ ("could not open '%s' for writing" ), - filename); -return -1 ; - } -if (read_ref (pseudoref, &actual_old_oid)) -die (_ ("could not read ref '%s'" ), pseudoref); -if (!oideq (&actual_old_oid, old_oid)) { -error (_ ("unexpected object ID when deleting '%s'" ), - pseudoref); -rollback_lock_file (&lock); -return -1 ; - } - -unlink (filename); -rollback_lock_file (&lock); - }else { -unlink (filename); - } - -return 0 ; -} - int refs_delete_ref(struct ref_store *refs, const char *msg, const char *refname, const struct object_id *old_oid,
@@ -843,11 +747,6 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,struct ref_transaction *transaction;struct strbuf err =STRBUF_INIT ; -if (ref_type (refname) ==REF_TYPE_PSEUDOREF ) { -assert (refs ==get_main_ref_store (the_repository)); -return delete_pseudoref (refname, old_oid); - } - transaction =ref_store_transaction_begin (refs, &err);if (!transaction || ref_transaction_delete(transaction, refname, old_oid,
@@ -1170,18 +1069,13 @@ int refs_update_ref(struct ref_store *refs, const char *msg,struct strbuf err =STRBUF_INIT ;int ret =0 ; -if (ref_type (refname) ==REF_TYPE_PSEUDOREF ) { -assert (refs ==get_main_ref_store (the_repository)); - ret =write_pseudoref (refname, new_oid, old_oid, &err); - }else { - t =ref_store_transaction_begin (refs, &err); -if (!t || -ref_transaction_update (t, refname, new_oid, old_oid, - flags, msg, &err) || -ref_transaction_commit (t, &err)) { - ret =1 ; -ref_transaction_free (t); - } + t =ref_store_transaction_begin (refs, &err); +if (!t || +ref_transaction_update (t, refname, new_oid, old_oid, flags, msg, + &err) || +ref_transaction_commit (t, &err)) { + ret =1 ; +ref_transaction_free (t); }if (ret) {const char *str =_ ("update_ref failed for ref '%s': %s" );
refs/files-backend.c +7 -4
@@ -1228,7 +1228,6 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,for (i =0 ; i < refnames->nr; i++) {const char *refname = refnames->items[i].string; -if (refs_delete_ref (&refs->base, msg, refname,NULL , flags)) result |=error (_ ("could not remove reference %s" ), refname); }
@@ -2436,7 +2435,9 @@ static int lock_ref_for_update(struct files_ref_store *refs, update->backend_data = lock;if (update->type &REF_ISSYMREF ) { -if (update->flags &REF_NO_DEREF ) { +if (update->flags &REF_NO_DEREF || + (ref_type (update->refname) ==REF_TYPE_PSEUDOREF && +strcmp (update->refname,"HEAD" ))) {/* * We won't be reading the referent as part of * the transaction, so we have to read it here
@@ -2782,8 +2783,10 @@ static int files_transaction_finish(struct ref_store *ref_store,struct ref_update *update = transaction->updates[i];struct ref_lock *lock = update->backend_data; -if (update->flags &REF_NEEDS_COMMIT || - update->flags &REF_LOG_ONLY ) { +if ((ref_type (lock->ref_name) !=REF_TYPE_PSEUDOREF || + !strcmp (lock->ref_name,"HEAD" )) && + (update->flags &REF_NEEDS_COMMIT || + update->flags &REF_LOG_ONLY )) { if (files_log_ref_write(refs, lock->ref_name, &lock->old_oid,
t/t1400-update-ref.sh +3 -3
@@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && test_path_is_missing .git/PSEUDOREF && - test_i18ngrep "could not read ref" err + test_i18ngrep "unable to resolve reference" err ' test_expect_success 'create pseudoref' '
@@ -497,7 +497,7 @@ test_expect_success 'overwrite pseudoref with correct old value' ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && test $C = $(cat .git/PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref' '
@@ -509,7 +509,7 @@ test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && test $A = $(cat .git/PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref with correct old value' '
Signature · 1 line
gitgitgadget
PATCH 2/2 Make HEAD a PSEUDOREF rather than PER_WORKTREE.
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
This is consistent with the definition of REF_TYPE_PSEUDOREF (uppercase in the root ref namespace).
--- refs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
refs.c +3 -4
@@ -676,10 +676,9 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)static int is_per_worktree_ref (const char *refname) { -return !strcmp (refname,"HEAD" ) || -starts_with (refname,"refs/worktree/" ) || -starts_with (refname,"refs/bisect/" ) || -starts_with (refname,"refs/rewritten/" ); +return starts_with (refname,"refs/worktree/" ) || +starts_with (refname,"refs/bisect/" ) || +starts_with (refname,"refs/rewritten/" ); }static int is_pseudoref_syntax (const char *refname)
Signature · 1 line
gitgitgadget
Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
In reply to Han-Wen Nienhuys via GitGitGadgetQuoted 2 lines · Han-Wen Nienhuys via GitGitGadget
Subject: Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
From: Han-Wen Nienhuys <[email protected]>
With what definition of "pseudo refs" has this change been made? Those things like HEAD, CHERRY_PICK_HEAD, FETCH_HEAD etc. that have traditionally been written as a plain text file in $GIT_DIR and are used to name objects by having a full object name in it?
Or the entities that behave like refs and stored in ref backends, with all-uppercase-names but do not sit inside refs/ hierarchy?
I think it is OK (and possibly a good move in the longer term, but that is just my gut feeling) to make ref backends resopnsible for enumerating, reading and writing them (i.e. I think we want to use the latter definition for the longer term health of the project). And we would want to ...
Quoted 4 lines
The previous behavior was introduced in commit
74ec19d4be("pseudorefs: create and use pseudoref update and delete functions", Jul 31, 2015), with the justification "alternate ref backends still need to store pseudorefs inGIT_DIR".
... declare that justification invalid for that purpose.
Is that what is going on? I just want to make sure I am following your flow of thought.
Quoted 4 lines
Refs such as
REBASE_HEADare read through the ref backend. This can only work consistently if they are written through the ref backend as well. Tooling that works directly on files under .git should be updated to use git commands to read refs instead.
OK.
refs/files-backend.c static int files_delete_refs(struct ref_store *ref_store, const char *msg, · line 1233
Quoted 12 lines
refs/files-backend.c +0
-1@@ -1228,7 +1228,6 @@ static int files_delete_refs(struct ref_store *ref_store, const char *msg,for (i =0 ; i < refnames->nr; i++) {const char *refname = refnames->items[i].string; -if (refs_delete_ref (&refs->base, msg, refname,NULL , flags)) result |=error (_ ("could not remove reference %s" ), refname); }
Unreleated change?
refs/files-backend.c static int lock_ref_for_update(struct files_ref_store *refs, · line 2443
Quoted 11 lines
refs/files-backend.c +3
-1@@ -2436,7 +2435,9 @@ static int lock_ref_for_update(struct files_ref_store *refs, update->backend_data = lock;if (update->type &REF_ISSYMREF ) { -if (update->flags &REF_NO_DEREF ) { +if (update->flags &REF_NO_DEREF || + (ref_type (update->refname) ==REF_TYPE_PSEUDOREF && +strcmp (update->refname,"HEAD" ))) {/* * We won't be reading the referent as part of * the transaction, so we have to read it here
The old "if we are not dereferencing" condition in if() exactly matched the comment, but the condition in if() after this change is not "if we are not dereferencing". Even if we are dereferencing, under some new condition, we would still drop into this block and do not follow the "else" side that creates a new update for the referent. Is this part of "modify pseudo refs via backend" topic, or should it be a separate modification? Why is this change needed?
It seems that no matter where in the refs/ hierarchy (or even outside) a symbolic ref resides, the way to update itself (not the referent through the symbolic ref) should be the same, which is what the original says, and we want to change that reasoning here, but it is not quite clear to me why.
refs/files-backend.c static int files_transaction_finish(struct ref_store *ref_store, · line 2789
Quoted 10 lines
refs/files-backend.c +4
-2@@ -2782,8 +2783,10 @@ static int files_transaction_finish(struct ref_store *ref_store,struct ref_update *update = transaction->updates[i];struct ref_lock *lock = update->backend_data; -if (update->flags &REF_NEEDS_COMMIT || - update->flags &REF_LOG_ONLY ) { +if ((ref_type (lock->ref_name) !=REF_TYPE_PSEUDOREF || + !strcmp (lock->ref_name,"HEAD" )) && + (update->flags &REF_NEEDS_COMMIT || + update->flags &REF_LOG_ONLY )) {
And this one stops the files backend from touching all pseudorefs other than HEAD with this codepath. That somehow feels totally opposite from what the log message explained above---weren't we updating the code to write these pseudorefs through the individual backends, which the files backend is one example of? Isn't this change stopping the backend from writing the pseudorefs other than HEAD instead?
Puzzled.
t/t1400-update-ref.sh test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER · line 478
Quoted 13 lines
refs/files-backend.c +0
-0if (files_log_ref_write(refs, lock->ref_name, &lock->old_oid,t/t1400-update-ref.sh +0
-0@@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && test_path_is_missing .git/PSEUDOREF &&
The reason why I asked what this patch thinks the definition of pseudoref is is because of this thing. Shouldn't this line be fixed not to depend on the files backend? Likewise for $(cat .git/PSEUDOREF) in the remaining two hunks.
Quoted 23 lines
t/t1400-update-ref.sh +3
-3- test_i18ngrep "could not read ref" err + test_i18ngrep "unable to resolve reference" err ' test_expect_success 'create pseudoref' '@@ -497,7 +497,7 @@ test_expect_success 'overwrite pseudoref with correct old value' ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && test $C = $(cat .git/PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref' '@@ -509,7 +509,7 @@ test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && test $A = $(cat .git/PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref with correct old value' '
Re: [PATCH 2/2] Make HEAD a PSEUDOREF rather than PER_WORKTREE.
In reply to Han-Wen Nienhuys via GitGitGadgetQuoted 4 lines · Han-Wen Nienhuys via GitGitGadget
From: Han-Wen Nienhuys <[email protected]>
This is consistent with the definition of
REF_TYPE_PSEUDOREF(uppercase in the root ref namespace).
I wonder if some special casing we saw for "HEAD" in 1/2 (e.g. we no longer do this to pseudorefs in this codepath but HEAD is different and will continue to be dealt with in the codepath) needs adjustment after this change? HEAD still needs to be able to have a different value (either detached or pointing to another ref) per worktree, but it is unclear where that knowledge now resides in the new code. Are we declaring that all pseudorefs are per worktree (which I think is not wrong)?
Quoted 23 lines
Signed-off-by Han-Wen Nienhuys <[email protected]>--- refs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)refs.c +3
-4@@ -676,10 +676,9 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)static int is_per_worktree_ref (const char *refname) { -return !strcmp (refname,"HEAD" ) || -starts_with (refname,"refs/worktree/" ) || -starts_with (refname,"refs/bisect/" ) || -starts_with (refname,"refs/rewritten/" ); +return starts_with (refname,"refs/worktree/" ) || +starts_with (refname,"refs/bisect/" ) || +starts_with (refname,"refs/rewritten/" ); }static int is_pseudoref_syntax (const char *refname)
Re: [PATCH 2/2] Make HEAD a PSEUDOREF rather than PER_WORKTREE.
Quoted 11 lines · Junio C Hamano
Quoted 2 lines
This is consistent with the definition of
REF_TYPE_PSEUDOREF(uppercase in the root ref namespace).I wonder if some special casing we saw for "HEAD" in 1/2 (e.g. we no longer do this to pseudorefs in this codepath but HEAD is different and will continue to be dealt with in the codepath) needs adjustment after this change? HEAD still needs to be able to have a different value (either detached or pointing to another ref) per worktree, but it is unclear where that knowledge now resides in the new code. Are we declaring that all pseudorefs are per worktree (which I think is not wrong)?
the source code already says
enum ref_type {
REF_TYPE_PER_WORKTREE, /* refs inside refs/ but not shared */ REF_TYPE_PSEUDOREF, /* refs outside refs/ in current worktree */
but considers HEAD a REF_TYPE_PER_WORKTREE, counter to the comment.
IIRC, this change actually has almost no effect, because most code treats both enum values as equivalent. (see eg. builtin/reflog.c), except for the code that the preceding commit changes.
Signature · 7 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
In reply to Junio C HamanoQuoted 6 lines · Junio C Hamano
Quoted 2 lines · Han-Wen Nienhuys via GitGitGadget
Subject: Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
From: Han-Wen Nienhuys <[email protected]>
Quoted 7 lines
With what definition of "pseudo refs" has this change been made? Those things like HEAD,
CHERRY_PICK_HEAD,FETCH_HEADetc. that have traditionally been written as a plain text file in $GIT_DIR and are used to name objects by having a full object name in it?Or the entities that behave like refs and stored in ref backends, with all-uppercase-names but do not sit inside refs/ hierarchy?
I thought these were the same? - see below :)
Quoted 11 lines
I think it is OK (and possibly a good move in the longer term, but that is just my gut feeling) to make ref backends resopnsible for enumerating, reading and writing them (i.e. I think we want to use the latter definition for the longer term health of the project). And we would want to ...
Quoted 4 lines
The previous behavior was introduced in commit
74ec19d4be("pseudorefs: create and use pseudoref update and delete functions", Jul 31, 2015), with the justification "alternate ref backends still need to store pseudorefs inGIT_DIR".
Quoted 4 lines
... declare that justification invalid for that purpose.
Is that what is going on? I just want to make sure I am following your flow of thought.
yep.
Quoted 7 lines
Quoted 5 lines
const char *refname = refnames->items[i].string; - if (refs_delete_ref(&refs->base, msg, refname, NULL, flags)) result |= error(_("could not remove reference %s"), refname); }Unreleated change?
oops.
Quoted 19 lines
refs/files-backend.c static int lock_ref_for_update(struct files_ref_store *refs, · line 2443
Quoted 11 lines
refs/files-backend.c +3
-1@@ -2436,7 +2435,9 @@ static int lock_ref_for_update(struct files_ref_store *refs, update->backend_data = lock;if (update->type &REF_ISSYMREF ) { -if (update->flags &REF_NO_DEREF ) { +if (update->flags &REF_NO_DEREF || + (ref_type (update->refname) ==REF_TYPE_PSEUDOREF && +strcmp (update->refname,"HEAD" ))) {/* * We won't be reading the referent as part of * the transaction, so we have to read it here The old "if we are not dereferencing" condition in
if()exactly matched the comment, but the condition inif()after this change is not "if we are not dereferencing". Even if we are dereferencing, under some new condition, we would still drop into this block and do not follow the "else" side that creates a new update for the referent. Is this part of "modify pseudo refs via backend" topic, or should it be a separate modification? Why is this change needed?
There is a test (mentioned in the commit message), t1405, which does
$RUN create-symref FOO refs/heads/master nothing &&
# calls refs_create_symref() .. $RUN delete-refs 0 nothing FOO refs/tags/new-tag && # calls refs_delete_refs, which calls delete_pseudoref .. git rev-parse master >expected &&
Previously, the delete_pseudoref code would delete just .git/FOO file. Without the change here, going through the ref backend ends up in the !REF_NO_DEREF case, deleting the master branch.
I don't know what the correct semantics are (are symrefs used for anything except HEAD ?), so
Quoted 10 lines
It seems that no matter where in the refs/ hierarchy (or even outside) a symbolic ref resides, the way to update itself (not the referent through the symbolic ref) should be the same, which is what the original says, and we want to change that reasoning here, but it is not quite clear to me why.
Quoted 4 lines
refs/files-backend.c +0
-0@@ -2782,8 +2783,10 @@ static int files_transaction_finish(struct ref_store *ref_store,struct ref_update *update = transaction->updates[i];struct ref_lock *lock = update->backend_data;
Quoted 14 lines
refs/files-backend.c static int files_transaction_finish(struct ref_store *ref_store, · line 2789
Quoted 6 lines
refs/files-backend.c +4
-2-if (update->flags &REF_NEEDS_COMMIT || - update->flags &REF_LOG_ONLY ) { +if ((ref_type (lock->ref_name) !=REF_TYPE_PSEUDOREF || + !strcmp (lock->ref_name,"HEAD" )) && + (update->flags &REF_NEEDS_COMMIT || + update->flags &REF_LOG_ONLY )) {And this one stops the files backend from touching all pseudorefs other than HEAD with this codepath. That somehow feels totally opposite from what the log message explained above---weren't we updating the code to write these pseudorefs through the individual backends, which the files backend is one example of? Isn't this change stopping the backend from writing the pseudorefs other than HEAD instead?
There is a test
'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD'
that wants there to not be reflog updates for ORIG_HEAD. I don't see why that behavior exists, and would be happy to change it, but I'm too much of a newbie to decide what is right here.
Quoted 11 lines
t/t1400-update-ref.sh test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER · line 478
Quoted 6 lines
t/t1400-update-ref.sh +0
-0@@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && test_path_is_missing .git/PSEUDOREF &&The reason why I asked what this patch thinks the definition of pseudoref is is because of this thing. Shouldn't this line be fixed not to depend on the files backend? Likewise for $(cat .git/PSEUDOREF) in the remaining two hunks.
This patch doesn't introduce reftable yet, so both definitions are equivalent for the sake of this patch.
Signature · 8 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
Quoted 17 lines · Han-Wen Nienhuys
Quoted 2 lines
Or the entities that behave like refs and stored in ref backends, with all-uppercase-names but do not sit inside refs/ hierarchy?
I thought these were the same? - see below :)
Quoted 11 lines
t/t1400-update-ref.sh test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER · line 478
Quoted 6 lines
t/t1400-update-ref.sh +0
-0@@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && test_path_is_missing .git/PSEUDOREF &&The reason why I asked what this patch thinks the definition of pseudoref is is because of this thing. Shouldn't this line be fixed not to depend on the files backend? Likewise for $(cat .git/PSEUDOREF) in the remaining two hunks.
Quoted 2 lines
This patch doesn't introduce reftable yet, so both definitions are equivalent for the sake of this patch.
But at the end of the tunnel, we do want to see people stop expecting that .git/PSEUDOREF file is what PSEUDOREF ref is, no? I think that is what "pseudo refs are not just files directly under $GIT_DIR, but managed by the backend" means, and that in turn is a valid justification for other changes introduced in this patch. Expecting the effect of modifying pseudo refs _after_ the code is changed that such modifications are properly done through the ref API to appear on the filesystem feels like it goes against the reason why we are making this change, compared to checking to see if the pseudoref really got updated as desired via the ref API, at least to me.
Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
Quoted 8 lines · Junio C Hamano
Quoted 7 lines
Quoted 4 lines
The reason why I asked what this patch thinks the definition of pseudoref is is because of this thing. Shouldn't this line be fixed not to depend on the files backend? Likewise for $(cat .git/PSEUDOREF) in the remaining two hunks.
This patch doesn't introduce reftable yet, so both definitions are equivalent for the sake of this patch.
Quoted 11 lines
But at the end of the tunnel, we do want to see people stop expecting that .git/PSEUDOREF file is what PSEUDOREF ref is, no? I think that is what "pseudo refs are not just files directly under $GIT_DIR, but managed by the backend" means, and that in turn is a valid justification for other changes introduced in this patch. Expecting the effect of modifying pseudo refs _after_ the code is changed that such modifications are properly done through the ref API to appear on the filesystem feels like it goes against the reason why we are making this change, compared to checking to see if the pseudoref really got updated as desired via the ref API, at least to me.
I can fix this specific instance here (which is what I think you want), for this commit to practice what it preaches. At the same time there are probably about 100 or so other places where the tests check the file system directly for ref(log) existence, so it would never be totally consistent.
The only way to systematically find the offending places is to introduce a new ref backend and then fix all the tests, and I think that goes outside the scope of this small series.
--
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays. --
Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH 1/2] Modify pseudo refs through ref backend storage
Quoted 9 lines · Han-Wen Nienhuys
I can fix this specific instance here (which is what I think you want), for this commit to practice what it preaches. At the same time there are probably about 100 or so other places where the tests check the file system directly for ref(log) existence, so it would never be totally consistent.
The only way to systematically find the offending places is to introduce a new ref backend and then fix all the tests, and I think that goes outside the scope of this small series.
Good. I think we are on the same page. I suggested to make the patch internally consistent, nothing more. And fixing everything in the world is outside the scope of these two patches.
Thanks.
v2 cover Remove special casing for PSEUDOREF updates
In reply to Han-Wen Nienhuys via GitGitGadgetThis gets rid of the special casing code for pseudorefs in refs.c
This is in preparation for reftable.
v2
* remove special casing of non-HEAD pseudorefs; update t1400 and t1405 accordingly
* open question: should git-update-ref.txt be updated, when it talks about logAllRefUpdates?
Han-Wen Nienhuys (3):
t1400: use git rev-parse for testing PSEUDOREF existence Modify pseudo refs through ref backend storage Make HEAD a PSEUDOREF rather than PER_WORKTREE.
refs.c | 127 +++----------------------------------- t/t1400-update-ref.sh | 30 ++++----- t/t1405-main-ref-store.sh | 5 +- 3 files changed, 29 insertions(+), 133 deletions(-)
base-commit: 4a0fcf9f760c9774be77f51e1e88a7499b53d2e2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-673%2Fhanwen%2Fpseudoref-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-673/hanwen/pseudoref-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/673
Range-diff vs v1:
-: ---------- > 1: 9c3dc4b2cb t1400: use git rev-parse for testing PSEUDOREF existence 1: 6821f57bdf ! 2: 871b411517 Modify pseudo refs through ref backend storage
@@ Commit message
well. Tooling that works directly on files under .git should be updated to use git commands to read refs instead.
- This needs the following fixes
+ The following behaviors change:
- * Only write log for HEAD pseudo ref. Fixes t1400
- 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD'
+ * Updates to pseudorefs (eg. ORIG_HEAD) with
+ core.logAllRefUpdates=always will create reflogs for the pseudoref.
- * t1400: change hard coded error messages to check for.
-
- * don't deref non-HEAD pseudoref symrefs. This fixes t1405. Without
- this, a deleting a FOO symref pointing to refs/heads/master will remove
- master too.
+ * non-HEAD pseudoref symrefs are also dereferenced on deletion. Update
+ t1405 accordingly.
@@ refs.c: int refs_update_ref(struct ref_store *refs, const char *msg,
if (ret) {
const char *str = _("update_ref failed for ref '%s': %s");
- ## refs/files-backend.c ##
-@@ refs/files-backend.c: static int files_delete_refs(struct ref_store *ref_store, const char *msg, -
- for (i = 0; i < refnames->nr; i++) {
- const char *refname = refnames->items[i].string;
--
- if (refs_delete_ref(&refs->base, msg, refname, NULL, flags))
- result |= error(_("could not remove reference %s"), refname);
- }
-@@ refs/files-backend.c: static int lock_ref_for_update(struct files_ref_store *refs,
- update->backend_data = lock;
+ ## t/t1400-update-ref.sh ##
+@@ t/t1400-update-ref.sh: test_expect_success 'core.logAllRefUpdates=always creates reflog by default' '
+ git reflog exists $outside
+ '
- if (update->type & REF_ISSYMREF) {
-- if (update->flags & REF_NO_DEREF) {
-+ if (update->flags & REF_NO_DEREF ||
-+ (ref_type(update->refname) == REF_TYPE_PSEUDOREF &&
-+ strcmp(update->refname, "HEAD"))) {
- /*
- * We won't be reading the referent as part of
- * the transaction, so we have to read it here
-@@ refs/files-backend.c: static int files_transaction_finish(struct ref_store *ref_store,
- struct ref_update *update = transaction->updates[i];
- struct ref_lock *lock = update->backend_data;
+-test_expect_success 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD' ' ++test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' '
+ test_config core.logAllRefUpdates always &&
+ git update-ref ORIG_HEAD $A &&
+- test_must_fail git reflog exists ORIG_HEAD
++ git reflog exists ORIG_HEAD
+ '
-- if (update->flags & REF_NEEDS_COMMIT ||
-- update->flags & REF_LOG_ONLY) {
-+ if ((ref_type(lock->ref_name) != REF_TYPE_PSEUDOREF ||
-+ !strcmp(lock->ref_name, "HEAD")) &&
-+ (update->flags & REF_NEEDS_COMMIT ||
-+ update->flags & REF_LOG_ONLY)) {
- if (files_log_ref_write(refs,
- lock->ref_name,
- &lock->old_oid,
-
- ## t/t1400-update-ref.sh ##
+ test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
@@ t/t1400-update-ref.sh: test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER
test_expect_success 'given old value for missing pseudoref, do not create' '
test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
- test_path_is_missing .git/PSEUDOREF &&
+ test_must_fail git rev-parse PSEUDOREF &&
- test_i18ngrep "could not read ref" err
+ test_i18ngrep "unable to resolve reference" err
'
@@ t/t1400-update-ref.sh: test_expect_success 'git cat-file blob master@{2005-05-26
@@ t/t1400-update-ref.sh: test_expect_success 'overwrite pseudoref with correct old value' '
test_expect_success 'do not overwrite pseudoref with wrong old value' '
test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
- test $C = $(cat .git/PSEUDOREF) &&
+ test $C = $(git rev-parse PSEUDOREF) &&
- test_i18ngrep "unexpected object ID" err
+ test_i18ngrep "cannot lock ref.*expected" err
'
@@ t/t1400-update-ref.sh: test_expect_success 'overwrite pseudoref with correct old
@@ t/t1400-update-ref.sh: test_expect_success 'do not delete pseudoref with wrong old value' '
git update-ref PSEUDOREF $A &&
test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
- test $A = $(cat .git/PSEUDOREF) &&
+ test $A = $(git rev-parse PSEUDOREF) &&
- test_i18ngrep "unexpected object ID" err
+ test_i18ngrep "cannot lock ref.*expected" err
'
test_expect_success 'delete pseudoref with correct old value' '
+
+ ## t/t1405-main-ref-store.sh ##
+@@ t/t1405-main-ref-store.sh: test_expect_success 'create_symref(FOO, refs/heads/master)' '
+ test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
+ git rev-parse FOO -- &&
+ git rev-parse refs/tags/new-tag -- &&
++ m=$(git rev-parse master) &&
+ $RUN delete-refs 0 nothing FOO refs/tags/new-tag &&
+ test_must_fail git rev-parse FOO -- &&
+- test_must_fail git rev-parse refs/tags/new-tag --
++ test_must_fail git rev-parse refs/tags/new-tag --&&
++ test_must_fail git rev-parse master -- &&
++ git update-ref refs/heads/master $m
+ '
+
+ test_expect_success 'rename_refs(master, new-master)' '
2: 470821dc6d = 3: 1c2b9d5f17 Make HEAD a PSEUDOREF rather than PER_WORKTREE.
Signature · 1 line
gitgitgadget
PATCH v2 2/3 Modify pseudo refs through ref backend storage
From: Han-Wen Nienhuys <[email protected]>
The previous behavior was introduced in commit 74ec19d4be ("pseudorefs: create and use pseudoref update and delete functions", Jul 31, 2015), with the justification "alternate ref backends still need to store pseudorefs in GIT_DIR".
Refs such as REBASE_HEAD are read through the ref backend. This can only work consistently if they are written through the ref backend as well. Tooling that works directly on files under .git should be updated to use git commands to read refs instead.
The following behaviors change:
* Updates to pseudorefs (eg. ORIG_HEAD) with core.logAllRefUpdates=always will create reflogs for the pseudoref.
* non-HEAD pseudoref symrefs are also dereferenced on deletion. Update t1405 accordingly.
--- refs.c | 120 +++----------------------------------- t/t1400-update-ref.sh | 10 ++-- t/t1405-main-ref-store.sh | 5 +- 3 files changed, 16 insertions(+), 119 deletions(-)
refs.c +7 -113
@@ -771,102 +771,6 @@ long get_files_ref_lock_timeout_ms(void)return timeout_ms; } -static int write_pseudoref (const char *pseudoref,const struct object_id *oid, -const struct object_id *old_oid,struct strbuf *err) -{ -const char *filename; -int fd; -struct lock_file lock =LOCK_INIT ; -struct strbuf buf =STRBUF_INIT ; -int ret =-1 ; - -if (!oid) -return 0 ; - -strbuf_addf (&buf,"%s\n" ,oid_to_hex (oid)); - - filename =git_path ("%s" , pseudoref); - fd =hold_lock_file_for_update_timeout (&lock, filename,0 , -get_files_ref_lock_timeout_ms ()); -if (fd <0 ) { -strbuf_addf (err,_ ("could not open '%s' for writing: %s" ), - filename,strerror (errno)); - goto done; - } - -if (old_oid) { -struct object_id actual_old_oid; - -if (read_ref (pseudoref, &actual_old_oid)) { -if (!is_null_oid (old_oid)) { -strbuf_addf (err,_ ("could not read ref '%s'" ), - pseudoref); -rollback_lock_file (&lock); - goto done; - } - }else if (is_null_oid (old_oid)) { -strbuf_addf (err,_ ("ref '%s' already exists" ), - pseudoref); -rollback_lock_file (&lock); - goto done; - }else if (!oideq (&actual_old_oid, old_oid)) { -strbuf_addf (err,_ ("unexpected object ID when writing '%s'" ), - pseudoref); -rollback_lock_file (&lock); - goto done; - } - } - -if (write_in_full (fd, buf.buf, buf.len) <0 ) { -strbuf_addf (err,_ ("could not write to '%s'" ), filename); -rollback_lock_file (&lock); - goto done; - } - -commit_lock_file (&lock); - ret =0 ; -done: -strbuf_release (&buf); -return ret; -} - -static int delete_pseudoref (const char *pseudoref,const struct object_id *old_oid) -{ -const char *filename; - - filename =git_path ("%s" , pseudoref); - -if (old_oid && !is_null_oid (old_oid)) { -struct lock_file lock =LOCK_INIT ; -int fd; -struct object_id actual_old_oid; - - fd =hold_lock_file_for_update_timeout ( - &lock, filename,0 , -get_files_ref_lock_timeout_ms ()); -if (fd <0 ) { -error_errno (_ ("could not open '%s' for writing" ), - filename); -return -1 ; - } -if (read_ref (pseudoref, &actual_old_oid)) -die (_ ("could not read ref '%s'" ), pseudoref); -if (!oideq (&actual_old_oid, old_oid)) { -error (_ ("unexpected object ID when deleting '%s'" ), - pseudoref); -rollback_lock_file (&lock); -return -1 ; - } - -unlink (filename); -rollback_lock_file (&lock); - }else { -unlink (filename); - } - -return 0 ; -} - int refs_delete_ref(struct ref_store *refs, const char *msg, const char *refname, const struct object_id *old_oid,
@@ -875,11 +779,6 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,struct ref_transaction *transaction;struct strbuf err =STRBUF_INIT ; -if (ref_type (refname) ==REF_TYPE_PSEUDOREF ) { -assert (refs ==get_main_ref_store (the_repository)); -return delete_pseudoref (refname, old_oid); - } - transaction =ref_store_transaction_begin (refs, &err);if (!transaction || ref_transaction_delete(transaction, refname, old_oid,
@@ -1202,18 +1101,13 @@ int refs_update_ref(struct ref_store *refs, const char *msg,struct strbuf err =STRBUF_INIT ;int ret =0 ; -if (ref_type (refname) ==REF_TYPE_PSEUDOREF ) { -assert (refs ==get_main_ref_store (the_repository)); - ret =write_pseudoref (refname, new_oid, old_oid, &err); - }else { - t =ref_store_transaction_begin (refs, &err); -if (!t || -ref_transaction_update (t, refname, new_oid, old_oid, - flags, msg, &err) || -ref_transaction_commit (t, &err)) { - ret =1 ; -ref_transaction_free (t); - } + t =ref_store_transaction_begin (refs, &err); +if (!t || +ref_transaction_update (t, refname, new_oid, old_oid, flags, msg, + &err) || +ref_transaction_commit (t, &err)) { + ret =1 ; +ref_transaction_free (t); }if (ret) {const char *str =_ ("update_ref failed for ref '%s': %s" );
t/t1400-update-ref.sh +5 -5
@@ -160,10 +160,10 @@ test_expect_success 'core.logAllRefUpdates=always creates reflog by default' ' git reflog exists $outside ' -test_expect_success 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD' ' +test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' ' test_config core.logAllRefUpdates always && git update-ref ORIG_HEAD $A && - test_must_fail git reflog exists ORIG_HEAD + git reflog exists ORIG_HEAD ' test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
@@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && test_must_fail git rev-parse PSEUDOREF && - test_i18ngrep "could not read ref" err + test_i18ngrep "unable to resolve reference" err ' test_expect_success 'create pseudoref' '
@@ -497,7 +497,7 @@ test_expect_success 'overwrite pseudoref with correct old value' ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && test $C = $(git rev-parse PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref' '
@@ -509,7 +509,7 @@ test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && test $A = $(git rev-parse PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref with correct old value' '
t/t1405-main-ref-store.sh +4 -1
@@ -31,9 +31,12 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' ' test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' ' git rev-parse FOO -- && git rev-parse refs/tags/new-tag -- && + m=$(git rev-parse master) && $RUN delete-refs 0 nothing FOO refs/tags/new-tag && test_must_fail git rev-parse FOO -- && - test_must_fail git rev-parse refs/tags/new-tag -- + test_must_fail git rev-parse refs/tags/new-tag --&& + test_must_fail git rev-parse master -- && + git update-ref refs/heads/master $m ' test_expect_success 'rename_refs(master, new-master)' '
Signature · 1 line
gitgitgadget
PATCH v2 3/3 Make HEAD a PSEUDOREF rather than PER_WORKTREE.
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
This is consistent with the definition of REF_TYPE_PSEUDOREF (uppercase in the root ref namespace).
--- refs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
refs.c +3 -4
@@ -708,10 +708,9 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)static int is_per_worktree_ref (const char *refname) { -return !strcmp (refname,"HEAD" ) || -starts_with (refname,"refs/worktree/" ) || -starts_with (refname,"refs/bisect/" ) || -starts_with (refname,"refs/rewritten/" ); +return starts_with (refname,"refs/worktree/" ) || +starts_with (refname,"refs/bisect/" ) || +starts_with (refname,"refs/rewritten/" ); }static int is_pseudoref_syntax (const char *refname)
Signature · 1 line
gitgitgadget
PATCH v2 1/3 t1400: use git rev-parse for testing PSEUDOREF existence
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
This will allow these tests to run with alternative ref backends
--- t/t1400-update-ref.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
t/t1400-update-ref.sh +10 -10
@@ -475,57 +475,57 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && - test_path_is_missing .git/PSEUDOREF && + test_must_fail git rev-parse PSEUDOREF && test_i18ngrep "could not read ref" err ' test_expect_success 'create pseudoref' ' git update-ref PSEUDOREF $A && - test $A = $(cat .git/PSEUDOREF) + test $A = $(git rev-parse PSEUDOREF) ' test_expect_success 'overwrite pseudoref with no old value given' ' git update-ref PSEUDOREF $B && - test $B = $(cat .git/PSEUDOREF) + test $B = $(git rev-parse PSEUDOREF) ' test_expect_success 'overwrite pseudoref with correct old value' ' git update-ref PSEUDOREF $C $B && - test $C = $(cat .git/PSEUDOREF) + test $C = $(git rev-parse PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && - test $C = $(cat .git/PSEUDOREF) && + test $C = $(git rev-parse PSEUDOREF) && test_i18ngrep "unexpected object ID" err ' test_expect_success 'delete pseudoref' ' git update-ref -d PSEUDOREF && - test_path_is_missing .git/PSEUDOREF + test_must_fail git rev-parse PSEUDOREF ' test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && - test $A = $(cat .git/PSEUDOREF) && + test $A = $(git rev-parse PSEUDOREF) && test_i18ngrep "unexpected object ID" err ' test_expect_success 'delete pseudoref with correct old value' ' git update-ref -d PSEUDOREF $A && - test_path_is_missing .git/PSEUDOREF + test_must_fail git rev-parse PSEUDOREF ' test_expect_success 'create pseudoref with old OID zero' ' git update-ref PSEUDOREF $A $Z && - test $A = $(cat .git/PSEUDOREF) + test $A = $(git rev-parse PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with old OID zero' ' test_when_finished git update-ref -d PSEUDOREF && test_must_fail git update-ref PSEUDOREF $B $Z 2>err && - test $A = $(cat .git/PSEUDOREF) && + test $A = $(git rev-parse PSEUDOREF) && test_i18ngrep "already exists" err '
Signature · 1 line
gitgitgadget
Quoted 10 lines · Han-Wen Nienhuys via GitGitGadget
This gets rid of the special casing code for pseudorefs in
refs.cThis is in preparation for reftable.
v2
* remove special casing of non-HEAD pseudorefs; update t1400 and t1405 accordingly
* open question: should git-update-ref.txt be updated, when it talks about logAllRefUpdates?
This does make writing ORIG_HEAD and friends a lot more heavyweight that just "write a 40-byte text file on the filesystem to remember it for a short while", and it becomes even so with the whole reflog thing, but I think it is a good longer term direction to go.
Others may disagree, though.
In any case, if we are changing the behaviour with these patches, we should update the documentation.
Thanks.
v3 cover Remove special casing for PSEUDOREF updates
In reply to Han-Wen Nienhuys via GitGitGadgetThis gets rid of the special casing code for pseudorefs in refs.c
This is in preparation for reftable.
v3
* tweak git-update-ref.txt description for logAllRefUpdates
Han-Wen Nienhuys (3):
t1400: use git rev-parse for testing PSEUDOREF existence Modify pseudo refs through ref backend storage Make HEAD a PSEUDOREF rather than PER_WORKTREE.
Documentation/git-update-ref.txt | 13 ++-- refs.c | 127 +++---------------------------- t/t1400-update-ref.sh | 30 ++++---- t/t1405-main-ref-store.sh | 5 +- 4 files changed, 36 insertions(+), 139 deletions(-)
base-commit: b6a658bd00c9c29e07f833cabfc0ef12224e277a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-673%2Fhanwen%2Fpseudoref-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-673/hanwen/pseudoref-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/673
Range-diff vs v2:
1: 9c3dc4b2cb = 1: 28bd3534d0 t1400: use git rev-parse for testing PSEUDOREF existence 2: 871b411517 ! 2: 79cd5dd480 Modify pseudo refs through ref backend storage
@@ Commit message
+ ## Documentation/git-update-ref.txt ##
+@@ Documentation/git-update-ref.txt: still see a subset of the modifications. +
+ LOGGING UPDATES
+ ---------------
+-If config parameter "core.logAllRefUpdates" is true and the ref is one under +-"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; or +-the file "$GIT_DIR/logs/<ref>" exists then git update-ref will append +-a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all +-symbolic refs before creating the log name) describing the change +-in ref value. Log lines are formatted as:
++If config parameter "core.logAllRefUpdates" is true and the ref is one ++under "refs/heads/", "refs/remotes/", "refs/notes/", or a pseudoref ++like HEAD or ORIG_HEAD; or the file "$GIT_DIR/logs/<ref>" exists then ++git update-ref will append a line to the log file ++"$GIT_DIR/logs/<ref>" (dereferencing all symbolic refs before creating ++the log name) describing the change in ref value. Log lines are ++formatted as:
+
+ oldsha1 SP newsha1 SP committer LF
+
+
## refs.c ##
@@ refs.c: long get_files_ref_lock_timeout_ms(void)
return timeout_ms;
3: 1c2b9d5f17 = 3: 3ab9f2f04e Make HEAD a PSEUDOREF rather than PER_WORKTREE.
Signature · 1 line
gitgitgadget
PATCH v3 1/3 t1400: use git rev-parse for testing PSEUDOREF existence
From: Han-Wen Nienhuys <[email protected]>
This will allow these tests to run with alternative ref backends
--- t/t1400-update-ref.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
t/t1400-update-ref.sh +10 -10
@@ -475,57 +475,57 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && - test_path_is_missing .git/PSEUDOREF && + test_must_fail git rev-parse PSEUDOREF && test_i18ngrep "could not read ref" err ' test_expect_success 'create pseudoref' ' git update-ref PSEUDOREF $A && - test $A = $(cat .git/PSEUDOREF) + test $A = $(git rev-parse PSEUDOREF) ' test_expect_success 'overwrite pseudoref with no old value given' ' git update-ref PSEUDOREF $B && - test $B = $(cat .git/PSEUDOREF) + test $B = $(git rev-parse PSEUDOREF) ' test_expect_success 'overwrite pseudoref with correct old value' ' git update-ref PSEUDOREF $C $B && - test $C = $(cat .git/PSEUDOREF) + test $C = $(git rev-parse PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && - test $C = $(cat .git/PSEUDOREF) && + test $C = $(git rev-parse PSEUDOREF) && test_i18ngrep "unexpected object ID" err ' test_expect_success 'delete pseudoref' ' git update-ref -d PSEUDOREF && - test_path_is_missing .git/PSEUDOREF + test_must_fail git rev-parse PSEUDOREF ' test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && - test $A = $(cat .git/PSEUDOREF) && + test $A = $(git rev-parse PSEUDOREF) && test_i18ngrep "unexpected object ID" err ' test_expect_success 'delete pseudoref with correct old value' ' git update-ref -d PSEUDOREF $A && - test_path_is_missing .git/PSEUDOREF + test_must_fail git rev-parse PSEUDOREF ' test_expect_success 'create pseudoref with old OID zero' ' git update-ref PSEUDOREF $A $Z && - test $A = $(cat .git/PSEUDOREF) + test $A = $(git rev-parse PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with old OID zero' ' test_when_finished git update-ref -d PSEUDOREF && test_must_fail git update-ref PSEUDOREF $B $Z 2>err && - test $A = $(cat .git/PSEUDOREF) && + test $A = $(git rev-parse PSEUDOREF) && test_i18ngrep "already exists" err '
Signature · 1 line
gitgitgadget
PATCH v3 2/3 Modify pseudo refs through ref backend storage
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
The previous behavior was introduced in commit 74ec19d4be ("pseudorefs: create and use pseudoref update and delete functions", Jul 31, 2015), with the justification "alternate ref backends still need to store pseudorefs in GIT_DIR".
Refs such as REBASE_HEAD are read through the ref backend. This can only work consistently if they are written through the ref backend as well. Tooling that works directly on files under .git should be updated to use git commands to read refs instead.
The following behaviors change:
* Updates to pseudorefs (eg. ORIG_HEAD) with core.logAllRefUpdates=always will create reflogs for the pseudoref.
* non-HEAD pseudoref symrefs are also dereferenced on deletion. Update t1405 accordingly.
--- Documentation/git-update-ref.txt | 13 ++-- refs.c | 120 ++----------------------------- t/t1400-update-ref.sh | 10 +-- t/t1405-main-ref-store.sh | 5 +- 4 files changed, 23 insertions(+), 125 deletions(-)
Documentation/git-update-ref.txt +7 -6
@@ -148,12 +148,13 @@ still see a subset of the modifications. LOGGING UPDATES --------------- -If config parameter "core.logAllRefUpdates" is true and the ref is one under -"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; or -the file "$GIT_DIR/logs/<ref>" exists then `git update-ref` will append -a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all -symbolic refs before creating the log name) describing the change -in ref value. Log lines are formatted as: +If config parameter "core.logAllRefUpdates" is true and the ref is one +under "refs/heads/", "refs/remotes/", "refs/notes/", or a pseudoref +like HEAD or ORIG_HEAD; or the file "$GIT_DIR/logs/<ref>" exists then +`git update-ref` will append a line to the log file +"$GIT_DIR/logs/<ref>" (dereferencing all symbolic refs before creating +the log name) describing the change in ref value. Log lines are +formatted as: oldsha1 SP newsha1 SP committer LF
refs.c +7 -113
138 lines not on this page · raw message
t/t1400-update-ref.sh +5 -5
@@ -160,10 +160,10 @@ test_expect_success 'core.logAllRefUpdates=always creates reflog by default' ' git reflog exists $outside ' -test_expect_success 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD' ' +test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' ' test_config core.logAllRefUpdates always && git update-ref ORIG_HEAD $A && - test_must_fail git reflog exists ORIG_HEAD + git reflog exists ORIG_HEAD ' test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
@@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && test_must_fail git rev-parse PSEUDOREF && - test_i18ngrep "could not read ref" err + test_i18ngrep "unable to resolve reference" err ' test_expect_success 'create pseudoref' '
@@ -497,7 +497,7 @@ test_expect_success 'overwrite pseudoref with correct old value' ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && test $C = $(git rev-parse PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref' '
@@ -509,7 +509,7 @@ test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && test $A = $(git rev-parse PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref with correct old value' '
t/t1405-main-ref-store.sh +4 -1
@@ -31,9 +31,12 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' ' test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' ' git rev-parse FOO -- && git rev-parse refs/tags/new-tag -- && + m=$(git rev-parse master) && $RUN delete-refs 0 nothing FOO refs/tags/new-tag && test_must_fail git rev-parse FOO -- && - test_must_fail git rev-parse refs/tags/new-tag -- + test_must_fail git rev-parse refs/tags/new-tag --&& + test_must_fail git rev-parse master -- && + git update-ref refs/heads/master $m ' test_expect_success 'rename_refs(master, new-master)' '
Signature · 1 line
gitgitgadget
PATCH v3 3/3 Make HEAD a PSEUDOREF rather than PER_WORKTREE.
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
This is consistent with the definition of REF_TYPE_PSEUDOREF (uppercase in the root ref namespace).
--- refs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
refs.c +3 -4
@@ -708,10 +708,9 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)static int is_per_worktree_ref (const char *refname) { -return !strcmp (refname,"HEAD" ) || -starts_with (refname,"refs/worktree/" ) || -starts_with (refname,"refs/bisect/" ) || -starts_with (refname,"refs/rewritten/" ); +return starts_with (refname,"refs/worktree/" ) || +starts_with (refname,"refs/bisect/" ) || +starts_with (refname,"refs/rewritten/" ); }static int is_pseudoref_syntax (const char *refname)
Signature · 1 line
gitgitgadget
Quoted 4 lines · Han-Wen Nienhuys via GitGitGadget
This gets rid of the special casing code for pseudorefs in
refs.cThis is in preparation for reftable.
Quoted 8 lines
v3
* tweak git-update-ref.txt description for logAllRefUpdates
Han-Wen Nienhuys (3):
t1400: use git rev-parse for testing PSEUDOREF existence Modify pseudo refs through ref backend storage Make HEAD a PSEUDOREF rather thanPER_WORKTREE.
I reviewed some codepaths that deal with FETCH_HEAD recently.
As the file is quite different from all the other pseudo references in that it needs to store more than one object name and in that each ref in it needs more than just the object name, I doubt that it makes much sense to enhance the refs API so that its requirements can be covered.
It would probably make sense for FETCH_HEAD to stay "a text file directly underneath $GIT_DIR", but get_oid() needs to be able to read it and return the first object name recorded in the file.
Re: [PATCH v3 2/3] Modify pseudo refs through ref backend storage
In reply to Han-Wen Nienhuys via GitGitGadgetHi Han-Wen,
Quoted 12 lines · Han-Wen Nienhuys via GitGitGadget
From: Han-Wen Nienhuys <[email protected]>
The previous behavior was introduced in commit
74ec19d4be("pseudorefs: create and use pseudoref update and delete functions", Jul 31, 2015), with the justification "alternate ref backends still need to store pseudorefs inGIT_DIR".Refs such as
REBASE_HEADare read through the ref backend. This can only work consistently if they are written through the ref backend as well. Tooling that works directly on files under .git should be updated to use git commands to read refs instead.
Quoted 7 lines
The following behaviors change:
* Updates to pseudorefs (eg.
ORIG_HEAD) with core.logAllRefUpdates=always will create reflogs for the pseudoref.* non-HEAD pseudoref symrefs are also dereferenced on deletion. Update t1405 accordingly.
Unfortunately, there is still a breakage in t1405, although it only really shows up on Windows and macOS because of case-insensitive filesystems.
https://github.com/gitgitgadget/git/runs/879772942?check_suite_focus=true
shows the concrete problem: t1405.17 'delete_ref(refs/heads/foo)' will fail thusly:
++ test-tool ref-store main delete-ref msg refs/heads/foo c90e4dc5e12224a428dedfbd45ba11e5531706a2 0 error: cannot lock ref 'refs/heads/foo': is at 1e995a94b5a60488b6ebaf78ec779d85a55ea700 but expected c90e4dc5e12224a428dedfbd45ba11e5531706a2 error: last command exited with $?=1
The reason is that there exists a refs/heads/foo _and_ the symref FOO (which points to refs/heads/master, which is at 1e995a).
An earlier symptom of this bug is visible on Linux, too, though: when you run t1405.4 'delete_refs(FOO, refs/tags/new-tag)', it shows this:
+ git rev-parse FOO --
warning: ignoring dangling symref FOO
fatal: bad revision 'FOO'
(Seeing this warning suggests to me that this should probably be caught _by the regression test_, i.e. stderr should be redirected, and it should be verified via test_i18ngrep that that warning is not shown.)
The reason for this warning is that the symref .git/FOO is no longer removed as part of t1405.4 'delete_refs(FOO, refs/tags/new-tag)'. I've used this patch to bisect the breakage down to this here patch:
-- snip --
t/t1405-main-ref-store.sh +1 -0
@@ -34,6 +34,7 @@ test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' ' m=$(git rev-parse master) && $RUN delete-refs 0 nothing FOO refs/tags/new-tag && test_must_fail git rev-parse FOO -- && + test_path_is_missing .git/FOO && test_must_fail git rev-parse refs/tags/new-tag --&& test_must_fail git rev-parse master -- && git update-ref refs/heads/master $m
-- snap --
Hopefully you can figure out what is going wrong.
Ciao,
Dscho
Quoted 7 lines · Junio C Hamano
I reviewed some codepaths that deal with
FETCH_HEADrecently.As the file is quite different from all the other pseudo references in that it needs to store more than one object name and in that each ref in it needs more than just the object name, I doubt that it makes much sense to enhance the refs API so that its requirements can be covered.
I agree. Do we ever pretend that FETCH_HEAD is a ref today?
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Re: [PATCH v3 2/3] Modify pseudo refs through ref backend storage
In reply to Johannes SchindelinQuoted 9 lines · Johannes Schindelin
The reason is that there exists a
refs/heads/foo_and_ the symrefFOO(which points torefs/heads/master, which is at 1e995a).An earlier symptom of this bug is visible on Linux, too, though: when you run t1405.4 '
delete_refs(FOO, refs/tags/new-tag)', it shows this:+ git rev-parse FOO --
warning: ignoring dangling symref FOO
fatal: bad revision 'FOO'
Thanks, this was very helpful for debugging.
The reason is that we do split_symref_update(), where a transaction that modifies SYMREF (pointing to REFERENT) without REF_NO_DEREF is changed to a transaction that modifies REFERENT and a reflog-only update for SYMREF. In this case, that leaves the FOO symref in place.
This seems very specific to the test (is there any use of symrefs beyond HEAD?) , and I fixed it by passing REF_NO_DEREF to the delete-refs call.
It would also be nice if this behavior was lifted out of the files backend and into the generic layer, but it's not yet clear to me if this is possible.
Signature · 7 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Quoted 10 lines · Han-Wen Nienhuys
Quoted 7 lines · Junio C Hamano
I reviewed some codepaths that deal with
FETCH_HEADrecently.As the file is quite different from all the other pseudo references in that it needs to store more than one object name and in that each ref in it needs more than just the object name, I doubt that it makes much sense to enhance the refs API so that its requirements can be covered.
I agree. Do we ever pretend that
FETCH_HEADis a ref today?
"git rev-parse FETCH_HEAD", "git show FETCH_HEAD" etc. all should keep working, so in that sense, it is treated as a ref. It does not protect the history leading to the objects listed in it from being collected, though.
"git merge FETCH_HEAD" is an interesting case---I haven't thought it through.
Jung fubhyq unccra nsgre "tvg chyy bevtva sbb one" nggrzcgf gb teno gjb oenapurf naq znxr na bpgbchf zretr vagb gur oenapu pheeragyl purpxrq bhg, naq gura "tvg erfrg --uneq && tvg zretr SRGPU_URNQ" vf tvira?
v4 cover Remove special casing for PSEUDOREF updates
In reply to Han-Wen Nienhuys via GitGitGadgetThis gets rid of the special casing code for pseudorefs in refs.c
This is in preparation for reftable.
v4
* Address problems on case-insensitive file systems reported by Dscho.
Han-Wen Nienhuys (3):
t1400: use git rev-parse for testing PSEUDOREF existence Modify pseudo refs through ref backend storage Make HEAD a PSEUDOREF rather than PER_WORKTREE.
Documentation/git-update-ref.txt | 13 ++-- refs.c | 127 +++---------------------------- t/t1400-update-ref.sh | 30 ++++---- t/t1405-main-ref-store.sh | 5 +- 4 files changed, 36 insertions(+), 139 deletions(-)
base-commit: 5c06d60fc55d2213c089f63c282468080f812686
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-673%2Fhanwen%2Fpseudoref-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-673/hanwen/pseudoref-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/673
Range-diff vs v3:
1: 28bd3534d0 = 1: b5274d9053 t1400: use git rev-parse for testing PSEUDOREF existence
2: 79cd5dd480 ! 2: ba5f1b4d26 Modify pseudo refs through ref backend storage
@@ t/t1405-main-ref-store.sh: test_expect_success 'create_symref(FOO, refs/heads/ma
test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
git rev-parse FOO -- &&
git rev-parse refs/tags/new-tag -- &&
+- $RUN delete-refs 0 nothing FOO refs/tags/new-tag &&
+ m=$(git rev-parse master) &&
- $RUN delete-refs 0 nothing FOO refs/tags/new-tag &&
++ REF_NO_DEREF=1 &&
++ $RUN delete-refs $REF_NO_DEREF nothing FOO refs/tags/new-tag &&
++ test_must_fail git rev-parse --symbolic-full-name FOO &&
test_must_fail git rev-parse FOO -- &&
-- test_must_fail git rev-parse refs/tags/new-tag --
-+ test_must_fail git rev-parse refs/tags/new-tag --&&
-+ test_must_fail git rev-parse master -- &&
-+ git update-ref refs/heads/master $m
+ test_must_fail git rev-parse refs/tags/new-tag --
'
-
- test_expect_success 'rename_refs(master, new-master)' ' 3: 3ab9f2f04e = 3: 358d34df07 Make HEAD a PSEUDOREF rather than PER_WORKTREE.
Signature · 1 line
gitgitgadget
PATCH v4 1/3 t1400: use git rev-parse for testing PSEUDOREF existence
From: Han-Wen Nienhuys <[email protected]>
This will allow these tests to run with alternative ref backends
--- t/t1400-update-ref.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
t/t1400-update-ref.sh +10 -10
@@ -475,57 +475,57 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && - test_path_is_missing .git/PSEUDOREF && + test_must_fail git rev-parse PSEUDOREF && test_i18ngrep "could not read ref" err ' test_expect_success 'create pseudoref' ' git update-ref PSEUDOREF $A && - test $A = $(cat .git/PSEUDOREF) + test $A = $(git rev-parse PSEUDOREF) ' test_expect_success 'overwrite pseudoref with no old value given' ' git update-ref PSEUDOREF $B && - test $B = $(cat .git/PSEUDOREF) + test $B = $(git rev-parse PSEUDOREF) ' test_expect_success 'overwrite pseudoref with correct old value' ' git update-ref PSEUDOREF $C $B && - test $C = $(cat .git/PSEUDOREF) + test $C = $(git rev-parse PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && - test $C = $(cat .git/PSEUDOREF) && + test $C = $(git rev-parse PSEUDOREF) && test_i18ngrep "unexpected object ID" err ' test_expect_success 'delete pseudoref' ' git update-ref -d PSEUDOREF && - test_path_is_missing .git/PSEUDOREF + test_must_fail git rev-parse PSEUDOREF ' test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && - test $A = $(cat .git/PSEUDOREF) && + test $A = $(git rev-parse PSEUDOREF) && test_i18ngrep "unexpected object ID" err ' test_expect_success 'delete pseudoref with correct old value' ' git update-ref -d PSEUDOREF $A && - test_path_is_missing .git/PSEUDOREF + test_must_fail git rev-parse PSEUDOREF ' test_expect_success 'create pseudoref with old OID zero' ' git update-ref PSEUDOREF $A $Z && - test $A = $(cat .git/PSEUDOREF) + test $A = $(git rev-parse PSEUDOREF) ' test_expect_success 'do not overwrite pseudoref with old OID zero' ' test_when_finished git update-ref -d PSEUDOREF && test_must_fail git update-ref PSEUDOREF $B $Z 2>err && - test $A = $(cat .git/PSEUDOREF) && + test $A = $(git rev-parse PSEUDOREF) && test_i18ngrep "already exists" err '
Signature · 1 line
gitgitgadget
PATCH v4 2/3 Modify pseudo refs through ref backend storage
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
The previous behavior was introduced in commit 74ec19d4be ("pseudorefs: create and use pseudoref update and delete functions", Jul 31, 2015), with the justification "alternate ref backends still need to store pseudorefs in GIT_DIR".
Refs such as REBASE_HEAD are read through the ref backend. This can only work consistently if they are written through the ref backend as well. Tooling that works directly on files under .git should be updated to use git commands to read refs instead.
The following behaviors change:
* Updates to pseudorefs (eg. ORIG_HEAD) with core.logAllRefUpdates=always will create reflogs for the pseudoref.
* non-HEAD pseudoref symrefs are also dereferenced on deletion. Update t1405 accordingly.
--- Documentation/git-update-ref.txt | 13 ++-- refs.c | 120 ++----------------------------- t/t1400-update-ref.sh | 10 +-- t/t1405-main-ref-store.sh | 5 +- 4 files changed, 23 insertions(+), 125 deletions(-)
Documentation/git-update-ref.txt +7 -6
@@ -148,12 +148,13 @@ still see a subset of the modifications. LOGGING UPDATES --------------- -If config parameter "core.logAllRefUpdates" is true and the ref is one under -"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; or -the file "$GIT_DIR/logs/<ref>" exists then `git update-ref` will append -a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all -symbolic refs before creating the log name) describing the change -in ref value. Log lines are formatted as: +If config parameter "core.logAllRefUpdates" is true and the ref is one +under "refs/heads/", "refs/remotes/", "refs/notes/", or a pseudoref +like HEAD or ORIG_HEAD; or the file "$GIT_DIR/logs/<ref>" exists then +`git update-ref` will append a line to the log file +"$GIT_DIR/logs/<ref>" (dereferencing all symbolic refs before creating +the log name) describing the change in ref value. Log lines are +formatted as: oldsha1 SP newsha1 SP committer LF
refs.c +7 -113
138 lines not on this page · raw message
t/t1400-update-ref.sh +5 -5
@@ -160,10 +160,10 @@ test_expect_success 'core.logAllRefUpdates=always creates reflog by default' ' git reflog exists $outside ' -test_expect_success 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD' ' +test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' ' test_config core.logAllRefUpdates always && git update-ref ORIG_HEAD $A && - test_must_fail git reflog exists ORIG_HEAD + git reflog exists ORIG_HEAD ' test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
@@ -476,7 +476,7 @@ test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER test_expect_success 'given old value for missing pseudoref, do not create' ' test_must_fail git update-ref PSEUDOREF $A $B 2>err && test_must_fail git rev-parse PSEUDOREF && - test_i18ngrep "could not read ref" err + test_i18ngrep "unable to resolve reference" err ' test_expect_success 'create pseudoref' '
@@ -497,7 +497,7 @@ test_expect_success 'overwrite pseudoref with correct old value' ' test_expect_success 'do not overwrite pseudoref with wrong old value' ' test_must_fail git update-ref PSEUDOREF $D $E 2>err && test $C = $(git rev-parse PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref' '
@@ -509,7 +509,7 @@ test_expect_success 'do not delete pseudoref with wrong old value' ' git update-ref PSEUDOREF $A && test_must_fail git update-ref -d PSEUDOREF $B 2>err && test $A = $(git rev-parse PSEUDOREF) && - test_i18ngrep "unexpected object ID" err + test_i18ngrep "cannot lock ref.*expected" err ' test_expect_success 'delete pseudoref with correct old value' '
t/t1405-main-ref-store.sh +4 -1
@@ -31,7 +31,10 @@ test_expect_success 'create_symref(FOO, refs/heads/master)' ' test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' ' git rev-parse FOO -- && git rev-parse refs/tags/new-tag -- && - $RUN delete-refs 0 nothing FOO refs/tags/new-tag && + m=$(git rev-parse master) && + REF_NO_DEREF=1 && + $RUN delete-refs $REF_NO_DEREF nothing FOO refs/tags/new-tag && + test_must_fail git rev-parse --symbolic-full-name FOO && test_must_fail git rev-parse FOO -- && test_must_fail git rev-parse refs/tags/new-tag -- '
Signature · 1 line
gitgitgadget
PATCH v4 3/3 Make HEAD a PSEUDOREF rather than PER_WORKTREE.
In reply to Han-Wen Nienhuys via GitGitGadgetFrom: Han-Wen Nienhuys <[email protected]>
This is consistent with the definition of REF_TYPE_PSEUDOREF (uppercase in the root ref namespace).
--- refs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
refs.c +3 -4
@@ -708,10 +708,9 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)static int is_per_worktree_ref (const char *refname) { -return !strcmp (refname,"HEAD" ) || -starts_with (refname,"refs/worktree/" ) || -starts_with (refname,"refs/bisect/" ) || -starts_with (refname,"refs/rewritten/" ); +return starts_with (refname,"refs/worktree/" ) || +starts_with (refname,"refs/bisect/" ) || +starts_with (refname,"refs/rewritten/" ); }static int is_pseudoref_syntax (const char *refname)
Signature · 1 line
gitgitgadget
Quoted 9 lines · Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 7 lines
I reviewed some codepaths that deal with
FETCH_HEADrecently.As the file is quite different from all the other pseudo references in that it needs to store more than one object name and in that each ref in it needs more than just the object name, I doubt that it makes much sense to enhance the refs API so that its requirements can be covered.
Quoted 4 lines
Quoted 1 line
I agree. Do we ever pretend that
FETCH_HEADis a ref today?"git rev-parse
FETCH_HEAD", "git showFETCH_HEAD" etc. all should keep working, so in that sense, it is treated as a ref.
I added this to the last version of the full reftable patch series that I posted, as patches
"Split off reading loose ref data in separate function" and "Read FETCH_HEAD as loose ref".
Which other refs that aren't really refs should also be supported? The JGit source code suggests that MERGE_HEAD should also be special cased?
It's not pretty, though. The entry point is read_raw_ref(), which gets a ref_store as argument. ref_store doesn't have generic API to get at the repository directory, so the implementation of reading the FETCH_HEAD file has to be pushed down to the ref backend (which does know the directory).
Quoted 3 lines
It does not
protect the history leading to the objects listed in it from being collected, though.
Is there documented agreement of how pseudo refs and GC should interact?
Quoted 7 lines
"git merge
FETCH_HEAD" is an interesting case---I haven't thought it through.What should happen after "git pull origin foo bar" attempts to grab two branches and make an octopus merge into the branch currently checked out, and then "git reset --hard && git merge
FETCH_HEAD" is given?
I don't understand this question.
Signature · 7 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Quoted 11 lines · Han-Wen Nienhuys
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
As the file is quite different from all the other pseudo references in that it needs to store more than one object name and in that each ref in it needs more than just the object name, I doubt that it makes much sense to enhance the refs API so that its requirements can be covered.
I agree. Do we ever pretend that
FETCH_HEADis a ref today?"git rev-parse
FETCH_HEAD", "git showFETCH_HEAD" etc. all should keep working, so in that sense, it is treated as a ref.
Quoted 8 lines
I added this to the last version of the full reftable patch series that I posted, as patches
"Split off reading loose ref data in separate function" and "ReadFETCH_HEADas loose ref".Which other refs that aren't really refs should also be supported? The JGit source code suggests that
MERGE_HEADshould also be special cased?
I'd think all .git/${SOMETHING}_HEAD are of transitory nature that can be left as simple on-disk files that are read (and preferrably written---except for FETCH_HEAD for obvious reasons) as if they are loose refs handled by files backend. It probably makes sense not to even write reflog entries for them---it is not like the MERGE_HEAD I see now in .git/ directory is an updated version of MERGE_HEAD I had there yesterday. "git log -g MERGE_HEAD" gives no interesting information.
Quoted 9 lines
Quoted 7 lines
"git merge
FETCH_HEAD" is an interesting case---I haven't thought it through.What should happen after "git pull origin foo bar" attempts to grab two branches and make an octopus merge into the branch currently checked out, and then "git reset --hard && git merge
FETCH_HEAD" is given?I don't understand this question.
The request "git pull origin foo bar" is "grab the tip of 'foo' and 'bar' branches from remote whose name is 'origin'; merge these two commits into the commit that I have checked out".
To fulfill the request, "git pull" runs "git fetch", and the latter leaves two lines of interest in .git/FETCH_HEAD file. Each line lists the name of the object at the ref, an optional "not-for-merge" token (which in this case does not exist, as both records are for merging), and piece of human-readable text to describe where that object came from to help later step that computes the default message for the resulting merge commit.
If the octopus merge does not finish correctly (e.g. due to conflicts), with "git reset --hard", we can recover to the original state and re-attempt the opeation with "git merge FETCH_HEAD". Such a merge using FETCH_HEAD will produce an octopus merge.
Which means that at least "git merge", FETCH_HEAD is not just a regular ref where you can ask what object it points at and it gives you a single object name back.
But to other commands like "git log master..FETCH_HEAD", it acts as if there is only one object recorded. That makes it an interesting case. Making it act as if "git log ^master origin/foo origin/bar" were given might be a "bugfix" to make it behave more "correctly", but I do not know how large a fallout such a change brings in.
Quoted 8 lines · Junio C Hamano
Quoted 3 lines
Which other refs that aren't really refs should also be supported? The JGit source code suggests that
MERGE_HEADshould also be special cased?I'd think all .git/${SOMETHING}_HEAD are of transitory nature that can be left as simple on-disk files that are read (and preferrably written---except for
FETCH_HEADfor obvious reasons) as if they are loose refs handled by files backend.
Sorry for flipping and flopping. The above goes directly against the spirit of 09743417 (Modify pseudo refs through ref backend storage, 2020-07-27). I still think .git/${SOMETHING}_HEAD except for FETCH_HEAD should be written and read via the ref subsystem, but I was wrong to say that it should always be done via the files backend. There is no reason to insist on the use of files backend here.
Quoted 5 lines
It probably makes sense not to
even write reflog entries for them---it is not like theMERGE_HEADI see now in .git/ directory is an updated version ofMERGE_HEADI had there yesterday. "git log -gMERGE_HEAD" gives no interesting information.
This still is true, but that is pretty much orthogonal to which backend is used.
Quoted 11 lines
If the octopus merge does not finish correctly (e.g. due to conflicts), with "git reset --hard", we can recover to the original state and re-attempt the opeation with "git merge
FETCH_HEAD". Such a merge usingFETCH_HEADwill produce an octopus merge.Which means that at least "git merge",
FETCH_HEADis not just a regular ref where you can ask what object it points at and it gives you a single object name back.But to other commands like "git log master..FETCH_HEAD", it acts as if there is only one object recorded.
All of which means FETCH_HEAD is special and we may not want to burden the special casing of it to newer backends.
Quoted 5 lines · Junio C Hamano
Quoted 4 lines
I'd think all .git/${SOMETHING}_HEAD are of transitory nature that can be left as simple on-disk files that are read (and preferrably written---except for
FETCH_HEADfor obvious reasons) as if they are loose refs handled by files backend.
Quoted 7 lines
Sorry for flipping and flopping. The above goes directly against the spirit of 09743417 (Modify pseudo refs through ref backend storage, 2020-07-27). I still think .git/${SOMETHING}_HEAD except for
FETCH_HEADshould be written and read via the ref subsystem, but I was wrong to say that it should always be done via the files backend. There is no reason to insist on the use of files backend here.
Yes, that confused me. Thanks for setting that straight.
Quoted 9 lines
Quoted 9 lines
If the octopus merge does not finish correctly (e.g. due to conflicts), with "git reset --hard", we can recover to the original state and re-attempt the opeation with "git merge
FETCH_HEAD". Such a merge usingFETCH_HEADwill produce an octopus merge.Which means that at least "git merge",
FETCH_HEADis not just a regular ref where you can ask what object it points at and it gives you a single object name back.
Quoted 5 lines
Quoted 2 lines
But to other commands like "git log master..FETCH_HEAD", it acts as if there is only one object recorded.
All of which means
FETCH_HEADis special and we may not want to burden the special casing of it to newer backends.
Can you confirm that FETCH_HEAD is the only thing that can store more than just a symref / SHA1 ? Based on the name, and a comment in the JGit source, I thought that MERGE_HEAD might contain more than one SHA1 at a time.
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Quoted 7 lines · Han-Wen Nienhuys
Quoted 2 lines
All of which means
FETCH_HEADis special and we may not want to burden the special casing of it to newer backends.Can you confirm that
FETCH_HEADis the only thing that can store more than just a symref / SHA1 ? Based on the name, and a comment in the JGit source, I thought thatMERGE_HEADmight contain more than one SHA1 at a time.
No I cannot. I do not think MERGE_HEAD is something I added with as deep a thought as I did with FETCH_HEAD. If it mimics FETCH_HEAD, then perhaps it does, but I somehow doubt it.
As can be seen in builtin/merge.c::collect_parents(), we do special case FETCH_HEAD when grabbing what commit*S* to merge, but all others are read with get_merge_parent() that makes a single call to get_oid(), i.e. anything other than FETCH_HEAD cannot have more than one object recorded.
Quoted 12 lines · Junio C Hamano
Quoted 7 lines
Quoted 2 lines
All of which means
FETCH_HEADis special and we may not want to burden the special casing of it to newer backends.Can you confirm that
FETCH_HEADis the only thing that can store more than just a symref / SHA1 ? Based on the name, and a comment in the JGit source, I thought thatMERGE_HEADmight contain more than one SHA1 at a time.No I cannot. I do not think
MERGE_HEADis something I added with as deep a thought as I did withFETCH_HEAD. If it mimicsFETCH_HEAD, then perhaps it does, but I somehow doubt it.
Quoted 5 lines
As can be seen in builtin/merge.c::collect_parents(), we do special case
FETCH_HEADwhen grabbing what commit*S* to merge, but all others are read withget_merge_parent()that makes a single call toget_oid(), i.e. anything other thanFETCH_HEADcannot have more than one object recorded.
Understood. Is there anything you'd like me to do with this patch series so it can be merged?
Dealing with FETCH_HEAD generically isn't possible unless we extend the API of the ref backend: the generic ref_store instance doesn't offer a way to get at the path that corresponds to FETCH_HEAD, so we can't handle it in refs_read_raw_ref(). In the current reftable series, FETCH_HEAD is dealt with in the backends separately.
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Quoted 5 lines · Han-Wen Nienhuys
Dealing with
FETCH_HEADgenerically isn't possible unless we extend the API of the ref backend: the genericref_storeinstance doesn't offer a way to get at the path that corresponds toFETCH_HEAD, so we can't handle it inrefs_read_raw_ref(). In the current reftable series,FETCH_HEADis dealt with in the backends separately.
I am not sure what the best way would be, but I do not think any existing code writes into it using the refs API at all, even though it may be read only for the first object name using the refs API.
And I am not sure if we want to extend the write side API so that the callers can express the full flexibility of that single file.
So perhaps the best way forward would be to ensure that anybody who tries to read from FETCH_HEAD using the ref API reads the first object name in it from $GIT_DIR/FETCH_HEAD file as we've always done since the beginning of time, regardless of what ref backend is used, that anybody who tries to write FETCH_HEAD using the ref API gets an error, and letting the writers write into it directly?
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Han-Wen Nienhuys
Dealing with
FETCH_HEADgenerically isn't possible unless we extend the API of the ref backend: the genericref_storeinstance doesn't offer a way to get at the path that corresponds toFETCH_HEAD, so we can't handle it inrefs_read_raw_ref(). In the current reftable series,FETCH_HEADis dealt with in the backends separately.
Quoted 6 lines
I am not sure what the best way would be, but I do not think any existing code writes into it using the refs API at all, even though it may be read only for the first object name using the refs API.
And I am not sure if we want to extend the write side API so that the callers can express the full flexibility of that single file.
That's not what I am getting at. I am just interested in how to handle FETCH_HEAD in refs_read_raw_ref.
Quoted 4 lines
So perhaps the best way forward would be to ensure that anybody who tries to read from
FETCH_HEADusing the ref API reads the first object name in it from $GIT_DIR/FETCH_HEAD file as we've always done since the beginning of time, regardless of what ref backend is used,
Right, but how do we get at the value of $GIT_DIR given a struct ref_store? We can either push that out to the ref store backend, because each backend knows what $GIT_DIR is, or we can make $GIT_DIR a property of the generic ref_store.
I suppose it's cleaner to make the latter API extension.
Signature · 11 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Quoted 25 lines · Han-Wen Nienhuys
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Han-Wen Nienhuys
Dealing with
FETCH_HEADgenerically isn't possible unless we extend the API of the ref backend: the genericref_storeinstance doesn't offer a way to get at the path that corresponds toFETCH_HEAD, so we can't handle it inrefs_read_raw_ref(). In the current reftable series,FETCH_HEADis dealt with in the backends separately.Quoted 6 lines
I am not sure what the best way would be, but I do not think any existing code writes into it using the refs API at all, even though it may be read only for the first object name using the refs API.
And I am not sure if we want to extend the write side API so that the callers can express the full flexibility of that single file.
That's not what I am getting at. I am just interested in how to handle
FETCH_HEADinrefs_read_raw_ref.Quoted 4 lines
So perhaps the best way forward would be to ensure that anybody who tries to read from
FETCH_HEADusing the ref API reads the first object name in it from $GIT_DIR/FETCH_HEAD file as we've always done since the beginning of time, regardless of what ref backend is used,
Quoted 6 lines
Right, but how do we get at the value of $GIT_DIR given a struct
ref_store? We can either push that out to the ref store backend, because each backend knows what $GIT_DIR is, or we can make $GIT_DIR a property of the genericref_store.I suppose it's cleaner to make the latter API extension.
Yup. Sounds like the right direction to go.
Thanks.
Quoted 11 lines · Junio C Hamano
Quoted 7 lines
Quoted 2 lines
All of which means
FETCH_HEADis special and we may not want to burden the special casing of it to newer backends.Can you confirm that
FETCH_HEADis the only thing that can store more than just a symref / SHA1 ? Based on the name, and a comment in the JGit source, I thought thatMERGE_HEADmight contain more than one SHA1 at a time.No I cannot. I do not think
MERGE_HEADis something I added with as deep a thought as I did withFETCH_HEAD. If it mimicsFETCH_HEAD, then perhaps it does, but I somehow doubt it.
blame.c has an append_merge_parents() which reads multiple lines from MERGE_HEAD, and cmd_commit does so too. It's populated from write_merge_heads(). So the special casing should be extended to MERGE_HEAD.
Signature · 7 lines
Han-Wen Nienhuys - Google Munich I work 80%. Don't expect answers from me on Fridays. -- Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Quoted 4 lines · Han-Wen Nienhuys
blame.chas anappend_merge_parents()which reads multiple lines fromMERGE_HEAD, andcmd_commitdoes so too. It's populated fromwrite_merge_heads(). So the special casing should be extended toMERGE_HEAD.
Ahh. That makes sense.