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

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

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 16, 2008, 04:12 UTC
Message-ID
<20080316041240.GH8410@spearce.org>
In-Reply-To
<7AFA021C-062D-4FC2-85EB-1DD6C054BEA4@orakel.ntnu.no>
Eyvind Bernhardsen <eyvind-git@orakel.ntnu.no> wrote:
> 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 :)

I think this is a slightly better patch, as it avoids creating a lock file around the ref if we aren't going to actually alter it.

At present fast-import does not allow an application to delete a branch that existed when fast-import started, but if the branch was strictly transient within the fast-import process (like the cvs2svn TAG.FIXUP) then there is no problem.

Is this patch acceptable?  Note it is from you, I carried in your
commit message, SBO, etc.
 
--8>--
From: Eyvind Bernhardsen <eyvind-git@orakel.ntnu.no>
Subject: [PATCH] fast-import: allow "reset" without "from" to delete temporary branch

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>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 fast-import.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 655913d..73e5439 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1516,6 +1516,8 @@ static int update_branch(struct branch *b)
 	struct ref_lock *lock;
 	unsigned char old_sha1[20];
 
+	if (is_null_sha1(b->sha1))
+		return 0;
 	if (read_ref(b->name, old_sha1))
 		hashclr(old_sha1);
 	lock = lock_any_ref_for_update(b->name, old_sha1, 0);
-- 
1.5.4.4.640.g8ae62

-- 
Shawn.
Previous: Eyvind BernhardsenNext: Eyvind Bernhardsen
Message 2 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.