git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vitor Antunes <vitor.hda@gmail.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	Vitor Antunes <vitor.hda@gmail.com>
Subject: [PATCH v0] fast-import: Add drop command
Date: Sat, 24 Sep 2011 16:27:45 +0100	[thread overview]
Message-ID: <1316878065-11782-2-git-send-email-vitor.hda@gmail.com> (raw)
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

  reply	other threads:[~2011-09-24 15:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-24 15:27 [PATCH v0] fast-import: Add drop command Vitor Antunes
2011-09-24 15:27 ` Vitor Antunes [this message]
2011-09-24 19:37   ` Jonathan Nieder
2011-09-24 21:19     ` Dmitry Ivankov
2011-09-27  8:57       ` Vitor Antunes
2011-10-24 16:37         ` Vitor Antunes
2011-10-24 18:01           ` Sverre Rabbelier
2011-10-25  9:56             ` Vitor Antunes
2011-10-27 11:06               ` Sverre Rabbelier
2011-10-27 11:22                 ` Vitor Antunes
2011-10-27 14:36                   ` Sverre Rabbelier
2011-11-09  0:24                     ` Vitor Antunes
2011-11-09  0:27                       ` Sverre Rabbelier
2011-11-09 11:29                         ` Vitor Antunes
2011-09-24 21:35     ` Vitor Antunes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1316878065-11782-2-git-send-email-vitor.hda@gmail.com \
    --to=vitor.hda@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).