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

[PATCH/RFC] fast-import: allow "reset" without "from" to delete a branch

From
Eyvind Bernhardsen <eyvind-git@orakel.ntnu.no>
Date
Mar 15, 2008, 14:59 UTC
Message-ID
<7AFA021C-062D-4FC2-85EB-1DD6C054BEA4@orakel.ntnu.no>

Resetting a branch without "from" and not making any further commits to it currently causes fast-import to fail with an error message.

This patch prevents the error, allowing "reset" to be used to delete a branch.

Signed-off-by: Eyvind Bernhardsen <eyvind-git@orakel.ntnu.no>
---
Since commit c3b0dec ("Be more careful about updating refs"), git fast- 
import has given the following error message on every import from  
cvs2svn:
	error: Trying to write ref refs/heads/TAG.FIXUP with nonexistant  
object 0000000000000000000000000000000000000000
	error: Unable to update refs/heads/TAG.FIXUP

The imported repository is fine, but the error message finally bugged me enough to figure out what was going on, and the explanation is simple. If a branch is reset in fast-import, and no further commits are made on that branch, the final dump_branches() call in fast- import.c fails.

cvs2svn creates a TAG.FIXUP branch for every tag and then resets it after the tag has been set. The intent is that TAG.FIXUP should be deleted, and this patch makes that work without error (the branch is actually deleted even without this patch).

It's a small change and the test suite passes, but I'm not sure if using reset to delete a branch is desired behaviour, so I would appreciate it if someone who actually knows what they are doing could take a look at it :)

  fast-import.c |    5 +++--
  1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 655913d..989ba94 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1539,8 +1539,9 @@ static int update_branch(struct branch *b)
  			return -1;
  		}
  	}
-	if (write_ref_sha1(lock, b->sha1, msg) < 0)
-		return error("Unable to update %s", b->name);
+	if (!is_null_sha1(b->sha1))
+		if (write_ref_sha1(lock, b->sha1, msg) < 0)
+			return error("Unable to update %s", b->name);
  	return 0;
  }
-- 
1.5.4.4.555.ga98c.dirty
Next: Shawn O. Pearce
Message 1 of 4 in “fast-import: allow "reset" without "from" to delete a branch”
  1. fast-import: allow "reset" without "from" to delete a branchEyvind Bernhardsen, Mar 15, 2008
  2. Shawn O. PearceMar 16, 2008
  3. fast-import: Allow "reset" to delete a new branch without errorEyvind Bernhardsen, Mar 16, 2008
  4. Junio C HamanoMar 16, 2008

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.