From: Felipe Contreras Subject: [PATCH v6 08/10] fast-import: add support to delete refs Date: Tue, 12 Nov 2013 14:57:04 -0600 Message-ID: <1384289830-5471-12-git-send-email-felipe.contreras@gmail.com> References: <1384289830-5471-1-git-send-email-felipe.contreras@gmail.com> Cc: Richard Hansen , Felipe Contreras To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Nov 12 22:05:44 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 1VgL9U-0000cy-Uk for gcvg-git-2@plane.gmane.org; Tue, 12 Nov 2013 22:05:37 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932297Ab3KLVEq (ORCPT ); Tue, 12 Nov 2013 16:04:46 -0500 Received: from mail-ob0-f172.google.com ([209.85.214.172]:35685 "EHLO mail-ob0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932251Ab3KLVEf (ORCPT ); Tue, 12 Nov 2013 16:04:35 -0500 Received: by mail-ob0-f172.google.com with SMTP id wm4so6651217obc.31 for ; Tue, 12 Nov 2013 13:04:35 -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=Lvbcl4odOkGg7bH8ZXzndGD13zlJvTHYMLK3dMmUnDYBiI1Cw+Q3JP5LruO2XaD85H Anh5oZ5eCHpPjm6CmzKOtUI1caaneuM2bSw55GCjvhm8whjHJCcPi2FLrVTBbW7V5XEM Qh7zd36JBqat9Uf4pUOoERtw9eIDSzD2OEnDFzMceXitFl2/eG4S8BjOv1/6PYobm0YC LvHvLsot4mYGsUB3rK/piyn3ZgWmHBH7gM47mJmr47wcBsin6CUk/1qVPxETOGKIwzvR 3an0DkxWB11P55vxJo4/hQoIEtrsW5cHNWJwcGyBiWLQgKxzdXT3on+cFtu/dCh2UOb4 qTNw== X-Received: by 10.182.129.106 with SMTP id nv10mr3528835obb.85.1384290275322; Tue, 12 Nov 2013 13:04:35 -0800 (PST) Received: from localhost (187-162-140-241.static.axtel.net. [187.162.140.241]) by mx.google.com with ESMTPSA id qe2sm35404967obc.1.2013.11.12.13.04.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Nov 2013 13:04:34 -0800 (PST) X-Mailer: git-send-email 1.8.4.2+fc1 In-Reply-To: <1384289830-5471-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