pseudorefs
v2 cover pseudorefs
This version of the pseudorefs patch series is much simpler. Instead of forbidding update_ref and delete_ref from updating pseudorefs, these functions now just special-case pseudorefs. So we can use update_ref to write pseudorefs in a rebase and sequencer, and we don't need to rewrite so much code.
In addition, I made typo fixes suggested by Eric Sunshine and Philip Oakley.
PATCH v2 1/5 refs: Introduce pseudoref and per-worktree ref concepts
Add glossary entries for both concepts.
Pseudorefs and per-worktree refs do not yet have special handling, because the files refs backend already handles them correctly. Later, we will make the LMDB backend call out to the files backend to handle per-worktree refs.
--- Documentation/glossary-content.txt | 21 +++++++++++++++++++++ refs.c | 23 +++++++++++++++++++++++ refs.h | 2 ++ 3 files changed, 46 insertions(+)
Documentation/glossary-content.txt +21 -0
@@ -411,6 +411,27 @@ exclude;; core Git. Porcelains expose more of a <<def_SCM,SCM>> interface than the <<def_plumbing,plumbing>>. +[[def_per_worktree_ref]]per-worktree ref:: + Refs that are per-<<def_worktree,worktree>>, rather than + global. This is presently only <<def_HEAD,HEAD>>, but might + later include other unusual refs. + +[[def_pseudoref]]pseudoref:: + Pseudorefs are a class of files under `$GIT_DIR` which behave + like refs for the purposes of rev-parse, but which are treated + specially by git. Psuedorefs both have names are all-caps, + and always start with a line consisting of a + <<def_sha1,SHA-1>> followed by whitespace. So, HEAD is not a + pseudoref, because it is sometimes a symbolic ref. They might + optionally some additional data. `MERGE_HEAD` and + `CHERRY_PICK_HEAD` are examples. Unlike + <<def_per_worktree_ref,per-worktree refs>>, these files cannot + be symbolic refs, and never have reflogs. They also cannot be + updated through the normal ref update machinery. Instead, + they are updated by directly writing to the files. However, + they can be read as if they were refs, so `git rev-parse + MERGE_HEAD` will work. + [[def_pull]]pull:: Pulling a <<def_branch,branch>> means to <<def_fetch,fetch>> it and <<def_merge,merge>> it. See also linkgit:git-pull[1].
refs.c +23 -0
@@ -2848,6 +2848,29 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)return 0 ; } +int is_per_worktree_ref (const char *refname) +{ +return !strcmp (refname,"HEAD" ); +} + +static int is_pseudoref (const char *refname) +{ +const char *c; + +if (strchr (refname,'/' )) +return 0 ; + +if (is_per_worktree_ref (refname)) +return 0 ; + +for (c = refname; *c; ++c) { +if (!isupper (*c) && *c !='-' && *c !='_' ) +return 0 ; + } + +return 1 ; +} +int delete_ref (const char *refname,const unsigned char *old_sha1,unsigned int flags) {
refs.h +2 -0
@@ -445,6 +445,8 @@ extern int parse_hide_refs_config(const char *var, const char *value, const charextern int ref_is_hidden (const char *); +int is_per_worktree_ref (const char *refname); +enum expire_reflog_flags {EXPIRE_REFLOGS_DRY_RUN =1 <<0 ,EXPIRE_REFLOGS_UPDATE_REF =1 <<1 ,
Signature · 1 line
2.0.4.315.gad8727a-twtrsrc
PATCH v2 2/5 notes: replace pseudorefs with real refs
In reply to David TurnerAll-caps files like NOTES_MERGE_REF are pseudorefs, and thus are per-worktree. We don't want multiple notes merges happening at once (in different worktrees), so we want to make these refs true refs.
So, we lowercase NOTES_MERGE_REF and friends. That way, backends that distinguish between pseudorefs and real refs can correctly handle notes merges.
This will also enable us to prevent pseudorefs from being updated by the ref update machinery e.g. git update-ref.
--- Documentation/git-notes.txt | 12 ++--- builtin/notes.c | 38 ++++++++-------- notes-merge.c | 10 ++-- notes-merge.h | 8 ++-- t/t3310-notes-merge-manual-resolve.sh | 86 +++++++++++++++++------------------ t/t3311-notes-merge-fanout.sh | 6 +-- 6 files changed, 80 insertions(+), 80 deletions(-)
Documentation/git-notes.txt +6 -6
@@ -103,7 +103,7 @@ merge:: If conflicts arise and a strategy for automatically resolving conflicting notes (see the -s/--strategy option) is not given, the "manual" resolver is used. This resolver checks out the -conflicting notes in a special worktree (`.git/NOTES_MERGE_WORKTREE`), +conflicting notes in a special worktree (`.git/notes_merge_worktree`), and instructs the user to manually resolve the conflicts there. When done, the user can either finalize the merge with 'git notes merge --commit', or abort the merge with
@@ -189,11 +189,11 @@ OPTIONS --commit:: Finalize an in-progress 'git notes merge'. Use this option when you have resolved the conflicts that 'git notes merge' - stored in .git/NOTES_MERGE_WORKTREE. This amends the partial + stored in .git/notes_merge_worktree. This amends the partial merge commit created by 'git notes merge' (stored in - .git/NOTES_MERGE_PARTIAL) by adding the notes in - .git/NOTES_MERGE_WORKTREE. The notes ref stored in the - .git/NOTES_MERGE_REF symref is updated to the resulting commit. + .git/notes_merge_partial) by adding the notes in + .git/notes_merge_worktree. The notes ref stored in the + .git/notes_merge_ref symref is updated to the resulting commit. --abort:: Abort/reset a in-progress 'git notes merge', i.e. a notes merge
@@ -241,7 +241,7 @@ NOTES MERGE STRATEGIES The default notes merge strategy is "manual", which checks out conflicting notes in a special work tree for resolving notes conflicts -(`.git/NOTES_MERGE_WORKTREE`), and instructs the user to resolve the +(`.git/notes_merge_worktree`), and instructs the user to resolve the conflicts in that work tree. When done, the user can either finalize the merge with 'git notes merge --commit', or abort the merge with
builtin/notes.c +19 -19
@@ -670,14 +670,14 @@ static int merge_abort(struct notes_merge_options *o)int ret =0 ;/* -* Remove .git/NOTES_MERGE_PARTIAL and .git/NOTES_MERGE_REF, and call -* notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE. +* Remove .git/notes_merge_partial and .git/notes_merge_ref, and call +* notes_merge_abort() to remove .git/notes_merge_worktree. */ -if (delete_ref ("NOTES_MERGE_PARTIAL" ,NULL ,0 )) - ret +=error ("Failed to delete ref NOTES_MERGE_PARTIAL" ); -if (delete_ref ("NOTES_MERGE_REF" ,NULL ,REF_NODEREF )) - ret +=error ("Failed to delete ref NOTES_MERGE_REF" ); +if (delete_ref ("notes_merge_partial" ,NULL ,0 )) + ret +=error ("Failed to delete ref notes_merge_partial" ); +if (delete_ref ("notes_merge_ref" ,NULL ,REF_NODEREF )) + ret +=error ("Failed to delete ref notes_merge_ref" );if (notes_merge_abort (o)) ret +=error ("Failed to remove 'git notes merge' worktree" );return ret;
@@ -694,16 +694,16 @@ static int merge_commit(struct notes_merge_options *o)int ret;/* -* Read partial merge result from .git/NOTES_MERGE_PARTIAL, -* and target notes ref from .git/NOTES_MERGE_REF. +* Read partial merge result from .git/notes_merge_partial, +* and target notes ref from .git/notes_merge_ref. */ -if (get_sha1 ("NOTES_MERGE_PARTIAL" , sha1)) -die ("Failed to read ref NOTES_MERGE_PARTIAL" ); +if (get_sha1 ("notes_merge_partial" , sha1)) +die ("Failed to read ref notes_merge_partial" );else if (!(partial =lookup_commit_reference (sha1))) -die ("Could not find commit from NOTES_MERGE_PARTIAL." ); +die ("Could not find commit from notes_merge_partial." );else if (parse_commit (partial)) -die ("Could not parse commit from NOTES_MERGE_PARTIAL." ); +die ("Could not parse commit from notes_merge_partial." );if (partial->parents)hashcpy (parent_sha1, partial->parents->item->object.sha1);
@@ -711,12 +711,12 @@ static int merge_commit(struct notes_merge_options *o)hashclr (parent_sha1); t =xcalloc (1 ,sizeof (struct notes_tree )); -init_notes (t,"NOTES_MERGE_PARTIAL" , combine_notes_overwrite,0 ); +init_notes (t,"notes_merge_partial" , combine_notes_overwrite,0 ); o->local_ref = local_ref_to_free = -resolve_refdup ("NOTES_MERGE_REF" ,0 , sha1,NULL ); +resolve_refdup ("notes_merge_ref" ,0 , sha1,NULL );if (!o->local_ref) -die ("Failed to resolve NOTES_MERGE_REF" ); +die ("Failed to resolve notes_merge_ref" );if (notes_merge_commit (o, t, partial, sha1))die ("Failed to finalize notes merge" );
@@ -825,11 +825,11 @@ static int merge(int argc, const char **argv, const char *prefix)update_ref (msg.buf,default_notes_ref (), result_sha1,NULL ,0 ,UPDATE_REFS_DIE_ON_ERR ); else { /* Merge has unresolved conflicts */ -/* Update .git/NOTES_MERGE_PARTIAL with partial merge result */ -update_ref (msg.buf,"NOTES_MERGE_PARTIAL" , result_sha1,NULL , +/* Update .git/notes_merge_partial with partial merge result */ +update_ref (msg.buf,"notes_merge_partial" , result_sha1,NULL ,0 ,UPDATE_REFS_DIE_ON_ERR ); -/* Store ref-to-be-updated into .git/NOTES_MERGE_REF */ -if (create_symref ("NOTES_MERGE_REF" ,default_notes_ref (),NULL )) +/* Store ref-to-be-updated into .git/notes_merge_ref */ +if (create_symref ("notes_merge_ref" ,default_notes_ref (),NULL ))die ("Failed to store link to current notes ref (%s)" ,default_notes_ref ()); printf("Automatic notes merge failed. Fix conflicts in %s and "
notes-merge.c +5 -5
@@ -274,10 +274,10 @@ static void check_notes_merge_worktree(struct notes_merge_options *o)"'git notes merge --commit' or 'git notes " "merge --abort' to commit/abort the " "previous merge before you start a new " - "notes merge.", git_path("NOTES_MERGE_*")); + "notes merge.", git_path("notes_merge_*")); else die("You have not concluded your notes merge " - "(%s exists).", git_path("NOTES_MERGE_*")); + "(%s exists).", git_path("notes_merge_*")); } if (safe_create_leading_directories_const(git_path(
@@ -663,7 +663,7 @@ int notes_merge_commit(struct notes_merge_options *o, unsigned char *result_sha1) {/* -* Iterate through files in .git/NOTES_MERGE_WORKTREE and add all +* Iterate through files in .git/notes_merge_workree and add all * found notes to 'partial_tree'. Write the updated notes tree to * the DB, and commit the resulting tree object while reusing the * commit message and parents from 'partial_commit'.
@@ -734,8 +734,8 @@ int notes_merge_commit(struct notes_merge_options *o,int notes_merge_abort (struct notes_merge_options *o) {/* -* Remove all files within .git/NOTES_MERGE_WORKTREE. We do not remove -* the .git/NOTES_MERGE_WORKTREE directory itself, since it might be +* Remove all files within .git/notes_merge_workree. We do not remove +* the .git/notes_merge_workree directory itself, since it might be * the current working directory of the user. */ struct strbuf buf =STRBUF_INIT ;
notes-merge.h +4 -4
@@ -1,7 +1,7 @@#ifndef NOTES_MERGE_H #define NOTES_MERGE_H -#define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE" +#define NOTES_MERGE_WORKTREE "notes_merge_worktree"enum notes_merge_verbosity { NOTES_MERGE_VERBOSITY_DEFAULT = 2,
@@ -46,7 +46,7 @@ void init_notes_merge_options(struct notes_merge_options *o);* are stored in 'local_tree', and the SHA1 or the resulting commit * (to be amended when the conflicts have been resolved) is written into * 'result_sha1'. The unmerged entries are written into the -* .git/NOTES_MERGE_WORKTREE directory with conflict markers. +* .git/notes_merge_worktree directory with conflict markers. * -1 is returned. * * Both o->local_ref and o->remote_ref must be given (non-NULL), but either ref
@@ -65,7 +65,7 @@ int notes_merge(struct notes_merge_options *o,* the given 'partial_commit', the partial result commit created by a previous * call to notes_merge(). * -* This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE +* This function will add the (now resolved) notes in .git/notes_merge_worktree * to 'partial_tree', and create a final notes merge commit, the SHA1 of which * will be stored in 'result_sha1'. */
@@ -77,7 +77,7 @@ int notes_merge_commit(struct notes_merge_options *o,/* * Abort conflict resolution from an earlier notes_merge() * -* Removes the notes merge worktree in .git/NOTES_MERGE_WORKTREE. +* Removes the notes merge worktree in .git/notes_merge_worktree. */ int notes_merge_abort (struct notes_merge_options *o);
t/t3310-notes-merge-manual-resolve.sh +43 -43
196 lines not on this page · raw message
t/t3311-notes-merge-fanout.sh +3 -3
@@ -387,10 +387,10 @@ other notes for commit4 EOF test_expect_success 'verify conflict entries (with no fanout)' ' - ls .git/NOTES_MERGE_WORKTREE >output_conflicts && + ls .git/notes_merge_worktree >output_conflicts && test_cmp expect_conflicts output_conflicts && ( for f in $(cat expect_conflicts); do - test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || + test_cmp "expect_conflict_$f" ".git/notes_merge_worktree/$f" || exit 1 done ) && # Verify that current notes tree (pre-merge) has not changed (m == w)
@@ -417,7 +417,7 @@ other notes for commit1 EOF test_expect_success 'resolve and finalize merge (z => w)' ' - cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <<EOF && + cat >.git/notes_merge_worktree/$commit_sha3 <<EOF && other notes for commit3 appended notes for commit3
Signature · 1 line
2.0.4.315.gad8727a-twtrsrc
PATCH v2 3/5 pseudorefs: create and use pseudoref update and delete functions
In reply to David TurnerPseudorefs should not be updated through the ref transaction API, because alternate ref backends still need to store pseudorefs in GIT_DIR (instead of wherever they store refs). Instead, change update_ref and delete_ref to call pseudoref-specific functions.
--- refs.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 8 deletions(-)
refs.c +92 -8
@@ -2871,12 +2871,87 @@ static int is_pseudoref(const char *refname)return 1 ; } +static int write_pseudoref (const char *pseudoref,const unsigned char *sha1, +const unsigned char *old_sha1,struct strbuf *err) +{ +const char *filename; +int fd; +static struct lock_file lock; +struct strbuf buf =STRBUF_INIT ; +int ret =-1 ; + +strbuf_addf (&buf,"%s\n" ,sha1_to_hex (sha1)); + + filename =git_path ("%s" , pseudoref); + fd =hold_lock_file_for_update (&lock, filename,LOCK_DIE_ON_ERROR ); +if (fd <0 ) { +strbuf_addf (err,"Could not open '%s' for writing: %s" , + filename,strerror (errno)); +return -1 ; + } + +if (old_sha1) { +unsigned char actual_old_sha1[20 ]; +read_ref (pseudoref, actual_old_sha1); +if (hashcmp (actual_old_sha1, old_sha1)) { +strbuf_addf (err,"Unexpected sha1 when writing %s" , pseudoref); +rollback_lock_file (&lock); + goto done; + } + } + +if (write_in_full (fd, buf.buf, buf.len) != buf.len) { +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 unsigned char *old_sha1) +{ +static struct lock_file lock; +const char *filename; + + filename =git_path ("%s" , pseudoref); + +if (old_sha1 && !is_null_sha1 (old_sha1)) { +int fd; +unsigned char actual_old_sha1[20 ]; + + fd =hold_lock_file_for_update (&lock, filename, +LOCK_DIE_ON_ERROR ); +if (fd <0 ) +die_errno (_ ("Could not open '%s' for writing" ), filename); +read_ref (pseudoref, actual_old_sha1); +if (hashcmp (actual_old_sha1, old_sha1)) { +warning ("Unexpected sha1 when deleting %s" , pseudoref); +return -1 ; + } + +unlink (filename); +rollback_lock_file (&lock); + }else { +unlink (filename); + } + +return 0 ; +} + int delete_ref(const char *refname, const unsigned char *old_sha1, unsigned int flags) { struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; + if (is_pseudoref(refname)) + return delete_pseudoref(refname, old_sha1); + transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_delete(transaction, refname, old_sha1,
@@ -3970,17 +4045,25 @@ int update_ref(const char *msg, const char *refname, const unsigned char *new_sha1, const unsigned char *old_sha1, unsigned int flags, enum action_on_err onerr) { - struct ref_transaction *t; + struct ref_transaction *t = NULL;struct strbuf err =STRBUF_INIT ; +int ret =0 ; - t =ref_transaction_begin (&err); -if (!t || -ref_transaction_update (t, refname, new_sha1, old_sha1, - flags, msg, &err) || -ref_transaction_commit (t, &err)) { +if (is_pseudoref (refname) &&0 ) { + ret =write_pseudoref (refname, new_sha1, old_sha1, &err); + }else { + t =ref_transaction_begin (&err); +if (!t || +ref_transaction_update (t, refname, new_sha1, old_sha1, + 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" ; -ref_transaction_free (t);switch (onerr) {case UPDATE_REFS_MSG_ON_ERR :error (str, refname, err.buf);
@@ -3995,7 +4078,8 @@ int update_ref(const char *msg, const char *refname,return 1 ; }strbuf_release (&err); -ref_transaction_free (t); +if (t) +ref_transaction_free (t);return 0 ; }
Signature · 1 line
2.0.4.315.gad8727a-twtrsrc
Re: [PATCH 3/5] pseudorefs: create and use pseudoref update and delete functions
refs.c int update_ref(const char *msg, const char *refname, · line 4052
Quoted 1 line · David Turner
refs.c +1
-0+if (is_pseudoref (refname) &&0 ) {
Whoa, that's not right. Will fix that in the next re-roll.
PATCH v2 4/5 rebase: use update_ref
In reply to David TurnerInstead of manually writing a pseudoref (in one case) and shelling out to git update-ref (in another), use the update_ref function. This is much simpler.
--- bisect.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-)
bisect.c +8 -29
@@ -19,7 +19,6 @@ static struct object_id *current_bad_oid;static const char *argv_checkout[] = {"checkout" ,"-q" ,NULL ,"--" ,NULL };static const char *argv_show_branch[] = {"show-branch" ,NULL ,NULL }; -static const char *argv_update_ref[] = {"update-ref" ,"--no-deref" ,"BISECT_HEAD" ,NULL ,NULL };static const char *term_bad;static const char *term_good;
@@ -675,34 +674,16 @@ static int is_expected_rev(const struct object_id *oid)return res; } -static void mark_expected_rev (char *bisect_rev_hex) -{ -int len =strlen (bisect_rev_hex); -const char *filename =git_path ("BISECT_EXPECTED_REV" ); -int fd =open (filename,O_CREAT |O_TRUNC |O_WRONLY ,0600 ); - -if (fd <0 ) -die_errno ("could not create file '%s'" , filename); - - bisect_rev_hex[len] ='\n' ; -write_or_die (fd, bisect_rev_hex, len +1 ); - bisect_rev_hex[len] ='\0' ; - -if (close (fd) <0 ) -die ("closing file %s: %s" , filename,strerror (errno)); -} - -static int bisect_checkout (char *bisect_rev_hex,int no_checkout) +static int bisect_checkout (const unsigned char *bisect_rev,int no_checkout) { +char bisect_rev_hex[GIT_SHA1_HEXSZ +1 ]; -mark_expected_rev (bisect_rev_hex); +memcpy (bisect_rev_hex,sha1_to_hex (bisect_rev),GIT_SHA1_HEXSZ +1 ); +update_ref (NULL ,"BISECT_EXPECTED_REV" , bisect_rev,NULL ,0 ,UPDATE_REFS_DIE_ON_ERR ); argv_checkout[2 ] = bisect_rev_hex;if (no_checkout) { - argv_update_ref[3 ] = bisect_rev_hex; -if (run_command_v_opt (argv_update_ref,RUN_GIT_CMD )) -die ("update-ref --no-deref HEAD failed on %s" , - bisect_rev_hex); +update_ref (NULL ,"BISECT_HEAD" , bisect_rev,NULL ,0 ,UPDATE_REFS_DIE_ON_ERR ); }else {int res; res =run_command_v_opt (argv_checkout,RUN_GIT_CMD );
@@ -804,7 +785,7 @@ static void check_merge_bases(int no_checkout)handle_skipped_merge_base (mb); }else {printf ("Bisecting: a merge base must be tested\n" ); -exit (bisect_checkout (sha1_to_hex (mb), no_checkout)); +exit (bisect_checkout (mb, no_checkout)); } }
@@ -948,7 +929,6 @@ int bisect_next_all(const char *prefix, int no_checkout)struct commit_list *tried;int reaches =0 , all =0 , nr, steps;const unsigned char *bisect_rev; -char bisect_rev_hex[GIT_SHA1_HEXSZ +1 ];read_bisect_terms (&term_bad, &term_good);if (read_bisect_refs ())
@@ -986,11 +966,10 @@ int bisect_next_all(const char *prefix, int no_checkout) } bisect_rev = revs.commits->item->object.sha1; -memcpy (bisect_rev_hex,sha1_to_hex (bisect_rev),GIT_SHA1_HEXSZ +1 );if (!hashcmp (bisect_rev, current_bad_oid->hash)) {exit_if_skipped_commits (tried, current_bad_oid); -printf ("%s is the first %s commit\n" , bisect_rev_hex, +printf ("%s is the first %s commit\n" ,sha1_to_hex (bisect_rev), term_bad);show_diff_tree (prefix, revs.commits->item);/* This means the bisection process succeeded. */
@@ -1003,7 +982,7 @@ int bisect_next_all(const char *prefix, int no_checkout)"(roughly %d step%s)\n" , nr, (nr ==1 ?"" :"s" ), steps, (steps == 1 ? "" : "s")); -return bisect_checkout (bisect_rev_hex, no_checkout); +return bisect_checkout (bisect_rev, no_checkout); }static inline int log2i (int n)
Signature · 1 line
2.0.4.315.gad8727a-twtrsrc
PATCH v2 5/5 sequencer: replace write_cherry_pick_head with update_ref
In reply to David TurnerNow update_ref (via write_pseudoref) does almost exactly what write_cherry_pick_head did, so we can remove write_cherry_pick_head and just use update_ref.
--- sequencer.c | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-)
sequencer.c +4 -19
@@ -158,23 +158,6 @@ static void free_message(struct commit *commit, struct commit_message *msg)unuse_commit_buffer (commit, msg->message); } -static void write_cherry_pick_head (struct commit *commit,const char *pseudoref) -{ -const char *filename; -int fd; -struct strbuf buf =STRBUF_INIT ; - -strbuf_addf (&buf,"%s\n" ,sha1_to_hex (commit->object.sha1)); - - filename =git_path ("%s" , pseudoref); - fd =open (filename,O_WRONLY |O_CREAT ,0666 ); -if (fd <0 ) -die_errno (_ ("Could not open '%s' for writing" ), filename); -if (write_in_full (fd, buf.buf, buf.len) != buf.len ||close (fd)) -die_errno (_ ("Could not write to '%s'" ), filename); -strbuf_release (&buf); -} -static void print_advice (int show_hint,struct replay_opts *opts) {char *msg =getenv ("GIT_CHERRY_PICK_HELP" );
@@ -607,9 +590,11 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)* write it at all. */ if (opts->action ==REPLAY_PICK && !opts->no_commit && (res ==0 || res ==1 )) -write_cherry_pick_head (commit,"CHERRY_PICK_HEAD" ); +update_ref (NULL ,"CHERRY_PICK_HEAD" , commit->object.sha1,NULL , +REF_NODEREF ,UPDATE_REFS_DIE_ON_ERR );if (opts->action ==REPLAY_REVERT && ((opts->no_commit && res ==0 ) || res ==1 )) -write_cherry_pick_head (commit,"REVERT_HEAD" ); +update_ref (NULL ,"REVERT_HEAD" , commit->object.sha1,NULL , +REF_NODEREF ,UPDATE_REFS_DIE_ON_ERR );if (res) { error(opts->action == REPLAY_REVERT
Signature · 1 line
2.0.4.315.gad8727a-twtrsrc
Quoted 5 lines · David Turner
This version of the pseudorefs patch series is much simpler. Instead of forbidding
update_refanddelete_reffrom updating pseudorefs, these functions now just special-case pseudorefs. So we can useupdate_refto write pseudorefs in a rebase and sequencer, and we don't need to rewrite so much code.
The resulting update_ref/delete_ref look quite straight-forward, too. Thanks.
Quoted 2 lines
In addition, I made typo fixes suggested by Eric Sunshine and Philip Oakley.
Re: [PATCH 1/5] refs: Introduce pseudoref and per-worktree ref concepts
In reply to David TurnerQuoted 3 lines · David Turner
refs: Introduce pseudoref and per-worktree ref concepts
Add glossary entries for both concepts.
Based upon the above, I thought this was going to be a documentation-only patch and was mildly surprised to find that it also changed code. Perhaps:
Describe these concepts in the glossary and introduce is_per_worktree_ref() to distinguish such files.
or something. Of course the "and" in there suggests that this might be better off split into two patches...
More below.
Quoted 14 lines
Pseudorefs and per-worktree refs do not yet have special handling, because the files refs backend already handles them correctly. Later, we will make the LMDB backend call out to the files backend to handle per-worktree refs.
Signed-off-by David Turner <[email protected]>---
Documentation/glossary-content.txt +0
-0@@ -411,6 +411,27 @@ exclude;; core Git. Porcelains expose more of a <<def_SCM,SCM>> interface than the <<def_plumbing,plumbing>>.
Documentation/glossary-content.txt exclude;; · line 422
Quoted 10 lines
Documentation/glossary-content.txt +9
-0+[[def_per_worktree_ref]]per-worktree ref:: + Refs that are per-<<def_worktree,worktree>>, rather than + global. This is presently only <<def_HEAD,HEAD>>, but might + later include other unusual refs. + +[[def_pseudoref]]pseudoref:: + Pseudorefs are a class of files under `$GIT_DIR` which behave + like refs for the purposes of rev-parse, but which are treated + specially by git. Psuedorefs both have names are all-caps,
s/names/& that/
Documentation/glossary-content.txt exclude;; · line 426
Quoted 4 lines
Documentation/glossary-content.txt +4
-0+ and always start with a line consisting of a + <<def_sha1,SHA-1>> followed by whitespace. So, HEAD is not a + pseudoref, because it is sometimes a symbolic ref. They might + optionally some additional data. `MERGE_HEAD` and
s/optionally/& contain/
Quoted 31 lines
Documentation/glossary-content.txt +8
-0+ `CHERRY_PICK_HEAD` are examples. Unlike + <<def_per_worktree_ref,per-worktree refs>>, these files cannot + be symbolic refs, and never have reflogs. They also cannot be + updated through the normal ref update machinery. Instead, + they are updated by directly writing to the files. However, + they can be read as if they were refs, so `git rev-parse + MERGE_HEAD` will work. + [[def_pull]]pull:: Pulling a <<def_branch,branch>> means to <<def_fetch,fetch>> it and <<def_merge,merge>> it. See also linkgit:git-pull[1].refs.c +12
-0@@ -2848,6 +2848,29 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)return 0 ; } +int is_per_worktree_ref (const char *refname) +{ +return !strcmp (refname,"HEAD" ); +} + +static int is_pseudoref (const char *refname) +{ +const char *c; + +if (strchr (refname,'/' )) +return 0 ; +
refs.c static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err) · line 2872
Quoted 10 lines
refs.c +10
-0+if (is_per_worktree_ref (refname)) +return 0 ; + +for (c = refname; *c; ++c) { +if (!isupper (*c) && *c !='-' && *c !='_' ) +return 0 ; + } + +return 1 ; +}
This static function doesn't seem to have any callers, thus seems out of place in this patch.
Quoted 4 lines
refs.c +1
-0+int delete_ref (const char *refname,const unsigned char *old_sha1,unsigned int flags) {
Re: [PATCH 4/5] rebase: use update_ref
In reply to David TurnerQuoted 8 lines · David Turner
Instead of manually writing a pseudoref (in one case) and shelling out to git update-ref (in another), use the
update_reffunction. This is much simpler.Signed-off-by David Turner <[email protected]>--- bisect.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-)
Mistitled? I can do s/rebase/bisect/ at my end if that is all needed.
Quoted 92 lines
bisect.c +8
-29@@ -19,7 +19,6 @@ static struct object_id *current_bad_oid;static const char *argv_checkout[] = {"checkout" ,"-q" ,NULL ,"--" ,NULL };static const char *argv_show_branch[] = {"show-branch" ,NULL ,NULL }; -static const char *argv_update_ref[] = {"update-ref" ,"--no-deref" ,"BISECT_HEAD" ,NULL ,NULL };static const char *term_bad;static const char *term_good;@@ -675,34 +674,16 @@ static int is_expected_rev(const struct object_id *oid)return res; } -static void mark_expected_rev (char *bisect_rev_hex) -{ -int len =strlen (bisect_rev_hex); -const char *filename =git_path ("BISECT_EXPECTED_REV" ); -int fd =open (filename,O_CREAT |O_TRUNC |O_WRONLY ,0600 ); - -if (fd <0 ) -die_errno ("could not create file '%s'" , filename); - - bisect_rev_hex[len] ='\n' ; -write_or_die (fd, bisect_rev_hex, len +1 ); - bisect_rev_hex[len] ='\0' ; - -if (close (fd) <0 ) -die ("closing file %s: %s" , filename,strerror (errno)); -} - -static int bisect_checkout (char *bisect_rev_hex,int no_checkout) +static int bisect_checkout (const unsigned char *bisect_rev,int no_checkout) { +char bisect_rev_hex[GIT_SHA1_HEXSZ +1 ]; -mark_expected_rev (bisect_rev_hex); +memcpy (bisect_rev_hex,sha1_to_hex (bisect_rev),GIT_SHA1_HEXSZ +1 ); +update_ref (NULL ,"BISECT_EXPECTED_REV" , bisect_rev,NULL ,0 ,UPDATE_REFS_DIE_ON_ERR ); argv_checkout[2 ] = bisect_rev_hex;if (no_checkout) { - argv_update_ref[3 ] = bisect_rev_hex; -if (run_command_v_opt (argv_update_ref,RUN_GIT_CMD )) -die ("update-ref --no-deref HEAD failed on %s" , - bisect_rev_hex); +update_ref (NULL ,"BISECT_HEAD" , bisect_rev,NULL ,0 ,UPDATE_REFS_DIE_ON_ERR ); }else {int res; res =run_command_v_opt (argv_checkout,RUN_GIT_CMD );@@ -804,7 +785,7 @@ static void check_merge_bases(int no_checkout)handle_skipped_merge_base (mb); }else {printf ("Bisecting: a merge base must be tested\n" ); -exit (bisect_checkout (sha1_to_hex (mb), no_checkout)); +exit (bisect_checkout (mb, no_checkout)); } }@@ -948,7 +929,6 @@ int bisect_next_all(const char *prefix, int no_checkout)struct commit_list *tried;int reaches =0 , all =0 , nr, steps;const unsigned char *bisect_rev; -char bisect_rev_hex[GIT_SHA1_HEXSZ +1 ];read_bisect_terms (&term_bad, &term_good);if (read_bisect_refs ())@@ -986,11 +966,10 @@ int bisect_next_all(const char *prefix, int no_checkout) } bisect_rev = revs.commits->item->object.sha1; -memcpy (bisect_rev_hex,sha1_to_hex (bisect_rev),GIT_SHA1_HEXSZ +1 );if (!hashcmp (bisect_rev, current_bad_oid->hash)) {exit_if_skipped_commits (tried, current_bad_oid); -printf ("%s is the first %s commit\n" , bisect_rev_hex, +printf ("%s is the first %s commit\n" ,sha1_to_hex (bisect_rev), term_bad);show_diff_tree (prefix, revs.commits->item);/* This means the bisection process succeeded. */ @@ -1003,7 +982,7 @@ int bisect_next_all(const char *prefix, int no_checkout)"(roughly %d step%s)\n" , nr, (nr ==1 ?"" :"s" ), steps, (steps == 1 ? "" : "s")); -return bisect_checkout (bisect_rev_hex, no_checkout); +return bisect_checkout (bisect_rev, no_checkout); }static inline int log2i (int n)
Re: [PATCH 4/5] rebase: use update_ref
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · David Turner
Instead of manually writing a pseudoref (in one case) and shelling out to git update-ref (in another), use the
update_reffunction. This is much simpler.
Quoted 7 lines
Quoted 4 lines
Signed-off-by David Turner <[email protected]>--- bisect.c | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-)Mistitled? I can do s/rebase/bisect/ at my end if that is all needed.
Apparently, yes. Thanks.