From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Nieder Subject: [PATCH 09/20] fast-import.c: change update_branch to use ref transactions Date: Tue, 26 Aug 2014 17:32:26 -0700 Message-ID: <20140827003225.GJ20185@google.com> References: <20140820231723.GF20185@google.com> <20140826000354.GW20185@google.com> <20140826221448.GY20185@google.com> <20140827002804.GA20185@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Ronnie Sahlberg , "git@vger.kernel.org" , Michael Haggerty To: Junio C Hamano X-From: git-owner@vger.kernel.org Wed Aug 27 02:32:36 2014 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 1XMRAB-0006RU-3E for gcvg-git-2@plane.gmane.org; Wed, 27 Aug 2014 02:32:35 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756257AbaH0Acb (ORCPT ); Tue, 26 Aug 2014 20:32:31 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:49292 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755066AbaH0Aca (ORCPT ); Tue, 26 Aug 2014 20:32:30 -0400 Received: by mail-pa0-f46.google.com with SMTP id lj1so24347897pab.5 for ; Tue, 26 Aug 2014 17:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=ngNd6J/Hde5Hk2bOs3s3PqWEBRf9pIBbkCyW9HbW9+U=; b=c+QPlpUkASxBCXKdglMLCMvo6UC3QpwzThz48xK2E2wo66bpIP47au8/XZ2nXNBzx1 U6LBuJxC3OgHbz61IeHUPWyiweod72nNa+rxUQt/+XV1qIUVBvpHL8010gYfoDtRSpkg lmNk5PgNBIT0MbMU4irUAOvU1PP5rnvImJN/W6vuW4Jpn2qRfnRuv3Ojz3dBwY/taKGD VKmacW/8jCFEV/qEOBA9GmS8UD/QS1v27IMAiJ4TZgkHeWSk9Y8kpAI3QDyjlb8+ru3z RQ/2hyUtuj/bb19lafJD+thCFGCLUwxB2H8u7Hb1jUk1AFT6Xak2Pd5/IJMsvwGsoZR1 qmRA== X-Received: by 10.68.194.66 with SMTP id hu2mr14416994pbc.19.1409099550354; Tue, 26 Aug 2014 17:32:30 -0700 (PDT) Received: from google.com ([2620:0:1000:5b00:4ba:9bd4:148:77e4]) by mx.google.com with ESMTPSA id xj9sm15162943pab.40.2014.08.26.17.32.28 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 26 Aug 2014 17:32:29 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20140827002804.GA20185@google.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: From: Ronnie Sahlberg Date: Wed, 16 Apr 2014 16:21:13 -0700 Change update_branch() to use ref transactions for updates. Signed-off-by: Ronnie Sahlberg Signed-off-by: Jonathan Nieder --- fast-import.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/fast-import.c b/fast-import.c index 6707a66..79160d5 100644 --- a/fast-import.c +++ b/fast-import.c @@ -1679,8 +1679,9 @@ found_entry: static int update_branch(struct branch *b) { static const char *msg = "fast-import"; - struct ref_lock *lock; + struct ref_transaction *transaction; unsigned char old_sha1[20]; + struct strbuf err = STRBUF_INIT; if (read_ref(b->name, old_sha1)) hashclr(old_sha1); @@ -1689,29 +1690,33 @@ static int update_branch(struct branch *b) 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); if (!force_update && !is_null_sha1(old_sha1)) { struct commit *old_cmit, *new_cmit; old_cmit = lookup_commit_reference_gently(old_sha1, 0); new_cmit = lookup_commit_reference_gently(b->sha1, 0); - if (!old_cmit || !new_cmit) { - unlock_ref(lock); + if (!old_cmit || !new_cmit) return error("Branch %s is missing commits.", b->name); - } if (!in_merge_bases(old_cmit, new_cmit)) { - unlock_ref(lock); warning("Not updating %s" " (new tip %s does not contain %s)", b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1)); return -1; } } - if (write_ref_sha1(lock, b->sha1, msg) < 0) - return error("Unable to update %s", b->name); + transaction = ref_transaction_begin(&err); + if (!transaction || + ref_transaction_update(transaction, b->name, b->sha1, old_sha1, + 0, 1, &err) || + ref_transaction_commit(transaction, msg, &err)) { + ref_transaction_free(transaction); + error("%s", err.buf); + strbuf_release(&err); + return -1; + } + ref_transaction_free(transaction); + strbuf_release(&err); return 0; } -- 2.1.0.rc2.206.gedb03e5