git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/9] am/rebase: update pseudorefs by writing files

From
David Turner <dturner@twopensource.com>
Date
Jul 24, 2015, 04:45 UTC
Message-ID
<1437713129-19373-8-git-send-email-dturner@twopensource.com>
In-Reply-To
<1437713129-19373-1-git-send-email-dturner@twopensource.com>

git update-ref can no longer be used to update pseudorefs, so in git-am and git-rebase, we just directly edit the files.

Signed-off-by: David Turner <dturner@twopensource.com>
---
 builtin/am.c               | 6 +++---
 contrib/examples/git-am.sh | 4 ++--
 git-rebase--interactive.sh | 2 +-
 git-rebase.sh              | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/builtin/am.c b/builtin/am.c
index 3f0fc75..ff3eeee 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1049,12 +1049,12 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
 	if (!get_sha1("HEAD", curr_head)) {
 		write_file(am_path(state, "abort-safety"), 1, "%s", sha1_to_hex(curr_head));
 		if (!state->rebasing)
-			update_ref("am", "ORIG_HEAD", curr_head, NULL, 0,
-					UPDATE_REFS_DIE_ON_ERR);
+			write_pseudoref("ORIG_HEAD", curr_head, NULL);
 	} else {
 		write_file(am_path(state, "abort-safety"), 1, "%s", "");
 		if (!state->rebasing)
-			delete_ref("ORIG_HEAD", NULL, 0);
+			if (unlink(git_path("ORIG_HEAD")) && errno != ENOENT)
+				die("failed to unlink ORIG_HEAD");
 	}
 
 	/*
diff --git a/contrib/examples/git-am.sh b/contrib/examples/git-am.sh
index a3d0c84..a01a06e 100755
--- a/contrib/examples/git-am.sh
+++ b/contrib/examples/git-am.sh
@@ -614,9 +614,9 @@ Use \"git am --abort\" to remove it.")"
 		: >"$dotest/applying"
 		if test -n "$HAS_HEAD"
 		then
-			git update-ref ORIG_HEAD HEAD
+			git rev-parse HEAD >"$GIT_DIR/ORIG_HEAD"
 		else
-			git update-ref -d ORIG_HEAD >/dev/null 2>&1
+			rm -f "$GIT_DIR/ORIG_HEAD"
 		fi
 	fi
 fi
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f01637b..ae116a6 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -948,7 +948,7 @@ warn_lines () {
 checkout_onto () {
 	GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
 	output git checkout $onto || die_abort "could not detach HEAD"
-	git update-ref ORIG_HEAD $orig_head
+	echo $orig_head >"$GIT_DIR/ORIG_HEAD"
 }
 
 get_missing_commit_check_level () {
diff --git a/git-rebase.sh b/git-rebase.sh
index 1757404..23e2e64 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -611,7 +611,7 @@ say "$(gettext "First, rewinding head to replay your work on top of it...")"
 
 GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \
 	git checkout -q "$onto^0" || die "could not detach HEAD"
-git update-ref ORIG_HEAD $orig_head
+echo $orig_head >"$GIT_DIR/ORIG_HEAD"
 
 # If the $onto is a proper descendant of the tip of the branch, then
 # we just fast-forwarded.
-- 
2.0.4.315.gad8727a-twtrsrc
Previous: Junio C HamanoNext: David Turner
Message 17 of 20 in “Pseudorefs”
  1. 0/9 PseudorefsDavid Turner, Jul 24, 2015
  2. 1/9 refs: Introduce pseudoref and per-worktree ref conceptsDavid Turner, Jul 24, 2015
  3. Eric SunshineJul 24, 2015
  4. Junio C HamanoJul 24, 2015
  5. David TurnerJul 24, 2015
  6. Junio C HamanoJul 24, 2015
  7. Philip OakleyJul 24, 2015
  8. David TurnerJul 24, 2015
  9. 2/9 notes: replace pseudorefs with real refsDavid Turner, Jul 24, 2015
  10. 3/9 bisect: do not use update-ref for BISECT_HEADDavid Turner, Jul 24, 2015
  11. 4/9 tests: treat FETCH_HEAD as a pseudorefDavid Turner, Jul 24, 2015
  12. 5/9 tests: use --create-reflog option to git update-refDavid Turner, Jul 24, 2015
  13. 6/9 pseudorefs: create and use pseudoref update and delete functionsDavid Turner, Jul 24, 2015
  14. Junio C HamanoJul 24, 2015
  15. David TurnerJul 24, 2015
  16. Junio C HamanoJul 24, 2015
  17. 7/9 am/rebase: update pseudorefs by writing filesDavid Turner, Jul 24, 2015
  18. 8/9 rebase: use write_pseudorefDavid Turner, Jul 24, 2015
  19. 9/9 refs: forbid pseudoref updates through ref update APIDavid Turner, Jul 24, 2015
  20. Michael HaggertyAug 2, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.