From mboxrd@z Thu Jan 1 00:00:00 1970 From: Felipe Contreras Subject: [PATCH v6 08/10] fast-import: add support to delete refs Date: Mon, 11 Nov 2013 16:55:00 -0600 Message-ID: <1384210507-26561-4-git-send-email-felipe.contreras@gmail.com> References: <1384210507-26561-1-git-send-email-felipe.contreras@gmail.com> Cc: Sverre Rabbelier , Richard Hansen , Felipe Contreras To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Nov 12 00:02:19 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vg0Uq-0006DV-D0 for gcvg-git-2@plane.gmane.org; Tue, 12 Nov 2013 00:02:16 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753448Ab3KKXCL (ORCPT ); Mon, 11 Nov 2013 18:02:11 -0500 Received: from mail-ob0-f171.google.com ([209.85.214.171]:51459 "EHLO mail-ob0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753353Ab3KKXCG (ORCPT ); Mon, 11 Nov 2013 18:02:06 -0500 Received: by mail-ob0-f171.google.com with SMTP id gq1so5056648obb.2 for ; Mon, 11 Nov 2013 15:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ryf9BefKMzvXiPY1HaMZsrMeRBIFG7IWdZJdgn7W9Dg=; b=NomFdKNKay6DPdkZ2fIqfldzmQhyTr86W9qCAKqHU7V32GMET8Ow1aAW3eId9zObzV oAdqiPi2OE/hNR24NPr758ICUsozRuRV2kY+3lF6OOIzqfR9V6PUaTCwrYEeB1O9/Xxj fZSWdEQ6nntGgXh1DC0TxjW3koPfBxSFD7TqBlNUXLDBhAElZVwTWFSrNHp9l3e3HDD3 R4ISLpl5gShf+kAJJIE0q/Uq0IXv3FkFeqbXOp0OU3C45iuPMliTUoVoJGJ1kOOpvjbr 0zvUg712Zivw1WAfmXoCd5POb7Q6PfzWMeka06MApbFNyqHD14iwEo3LwmEFBTV5BVVW OEhQ== X-Received: by 10.60.146.210 with SMTP id te18mr5130382oeb.20.1384210926222; Mon, 11 Nov 2013 15:02:06 -0800 (PST) Received: from localhost (187-162-140-241.static.axtel.net. [187.162.140.241]) by mx.google.com with ESMTPSA id m7sm29280184obo.7.2013.11.11.15.02.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Nov 2013 15:02:05 -0800 (PST) X-Mailer: git-send-email 1.8.4.2+fc1 In-Reply-To: <1384210507-26561-1-git-send-email-felipe.contreras@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Signed-off-by: Felipe Contreras --- Documentation/git-fast-import.txt | 3 +++ fast-import.c | 13 ++++++++++--- t/t9300-fast-import.sh | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index 73f9806..2ffae42 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -483,6 +483,9 @@ Marks must be declared (via `mark`) before they can be used. * Any valid Git SHA-1 expression that resolves to a commit. See ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details. +* The special null SHA-1 (40 zeros) specifies that the branch is to be + removed. + The special case of restarting an incremental import from the current branch value should be written as: ---- diff --git a/fast-import.c b/fast-import.c index f4d9969..fdce0b7 100644 --- a/fast-import.c +++ b/fast-import.c @@ -248,6 +248,7 @@ struct branch { uintmax_t last_commit; uintmax_t num_notes; unsigned active : 1; + unsigned delete : 1; unsigned pack_id : PACK_ID_BITS; unsigned char sha1[20]; }; @@ -1690,10 +1691,13 @@ 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); + if (is_null_sha1(b->sha1)) { + if (b->delete) + delete_ref(b->name, old_sha1, 0); + return 0; + } lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL); if (!lock) return error("Unable to lock %s", b->name); @@ -2620,8 +2624,11 @@ static int parse_from(struct branch *b) free(buf); } else parse_from_existing(b); - } else if (!get_sha1(from, b->sha1)) + } else if (!get_sha1(from, b->sha1)) { parse_from_existing(b); + if (is_null_sha1(b->sha1)) + b->delete = 1; + } else die("Invalid ref name or SHA1 expression: %s", from); diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 27263df..5fc9ef2 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' ' test_cmp expect actual ' +test_expect_success 'T: delete branch' ' + git branch to-delete && + git fast-import <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + EOF + test_must_fail git rev-parse --verify refs/heads/to-delete +' + +test_expect_success 'T: empty reset doesnt delete branch' ' + git branch not-to-delete && + git fast-import <<-EOF && + reset refs/heads/not-to-delete + EOF + git show-ref && + git rev-parse --verify refs/heads/not-to-delete +' + test_done -- 1.8.4.2+fc1