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

[PATCH v0] fast-import: Add drop command

From
Vitor Antunes <vitor.hda@gmail.com>
Date
Sep 24, 2011, 15:27 UTC
Message-ID
<1316878065-11782-2-git-send-email-vitor.hda@gmail.com>
In-Reply-To
<1316878065-11782-1-git-send-email-vitor.hda@gmail.com>

The drop command deletes the given branch reference, allowing fast-import to actively ignore it in the final checks.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
 fast-import.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 742e7da..906bbf4 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -743,6 +743,29 @@ static struct branch *new_branch(const char *name)
 	return b;
 }
 
+static void release_tree_entry(struct tree_entry *e);
+static void drop_branch(const char *name)
+{
+	unsigned int hc = hc_str(name, strlen(name)) % branch_table_sz;
+	struct branch *b_prev = NULL, *b = NULL;
+	struct ref_lock *lock;
+	unsigned char old_sha1[20];
+
+	for (b = branch_table[hc]; b; b = b->table_next_branch) {
+		if (!strcmp(name, b->name)) {
+			release_tree_entry(&b->branch_tree);
+			if (b_prev)
+				b_prev->table_next_branch = b->table_next_branch;
+			branch_table[hc] = NULL;
+			branch_count--;
+		}
+		b_prev = b;
+	}
+
+	if (!read_ref(name, old_sha1))
+		delete_ref(name, old_sha1, 0)
+}
+
 static unsigned int hc_entries(unsigned int cnt)
 {
 	cnt = cnt & 7 ? (cnt / 8) + 1 : cnt / 8;
@@ -776,7 +799,6 @@ static struct tree_content *new_tree_content(unsigned int cnt)
 	return t;
 }
 
-static void release_tree_entry(struct tree_entry *e);
 static void release_tree_content(struct tree_content *t)
 {
 	struct avail_tree_content *f = (struct avail_tree_content*)t;
@@ -2793,6 +2815,15 @@ static void parse_reset_branch(void)
 		unread_command_buf = 1;
 }
 
+static void parse_drop_branch(void)
+{
+	char *sp;
+
+	/* Obtain the branch name from the rest of our command */
+	sp = strchr(command_buf.buf, ' ') + 1;
+	drop_branch(sp);
+}
+
 static void cat_blob_write(const char *buf, unsigned long size)
 {
 	if (write_in_full(cat_blob_fd, buf, size) != size)
@@ -3332,6 +3363,8 @@ int main(int argc, const char **argv)
 			parse_new_tag();
 		else if (!prefixcmp(command_buf.buf, "reset "))
 			parse_reset_branch();
+		else if (!prefixcmp(command_buf.buf, "drop "))
+			parse_drop_branch();
 		else if (!strcmp("checkpoint", command_buf.buf))
 			parse_checkpoint();
 		else if (!strcmp("done", command_buf.buf))
-- 
1.7.7.rc2.11.g4aecf.dirty
Previous: Vitor AntunesNext: Jonathan Nieder
Message 2 of 15 in “fast-import: Add drop command”
  1. fast-import: Add drop commandVitor Antunes, Sep 24, 2011
  2. fast-import: Add drop commandVitor Antunes, Sep 24, 2011
  3. Jonathan NiederSep 24, 2011
  4. Dmitry IvankovSep 24, 2011
  5. Vitor AntunesSep 27, 2011
  6. Vitor AntunesOct 24, 2011
  7. Sverre RabbelierOct 24, 2011
  8. Vitor AntunesOct 25, 2011
  9. Sverre RabbelierOct 27, 2011
  10. Vitor AntunesOct 27, 2011
  11. Sverre RabbelierOct 27, 2011
  12. Vitor AntunesNov 9, 2011
  13. Sverre RabbelierNov 9, 2011
  14. Vitor AntunesNov 9, 2011
  15. Vitor AntunesSep 24, 2011

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.