From patchwork Mon Oct 15 11:14:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Diamand X-Patchwork-Id: 10641557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D8B2925 for ; Mon, 15 Oct 2018 11:14:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E8A629235 for ; Mon, 15 Oct 2018 11:14:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12A3529477; Mon, 15 Oct 2018 11:14:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05F4E29235 for ; Mon, 15 Oct 2018 11:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726526AbeJOS7N (ORCPT ); Mon, 15 Oct 2018 14:59:13 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37659 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726319AbeJOS7N (ORCPT ); Mon, 15 Oct 2018 14:59:13 -0400 Received: by mail-pf1-f193.google.com with SMTP id j23-v6so9513484pfi.4 for ; Mon, 15 Oct 2018 04:14:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diamand.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ffdq98kySWVmKhM7VB6+p5/IbsOlzT1X5C/f8NIg+6o=; b=MAGo/h+VA6qTNT1ibKFaGE2nrHAgz1YTOWA8pJdWNUfv8jvmqnaKPjvV5ce2gZYQFZ WuCCCnpQi56EszVqwDIRQagJ7oQUN5bv9F8Cvvlz7vbkFNHBnxtGSA55jJZJTrN0LIO/ n1ck5yl/Dpa3ZGJxqW0rynqlZqSP4eC9foYW8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ffdq98kySWVmKhM7VB6+p5/IbsOlzT1X5C/f8NIg+6o=; b=iEKZObKrnEMRkV/jHRPVEHtEctsKLsE1jkAp/A0fs8SM3AaEmjEXJxmdXHW8IlsOhF 5F/Fuh/YpFp2SNrPvAT2XaQhzUL7b0C+JH1srIC7EPOBBd5RFPWD8BIkGB15QFHIZF64 UN0tcvy+TAUYb/vuEB4UrDUhi511uPxRLfl1YZ+2PNtNTq4j6YXe4maQ27jxKd3hPrwU qQRGFT7117Qydy4d8ziolHEAORM1q4whLXPO5w8W7bSjFdLp6dO+lIaV9taUJwNc0Jru Rwt8fyuSaISyUwRhvkEnfV6sGnyEfaHkD5SnXvwH8XO6QSpPZkJA0pA+mPV8gjuSBRPG IppA== X-Gm-Message-State: ABuFfogr877znAptuLIwGiZ7g2qGyEvsieiFWM8395uBqdlGx/rJmSsL rk3WsDqlEK7iLtozqtetZxALvoF6zdqXtihv X-Google-Smtp-Source: ACcGV63C0KTEKxoJMRxK9z1/UMl7tgHBIJhCLEqoR8HNZxYvYloEzoa2UgJNMQX073gEnlxhBBaAPg== X-Received: by 2002:a63:8c0b:: with SMTP id m11-v6mr15785653pgd.422.1539602065481; Mon, 15 Oct 2018 04:14:25 -0700 (PDT) Received: from lgd-kipper.hsd1.ca.comcast.net ([2601:646:8581:1fcf:8286:f2ff:fe24:931b]) by smtp.gmail.com with ESMTPSA id e22-v6sm11352461pfi.61.2018.10.15.04.14.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 04:14:24 -0700 (PDT) From: Luke Diamand To: git@vger.kernel.org Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Chen Bin , Miguel Torroja , George Vanburgh , Merland Romain , Vinicius Kursancew , larsxschneider@gmail.com, Lex Spoon , Johannes Schindelin , Luke Diamand Subject: [PATCHv2 1/3] git-p4: do not fail in verbose mode for missing 'fileSize' key Date: Mon, 15 Oct 2018 12:14:06 +0100 Message-Id: <20181015111408.17618-2-luke@diamand.org> X-Mailer: git-send-email 2.19.1.331.gae0ed827e6 In-Reply-To: <20181015111408.17618-1-luke@diamand.org> References: <20181015111408.17618-1-luke@diamand.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If deleting or moving a file, sometimes P4 doesn't report the file size. The code handles this just fine but some logging crashes. Stop this happening. There was some earlier discussion on the list about this: https://public-inbox.org/git/xmqq1sqpp1vv.fsf@gitster.mtv.corp.google.com/ Signed-off-by: Luke Diamand --- git-p4.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-p4.py b/git-p4.py index 7fab255584..5701bad06a 100755 --- a/git-p4.py +++ b/git-p4.py @@ -2775,7 +2775,10 @@ def streamOneP4File(self, file, contents): relPath = self.stripRepoPath(file['depotFile'], self.branchPrefixes) relPath = self.encodeWithUTF8(relPath) if verbose: - size = int(self.stream_file['fileSize']) + if 'fileSize' in self.stream_file: + size = int(self.stream_file['fileSize']) + else: + size = 0 # deleted files don't get a fileSize apparently sys.stdout.write('\r%s --> %s (%i MB)\n' % (file['depotFile'], relPath, size/1024/1024)) sys.stdout.flush() From patchwork Mon Oct 15 11:14:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Diamand X-Patchwork-Id: 10641559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5759C14E2 for ; Mon, 15 Oct 2018 11:14:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 483F729235 for ; Mon, 15 Oct 2018 11:14:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C37929400; Mon, 15 Oct 2018 11:14:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26B3F293B5 for ; Mon, 15 Oct 2018 11:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726534AbeJOS7P (ORCPT ); Mon, 15 Oct 2018 14:59:15 -0400 Received: from mail-pg1-f180.google.com ([209.85.215.180]:46655 "EHLO mail-pg1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726319AbeJOS7P (ORCPT ); Mon, 15 Oct 2018 14:59:15 -0400 Received: by mail-pg1-f180.google.com with SMTP id a5-v6so8996005pgv.13 for ; Mon, 15 Oct 2018 04:14:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diamand.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n9DLn3N8MxdlWF/xOd4AOanOLPC39tDsYeob6yjt69I=; b=FGyDmmbRlRsLugGko4ed35nGsOjZFBdWouDM95hVtKXQA/Ut6IKdplGAR9hJN0b47U W+w+NanghevMi394xaAYlt/7GhsimjJ3+nYF9itNY35zN3LJGAYeoLEh/H9sqHZvAF/Q nw7YvBsnp+XgZ18akYHi+ccsgJiZctLoUrNPE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n9DLn3N8MxdlWF/xOd4AOanOLPC39tDsYeob6yjt69I=; b=ElwMNLzOb1roAv17pY/QcpSCv4MGFE/EG2lE2U+a2m86lyJS+kDRVzxnTf363/ob1Z v/8ddZNXEL24OUVpcRuJbfYbzeOfC5NKOPPR8+UQlNJeqCQvk9oMby1kqIqpMZEW9GLX KFE78ezNQwN4exa/ZyMTx/UVq8zzsW0LOalJTcKXkrwQLnGcYuJwdNksMon4KE34mejO ThknlgMq344OM4WF4iVCeOcbi8gUqbYaJqnq8+PBtPiAjFkaHLmDkmznwVEbESCpxg8m 4vXX/gudjN0wMsgr6oQEHdWP0KtpnXqadCb12cdZkIpn9IV//7maUGNGZgXrx13GOOZG bu1A== X-Gm-Message-State: ABuFfohxMadAyaD3IRsQWSxLz2kwemJmh8ziwcKkGADw0HHCEYbKIF/g gk9aRn8r4yLRMcOiXiNo2IakVS9OU5f8Nkjf X-Google-Smtp-Source: ACcGV605HoGXUzZTx4qnC+YJC75xMBZMrh2Icy+IGCc6c2FlEoYWrJEeH/OQOK/+y7MvkJ5S/wydxQ== X-Received: by 2002:a62:7a81:: with SMTP id v123-v6mr17487906pfc.240.1539602066902; Mon, 15 Oct 2018 04:14:26 -0700 (PDT) Received: from lgd-kipper.hsd1.ca.comcast.net ([2601:646:8581:1fcf:8286:f2ff:fe24:931b]) by smtp.gmail.com with ESMTPSA id e22-v6sm11352461pfi.61.2018.10.15.04.14.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 04:14:26 -0700 (PDT) From: Luke Diamand To: git@vger.kernel.org Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Chen Bin , Miguel Torroja , George Vanburgh , Merland Romain , Vinicius Kursancew , larsxschneider@gmail.com, Lex Spoon , Johannes Schindelin , Luke Diamand Subject: [PATCHv2 2/3] git-p4: unshelve into refs/remotes/p4-unshelved, not refs/remotes/p4/unshelved Date: Mon, 15 Oct 2018 12:14:07 +0100 Message-Id: <20181015111408.17618-3-luke@diamand.org> X-Mailer: git-send-email 2.19.1.331.gae0ed827e6 In-Reply-To: <20181015111408.17618-1-luke@diamand.org> References: <20181015111408.17618-1-luke@diamand.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The branch detection code looks for branches under refs/remotes/p4/... and can end up getting confused if there are unshelved changes in there as well. This happens in the function p4BranchesInGit(). Instead, put the unshelved changes into refs/remotes/p4-unshelved/. Signed-off-by: Luke Diamand --- Documentation/git-p4.txt | 6 +++--- git-p4.py | 3 ++- t/t9832-unshelve.sh | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 41780a5aa9..6c0017e36e 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -174,7 +174,7 @@ $ git p4 submit --update-shelve 1234 --update-shelve 2345 Unshelve ~~~~~~~~ Unshelving will take a shelved P4 changelist, and produce the equivalent git commit -in the branch refs/remotes/p4/unshelved/. +in the branch refs/remotes/p4-unshelved/. The git commit is created relative to the current origin revision (HEAD by default). If the shelved changelist's parent revisions differ, git-p4 will refuse to unshelve; @@ -182,13 +182,13 @@ you need to be unshelving onto an equivalent tree. The origin revision can be changed with the "--origin" option. -If the target branch in refs/remotes/p4/unshelved already exists, the old one will +If the target branch in refs/remotes/p4-unshelved already exists, the old one will be renamed. ---- $ git p4 sync $ git p4 unshelve 12345 -$ git show refs/remotes/p4/unshelved/12345 +$ git show p4-unshelved/12345 $ git p4 unshelve 12345 diff --git a/git-p4.py b/git-p4.py index 5701bad06a..76c18a22e9 100755 --- a/git-p4.py +++ b/git-p4.py @@ -3956,7 +3956,8 @@ def __init__(self): ] self.verbose = False self.noCommit = False - self.destbranch = "refs/remotes/p4/unshelved" + self.destbranch = "refs/remotes/p4-unshelved" + self.origin = "p4/master" def renameBranch(self, branch_name): """ Rename the existing branch to branch_name.N diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh index 48ec7679b8..c3d15ceea8 100755 --- a/t/t9832-unshelve.sh +++ b/t/t9832-unshelve.sh @@ -54,8 +54,8 @@ EOF cd "$git" && change=$(last_shelved_change) && git p4 unshelve $change && - git show refs/remotes/p4/unshelved/$change | grep -q "Further description" && - git cherry-pick refs/remotes/p4/unshelved/$change && + git show refs/remotes/p4-unshelved/$change | grep -q "Further description" && + git cherry-pick refs/remotes/p4-unshelved/$change && test_path_is_file file2 && test_cmp file1 "$cli"/file1 && test_cmp file2 "$cli"/file2 && @@ -88,7 +88,7 @@ EOF cd "$git" && change=$(last_shelved_change) && git p4 unshelve $change && - git diff refs/remotes/p4/unshelved/$change.0 refs/remotes/p4/unshelved/$change | grep -q file3 + git diff refs/remotes/p4-unshelved/$change.0 refs/remotes/p4-unshelved/$change | grep -q file3 ) ' From patchwork Mon Oct 15 11:14:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Diamand X-Patchwork-Id: 10641561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2BE6E14E2 for ; Mon, 15 Oct 2018 11:14:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A62A28BE6 for ; Mon, 15 Oct 2018 11:14:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E45F293B5; Mon, 15 Oct 2018 11:14:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3FBE28BE6 for ; Mon, 15 Oct 2018 11:14:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbeJOS7Q (ORCPT ); Mon, 15 Oct 2018 14:59:16 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:44719 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726319AbeJOS7Q (ORCPT ); Mon, 15 Oct 2018 14:59:16 -0400 Received: by mail-pl1-f195.google.com with SMTP id p25-v6so9134712pli.11 for ; Mon, 15 Oct 2018 04:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diamand.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i4+UXgTOtFd7jFzmww18Z8j6495Uj6ep+WG+8CD6tWY=; b=ZiB6XXlAjbJfUOzhMnGw4v9XfSM1i2uSGABfzqv4HUZlQR3L2XMmE7GXP9wqSK0C2B 50+DIsjuQ+o7JqY+oOTHZtrXxvnyApzIcr15+lBWFsGWFprtIfuwsJlOmqvRewRoQ44K s11KkxJNGms7qUi2QFonL6a00qzm1GgOktMwk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i4+UXgTOtFd7jFzmww18Z8j6495Uj6ep+WG+8CD6tWY=; b=EGJngq0LSuLl96iXiOKn9Iys2mReG2pgBTAggkAhc44Lz7NVgRtJdVJgezv/w1svNu 3Ea41bNrCorTRPnKF6zlwkIF3tS4KzP1me2DTBqeblROqdqzisiVszlp73PWCyj5ZMUZ Di8du/UFx6rVlrVHpZGkhDBXws/rDf7BURcI8STfFQfVKtz2eHDNGgWJjAIA35+tFcTj n5l9b5vLcuIWiZBOTQPTR7bgnwyiVGI/+xDfeB5eFQVuDx9z5K61T3Cb26ufKzuZ2jV9 x05D9r2X10rTvJQHLVCSloeVe10uJ3DeablThjXBhfBtAw5GJsUcAIuJp85NPNAD/gUE v/lg== X-Gm-Message-State: ABuFfoifCbKS3LY6g1vnfOT3sYN858BLrcetp0BS6eJaJX+jLKzn+2w8 Nrb3+zuovDdEg2H9X9irVSYDc5Os9k0Djhi7 X-Google-Smtp-Source: ACcGV63S675CA0Dh95J2JY2hq2ArM2yhJVLsylkWaqjZcuw2uwkB2FQt6coFrB3Ygr3NmGUhowZk6g== X-Received: by 2002:a17:902:8502:: with SMTP id bj2-v6mr16480025plb.295.1539602068133; Mon, 15 Oct 2018 04:14:28 -0700 (PDT) Received: from lgd-kipper.hsd1.ca.comcast.net ([2601:646:8581:1fcf:8286:f2ff:fe24:931b]) by smtp.gmail.com with ESMTPSA id e22-v6sm11352461pfi.61.2018.10.15.04.14.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 04:14:27 -0700 (PDT) From: Luke Diamand To: git@vger.kernel.org Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Chen Bin , Miguel Torroja , George Vanburgh , Merland Romain , Vinicius Kursancew , larsxschneider@gmail.com, Lex Spoon , Johannes Schindelin , Luke Diamand Subject: [PATCHv2 3/3] git-p4: fully support unshelving changelists Date: Mon, 15 Oct 2018 12:14:08 +0100 Message-Id: <20181015111408.17618-4-luke@diamand.org> X-Mailer: git-send-email 2.19.1.331.gae0ed827e6 In-Reply-To: <20181015111408.17618-1-luke@diamand.org> References: <20181015111408.17618-1-luke@diamand.org> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The previous git-p4 unshelve support would check for changes in Perforce to the files being unshelved since the original shelve, and would complain if any were found. This was to ensure that the user wouldn't end up with both the shelved change delta, and some deltas from other changes in their git commit. e.g. given fileA: the quick brown fox change1: s/the/The/ <- p4 shelve this change change2: s/fox/Fox/ <- p4 submit this change git p4 unshelve 1 <- FAIL This change teaches the P4Unshelve class to always create a parent commit which matches the P4 tree (for the files being unshelved) at the point prior to the P4 shelve being created (which is reported in the p4 description for a shelved changelist). That then means git-p4 can always create a git commit matching the P4 shelve that was originally created, without any extra deltas. The user might still need to use the --origin option though - there is no way for git-p4 to work out the versions of all of the other *unchanged* files in the shelve, since this information is not recorded by Perforce. Additionally this fixes handling of shelved 'move' operations. Signed-off-by: Luke Diamand --- Documentation/git-p4.txt | 4 +- git-p4.py | 84 +++++++++++++++++++++++----------------- t/t9832-unshelve.sh | 69 ++++++++++++++++++++++++++------- 3 files changed, 106 insertions(+), 51 deletions(-) diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 6c0017e36e..f0a0280954 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -177,8 +177,8 @@ Unshelving will take a shelved P4 changelist, and produce the equivalent git com in the branch refs/remotes/p4-unshelved/. The git commit is created relative to the current origin revision (HEAD by default). -If the shelved changelist's parent revisions differ, git-p4 will refuse to unshelve; -you need to be unshelving onto an equivalent tree. +A parent commit is created based on the origin, and then the unshelve commit is +created based on that. The origin revision can be changed with the "--origin" option. diff --git a/git-p4.py b/git-p4.py index 76c18a22e9..1998c3e141 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1306,6 +1306,9 @@ def processContent(self, git_mode, relPath, contents): return LargeFileSystem.processContent(self, git_mode, relPath, contents) class Command: + delete_actions = ( "delete", "move/delete", "purge" ) + add_actions = ( "add", "move/add" ) + def __init__(self): self.usage = "usage: %prog [options]" self.needsGit = True @@ -2524,7 +2527,6 @@ def map_in_client(self, depot_path): return "" class P4Sync(Command, P4UserMap): - delete_actions = ( "delete", "move/delete", "purge" ) def __init__(self): Command.__init__(self) @@ -2612,20 +2614,7 @@ def checkpoint(self): if self.verbose: print("checkpoint finished: " + out) - def cmp_shelved(self, path, filerev, revision): - """ Determine if a path at revision #filerev is the same as the file - at revision @revision for a shelved changelist. If they don't match, - unshelving won't be safe (we will get other changes mixed in). - - This is comparing the revision that the shelved changelist is *based* on, not - the shelved changelist itself. - """ - ret = p4Cmd(["diff2", "{0}#{1}".format(path, filerev), "{0}@{1}".format(path, revision)]) - if verbose: - print("p4 diff2 path %s filerev %s revision %s => %s" % (path, filerev, revision, ret)) - return ret["status"] == "identical" - - def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0, origin_revision = 0): + def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0): self.cloneExclude = [re.sub(r"\.\.\.$", "", path) for path in self.cloneExclude] files = [] @@ -2650,17 +2639,6 @@ def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0, origin_r file["type"] = commit["type%s" % fnum] if shelved: file["shelved_cl"] = int(shelved_cl) - - # For shelved changelists, check that the revision of each file that the - # shelve was based on matches the revision that we are using for the - # starting point for git-fast-import (self.initialParent). Otherwise - # the resulting diff will contain deltas from multiple commits. - - if file["action"] != "add" and \ - not self.cmp_shelved(path, file["rev"], origin_revision): - sys.exit("change {0} not based on {1} for {2}, cannot unshelve".format( - commit["change"], self.initialParent, path)) - files.append(file) fnum = fnum + 1 return files @@ -3032,7 +3010,7 @@ def hasBranchPrefix(self, path): print('Ignoring file outside of prefix: {0}'.format(path)) return hasPrefix - def commit(self, details, files, branch, parent = ""): + def commit(self, details, files, branch, parent = "", allow_empty=False): epoch = details["time"] author = details["user"] jobs = self.extractJobsFromCommit(details) @@ -3046,7 +3024,10 @@ def commit(self, details, files, branch, parent = ""): files = [f for f in files if self.inClientSpec(f['path']) and self.hasBranchPrefix(f['path'])] - if not files and not gitConfigBool('git-p4.keepEmptyCommits'): + if gitConfigBool('git-p4.keepEmptyCommits'): + allow_empty = True + + if not files and not allow_empty: print('Ignoring revision {0} as it would produce an empty commit.' .format(details['change'])) return @@ -3387,10 +3368,10 @@ def searchParent(self, parent, branch, target): else: return None - def importChanges(self, changes, shelved=False, origin_revision=0): + def importChanges(self, changes, origin_revision=0): cnt = 1 for change in changes: - description = p4_describe(change, shelved) + description = p4_describe(change) self.updateOptionDict(description) if not self.silent: @@ -3460,7 +3441,7 @@ def importChanges(self, changes, shelved=False, origin_revision=0): print("Parent of %s not found. Committing into head of %s" % (branch, parent)) self.commit(description, filesForCommit, branch, parent) else: - files = self.extractFilesFromCommit(description, shelved, change, origin_revision) + files = self.extractFilesFromCommit(description) self.commit(description, files, self.branch, self.initialParent) # only needed once, to connect to the previous commit @@ -3957,7 +3938,6 @@ def __init__(self): self.verbose = False self.noCommit = False self.destbranch = "refs/remotes/p4-unshelved" - self.origin = "p4/master" def renameBranch(self, branch_name): """ Rename the existing branch to branch_name.N @@ -3989,6 +3969,32 @@ def findLastP4Revision(self, starting_point): sys.exit("could not find git-p4 commits in {0}".format(self.origin)) + def createShelveParent(self, change, branch_name, sync, origin): + """ Create a commit matching the parent of the shelved changelist 'change' + """ + parent_description = p4_describe(change, shelved=True) + parent_description['desc'] = 'parent for shelved changelist {}\n'.format(change) + files = sync.extractFilesFromCommit(parent_description, shelved=False, shelved_cl=change) + + parent_files = [] + for f in files: + # if it was added in the shelved changelist, it won't exist in the parent + if f['action'] in self.add_actions: + continue + + # if it was deleted in the shelved changelist it must not be deleted + # in the parent - we might even need to create it if the origin branch + # does not have it + if f['action'] in self.delete_actions: + f['action'] = 'add' + + parent_files.append(f) + + sync.commit(parent_description, parent_files, branch_name, + parent=origin, allow_empty=True) + print("created parent commit for {0} based on {1} in {2}".format( + change, self.origin, branch_name)) + def run(self, args): if len(args) != 1: return False @@ -3998,9 +4004,8 @@ def run(self, args): sync = P4Sync() changes = args - sync.initialParent = self.origin - # use the first change in the list to construct the branch to unshelve into + # only one change at a time change = changes[0] # if the target branch already exists, rename it @@ -4013,14 +4018,21 @@ def run(self, args): sync.suppress_meta_comment = True settings = self.findLastP4Revision(self.origin) - origin_revision = settings['change'] sync.depotPaths = settings['depot-paths'] sync.branchPrefixes = sync.depotPaths sync.openStreams() sync.loadUserMapFromCache() sync.silent = True - sync.importChanges(changes, shelved=True, origin_revision=origin_revision) + + # create a commit for the parent of the shelved changelist + self.createShelveParent(change, branch_name, sync, self.origin) + + # create the commit for the shelved changelist itself + description = p4_describe(change, True) + files = sync.extractFilesFromCommit(description, True, change) + + sync.commit(description, files, branch_name, "") sync.closeStreams() print("unshelved changelist {0} into {1}".format(change, branch_name)) diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh index c3d15ceea8..41c09f11f4 100755 --- a/t/t9832-unshelve.sh +++ b/t/t9832-unshelve.sh @@ -19,8 +19,10 @@ test_expect_success 'init depot' ' p4 add file1 && p4 submit -d "change 1" && : >file_to_delete && + : >file_to_move && p4 add file_to_delete && - p4 submit -d "file to delete" + p4 add file_to_move && + p4 submit -d "add files to delete" ) ' @@ -36,6 +38,8 @@ test_expect_success 'create shelved changelist' ' echo "new file" >file2 && p4 add file2 && p4 delete file_to_delete && + p4 edit file_to_move && + p4 move file_to_move moved_file && p4 opened && p4 shelve -i <>file1 && - p4 shelve -i <out.txt && + grep -q "Change to be unshelved" out.txt ) ' -# Now try to unshelve it. git-p4 should refuse to do so. +# Now try to unshelve it. test_expect_success 'try to unshelve the change' ' test_when_finished cleanup_git && ( change=$(last_shelved_change) && cd "$git" && - test_must_fail git p4 unshelve $change 2>out.txt && - grep -q "cannot unshelve" out.txt + git p4 unshelve $change >out.txt && + grep -q "unshelved changelist $change" out.txt ) ' +# Specify the origin. Create 2 unrelated files, and check that +# we only get the one in HEAD~, not the one in HEAD. + +test_expect_success 'unshelve specifying the origin' ' + ( + cd "$cli" && + : >unrelated_file0 && + p4 add unrelated_file0 && + p4 submit -d "unrelated" && + : >unrelated_file1 && + p4 add unrelated_file1 && + p4 submit -d "unrelated" && + : >file_to_shelve && + p4 add file_to_shelve && + shelve_one_file //depot/file_to_shelve + ) && + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot/@all && + ( + cd "$git" && + change=$(last_shelved_change) && + git p4 unshelve --origin HEAD~ $change && + git checkout refs/remotes/p4-unshelved/$change && + test_path_is_file unrelated_file0 && + test_path_is_missing unrelated_file1 && + test_path_is_file file_to_shelve + ) +' test_expect_success 'kill p4d' ' kill_p4d '