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

[PATCH v3 05/13] remote rm: handle symbolic refs correctly

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jun 18, 2016, 04:15 UTC
Message-ID
<e039bde30ed4481c8ac4266807ec3e660fadaeb5.1466222921.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1466222921.git.mhagger@alum.mit.edu>

In the modern world of reference backends, it is not OK to delete a symref by unlink()ing the file directly. This must be done via the refs API.

We do so by adding the symref to the list of references to delete along with the non-symbolic references, then calling delete_refs() with the new flags option set to REF_NODEREF.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/remote.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/builtin/remote.c b/builtin/remote.c
index 1bbf9b4..c4b4d67 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -539,10 +539,6 @@ static int add_branch_for_removal(const char *refname,
 		return 0;
 	}
 
-	/* make sure that symrefs are deleted */
-	if (flags & REF_ISSYMREF)
-		return unlink(git_path("%s", refname));
-
 	string_list_append(branches->branches, refname);
 
 	return 0;
@@ -788,7 +784,7 @@ static int rm(int argc, const char **argv)
 	strbuf_release(&buf);
 
 	if (!result)
-		result = delete_refs(&branches, 0);
+		result = delete_refs(&branches, REF_NODEREF);
 	string_list_clear(&branches, 0);
 
 	if (skipped.nr) {
-- 
2.8.1
Previous: Michael HaggertyNext: Michael Haggerty
Message 8 of 14 in “Reference iterators”
  1. 00/13 Reference iteratorsMichael Haggerty, Jun 18, 2016
  2. 01/13 refs: remove unnecessary "extern" keywordsMichael Haggerty, Jun 18, 2016
  3. 02/13 do_for_each_ref(): move docstring to the header fileMichael Haggerty, Jun 18, 2016
  4. 04/13 delete_refs(): add a flags argumentMichael Haggerty, Jun 18, 2016
  5. 06/13 get_ref_cache(): only create an instance if there is a submoduleMichael Haggerty, Jun 18, 2016
  6. 07/13 entry_resolves_to_object(): rename function from ref_resolves_to_object()Michael Haggerty, Jun 18, 2016
  7. 08/13 ref_resolves_to_object(): new functionMichael Haggerty, Jun 18, 2016
  8. 05/13 remote rm: handle symbolic refs correctlyMichael Haggerty, Jun 18, 2016
  9. 09/13 refs: introduce an iterator interfaceMichael Haggerty, Jun 18, 2016
  10. 10/13 do_for_each_ref(): reimplement using reference iterationMichael Haggerty, Jun 18, 2016
  11. 13/13 for_each_reflog(): reimplement using iteratorsMichael Haggerty, Jun 18, 2016
  12. 03/13 refs: use name "prefix" consistentlyMichael Haggerty, Jun 18, 2016
  13. 11/13 for_each_reflog(): don't abort for bad referencesMichael Haggerty, Jun 18, 2016
  14. 12/13 dir_iterator: new API for iterating over a directory treeMichael Haggerty, Jun 18, 2016

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.