From patchwork Thu Nov 29 21:58:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10705383 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 18EE7181D for ; Thu, 29 Nov 2018 21:59:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 075812F9AC for ; Thu, 29 Nov 2018 21:59:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF48A2F9E5; Thu, 29 Nov 2018 21:59:17 +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,FREEMAIL_FROM,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 9C5502F9B4 for ; Thu, 29 Nov 2018 21:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726406AbeK3JGJ (ORCPT ); Fri, 30 Nov 2018 04:06:09 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:46492 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726374AbeK3JGJ (ORCPT ); Fri, 30 Nov 2018 04:06:09 -0500 Received: by mail-lj1-f194.google.com with SMTP id v15-v6so3127065ljh.13 for ; Thu, 29 Nov 2018 13:59:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vfuE2Exm+TC8r5Ltjuf7nGMB6WGrz3RmuaVGwcYaKQs=; b=FMSOmxyx7aCLUnA3HRG6OcvEufM2YoCuQnGFAjOaRY7wm4y4C1KKSGOB6STuZELSaa B8JsAU1oQ6M4bFNHZDA6Ao0K6PiidOJwTsD90DLyNcna+mF10otOC1CINihDJM+vD6is 44bi0nmTm6765b1PtyUQvZpf+XxWnQsgrVwqCAzL+dpqvJSRokFBkNkVbFctta6tNiOs 6DuL7vwnBJswuh7wjPDbDrwaAkJ7BdFaYRhZ7qQsHTPhMjhNwX0ATmldm7+YDQJwue6O rD9kboa9k3SccZHpxlvryeqJO2ndWSjYjZhlydmaxPKgKe+NT9XUtu0H7GunFLGGIZRc qTuA== 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=vfuE2Exm+TC8r5Ltjuf7nGMB6WGrz3RmuaVGwcYaKQs=; b=TWiEJC8EnBXs+TJTaf4fDT8tfrRq9NyW3jG3XyGWxGsKLmyEa5pMG23rgECUi4xh30 x5AoELiM5LjhLU/3xHnAttB/gseDaIeb+8xbjzhFIeQxhMaR5yb7TFTQetPN6Ay/Qq+r 0Zdx76w2hqNyennp+PGvfS6fi7/al38Iy3dvJzJjdy+Ze9Jte1K6Y6Jg3NoswmJqWxF0 gI3b28SITNzE6cuugH+W2/6k6WFoI5mhL2BZ3cFklZNSiUgP0582xgmmKboOk8+LLc5P 8IP0MYFRAIv9ysYQZ7KPZmNA1oh7XAD54uD2+w8Y92xYQB6ES8I/eAL/qwgRi2Vnos6C MBTg== X-Gm-Message-State: AA+aEWYtDqpfXfajiRO1vdJchRsdRqKaFIsWWo7i3JGqL00/uFh4VWdO G2q9Tw7zyhqHbq0qZl9Ri3A= X-Google-Smtp-Source: AFSGD/VFZZ5EDcLZyrtxPh3lxYGe8NWW95RGMDDGe2v3jVFE/Myx25D2bSRtZngr/DriyCcDDqKbvA== X-Received: by 2002:a2e:2b11:: with SMTP id q17-v6mr2176430lje.25.1543528753363; Thu, 29 Nov 2018 13:59:13 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id o17sm489703lff.77.2018.11.29.13.59.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 13:59:12 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, sbeller@google.com, t.gummerer@gmail.com, sxenos@google.com Subject: [PATCH v3 01/14] git-checkout.txt: fix one syntax line Date: Thu, 29 Nov 2018 22:58:36 +0100 Message-Id: <20181129215850.7278-2-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.rc1.380.g3eb999425c.dirty In-Reply-To: <20181129215850.7278-1-pclouds@gmail.com> References: <20181127165211.24763-1-pclouds@gmail.com> <20181129215850.7278-1-pclouds@gmail.com> 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 can be omitted in this syntax, and it's actually documented a few paragraphs down: You could omit , in which case the command degenerates to "check out the current branch", which is a glorified no-op with rather expensive side-effects to show only the tracking information, if exists, for the current branch. Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/git-checkout.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 801de2f764..65bd1bc50d 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -23,7 +23,7 @@ or the specified tree. If no paths are given, 'git checkout' will also update `HEAD` to set the specified branch as the current branch. -'git checkout' :: +'git checkout' []:: To prepare for working on , switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch. Local modifications to the files in the From patchwork Thu Nov 29 21:58:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10705413 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 A650A181D for ; Thu, 29 Nov 2018 21:59:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 985612F9B4 for ; Thu, 29 Nov 2018 21:59:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C48C2F9CA; Thu, 29 Nov 2018 21:59:39 +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,FREEMAIL_FROM,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 CC22B2F9C6 for ; Thu, 29 Nov 2018 21:59:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726446AbeK3JGM (ORCPT ); Fri, 30 Nov 2018 04:06:12 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:38874 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726344AbeK3JGL (ORCPT ); Fri, 30 Nov 2018 04:06:11 -0500 Received: by mail-lf1-f68.google.com with SMTP id p86so2634027lfg.5 for ; Thu, 29 Nov 2018 13:59:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RoLYRYXpQHqKfYd5P+dsZAZkWkcWeO86aiadkVL2ZJQ=; b=FVh6MjrudroKHrCiDINu/Kp28/gthqTDNPrMFLf7ck8kb1c4GA6GTPPfQU0tH98gUc rszmPgVq03SJwQNTEHt217uwND/TAdp3Db30zGlK0A756/sj80HBac4HlDQOEFYSkzRF 4WK8LfnjOqV2oXGCTu3vCdjoHGNg05ynHJL3QjyDRqAxzhpUJiBNx9lhSlGC8TQcYdUl 0ND7av3+tnvjsg3w9KvJ1uASIzOyDYmltn1qvFqJwN8w2ywqp2iKvYhcN8rfehbHkEcg bg1Zgjw9s6BliW4ghOSQBR6VN0/20gNyAAckEjsbd9vwFDVAbeVeMXnrRCVWONHrP0Fc pbxQ== 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=RoLYRYXpQHqKfYd5P+dsZAZkWkcWeO86aiadkVL2ZJQ=; b=JwU5KuS6wae7LooPbMr5qG+hp9KHjhEwTX8KOolX46RTVr+X47zPAofDZfUkWll5t1 DkGj7mRm9wILIn1usnGE3T2AniEEFZfhhP7Y3+Oy7l4FWY8wx82arVB4vTo12bsTyBzz MCpdHaNy57ruuc3gR5inrHg0+8s5uVPozJ60r96zD5yLonJTpKGje8MkZhYU0wDrJ0+B 7h9MB/GVXDsSyqfjl1P34nkR74XoB8UdFqy6Cx8R/kaNf8RN6MI48zvRpbLFuV14d9O6 jLMKcWE13J0EO1s0O3HaDjhiJ8CwBXrCXPdsQ4zv0DtPHRasXGuMwTAyHt/38swN87gC T0zg== X-Gm-Message-State: AA+aEWYrG1JomOsZgFCwXKojakJeLlPXx9KH+8KEpAnmZqHqxCkpLUEC WouJvE9GMuPsxfJ3mJOHCDYP4Z4v X-Google-Smtp-Source: AFSGD/XLPaEUoEtpt3l/nyuRLMxqN7ntbjZGCCgEBkXd7vLeU3saRQpzGOeNGzqRXoTJSyOrFvRVmA== X-Received: by 2002:a19:4d8d:: with SMTP id a135mr2288397lfb.80.1543528754506; Thu, 29 Nov 2018 13:59:14 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id o17sm489703lff.77.2018.11.29.13.59.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 13:59:13 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, sbeller@google.com, t.gummerer@gmail.com, sxenos@google.com Subject: [PATCH v3 02/14] git-checkout.txt: split detached head section out Date: Thu, 29 Nov 2018 22:58:37 +0100 Message-Id: <20181129215850.7278-3-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.rc1.380.g3eb999425c.dirty In-Reply-To: <20181129215850.7278-1-pclouds@gmail.com> References: <20181127165211.24763-1-pclouds@gmail.com> <20181129215850.7278-1-pclouds@gmail.com> 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 This is to be reused by the coming git-switch-branch.txt man page which also deals with detached HEAD. Signed-off-by: Nguyễn Thái Ngọc Duy --- Documentation/detach-head.txt | 132 ++++++++++++++++++++++++++++++++ Documentation/git-checkout.txt | 133 +-------------------------------- 2 files changed, 133 insertions(+), 132 deletions(-) create mode 100644 Documentation/detach-head.txt diff --git a/Documentation/detach-head.txt b/Documentation/detach-head.txt new file mode 100644 index 0000000000..bb6f5d7843 --- /dev/null +++ b/Documentation/detach-head.txt @@ -0,0 +1,132 @@ +HEAD normally refers to a named branch (e.g. 'master'). Meanwhile, each +branch refers to a specific commit. Let's look at a repo with three +commits, one of them tagged, and with branch 'master' checked out: + +------------ + HEAD (refers to branch 'master') + | + v +a---b---c branch 'master' (refers to commit 'c') + ^ + | + tag 'v2.0' (refers to commit 'b') +------------ + +When a commit is created in this state, the branch is updated to refer to +the new commit. Specifically, 'git commit' creates a new commit 'd', whose +parent is commit 'c', and then updates branch 'master' to refer to new +commit 'd'. HEAD still refers to branch 'master' and so indirectly now refers +to commit 'd': + +------------ +$ edit; git add; git commit + + HEAD (refers to branch 'master') + | + v +a---b---c---d branch 'master' (refers to commit 'd') + ^ + | + tag 'v2.0' (refers to commit 'b') +------------ + +It is sometimes useful to be able to checkout a commit that is not at +the tip of any named branch, or even to create a new commit that is not +referenced by a named branch. Let's look at what happens when we +checkout commit 'b' (here we show two ways this may be done): + +------------ +$ git checkout v2.0 # or +$ git checkout master^^ + + HEAD (refers to commit 'b') + | + v +a---b---c---d branch 'master' (refers to commit 'd') + ^ + | + tag 'v2.0' (refers to commit 'b') +------------ + +Notice that regardless of which checkout command we use, HEAD now refers +directly to commit 'b'. This is known as being in detached HEAD state. +It means simply that HEAD refers to a specific commit, as opposed to +referring to a named branch. Let's see what happens when we create a commit: + +------------ +$ edit; git add; git commit + + HEAD (refers to commit 'e') + | + v + e + / +a---b---c---d branch 'master' (refers to commit 'd') + ^ + | + tag 'v2.0' (refers to commit 'b') +------------ + +There is now a new commit 'e', but it is referenced only by HEAD. We can +of course add yet another commit in this state: + +------------ +$ edit; git add; git commit + + HEAD (refers to commit 'f') + | + v + e---f + / +a---b---c---d branch 'master' (refers to commit 'd') + ^ + | + tag 'v2.0' (refers to commit 'b') +------------ + +In fact, we can perform all the normal Git operations. But, let's look +at what happens when we then checkout master: + +------------ +$ git checkout master + + HEAD (refers to branch 'master') + e---f | + / v +a---b---c---d branch 'master' (refers to commit 'd') + ^ + | + tag 'v2.0' (refers to commit 'b') +------------ + +It is important to realize that at this point nothing refers to commit +'f'. Eventually commit 'f' (and by extension commit 'e') will be deleted +by the routine Git garbage collection process, unless we create a reference +before that happens. If we have not yet moved away from commit 'f', +any of these will create a reference to it: + +------------ +$ git checkout -b foo <1> +$ git branch foo <2> +$ git tag foo <3> +------------ + +<1> creates a new branch 'foo', which refers to commit 'f', and then +updates HEAD to refer to branch 'foo'. In other words, we'll no longer +be in detached HEAD state after this command. + +<2> similarly creates a new branch 'foo', which refers to commit 'f', +but leaves HEAD detached. + +<3> creates a new tag 'foo', which refers to commit 'f', +leaving HEAD detached. + +If we have moved away from commit 'f', then we must first recover its object +name (typically by using git reflog), and then we can create a reference to +it. For example, to see the last two commits to which HEAD referred, we +can use either of these commands: + +------------ +$ git reflog -2 HEAD # or +$ git log -g -2 HEAD +------------ diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 65bd1bc50d..25887a6087 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -306,138 +306,7 @@ leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. DETACHED HEAD ------------- -HEAD normally refers to a named branch (e.g. 'master'). Meanwhile, each -branch refers to a specific commit. Let's look at a repo with three -commits, one of them tagged, and with branch 'master' checked out: - ------------- - HEAD (refers to branch 'master') - | - v -a---b---c branch 'master' (refers to commit 'c') - ^ - | - tag 'v2.0' (refers to commit 'b') ------------- - -When a commit is created in this state, the branch is updated to refer to -the new commit. Specifically, 'git commit' creates a new commit 'd', whose -parent is commit 'c', and then updates branch 'master' to refer to new -commit 'd'. HEAD still refers to branch 'master' and so indirectly now refers -to commit 'd': - ------------- -$ edit; git add; git commit - - HEAD (refers to branch 'master') - | - v -a---b---c---d branch 'master' (refers to commit 'd') - ^ - | - tag 'v2.0' (refers to commit 'b') ------------- - -It is sometimes useful to be able to checkout a commit that is not at -the tip of any named branch, or even to create a new commit that is not -referenced by a named branch. Let's look at what happens when we -checkout commit 'b' (here we show two ways this may be done): - ------------- -$ git checkout v2.0 # or -$ git checkout master^^ - - HEAD (refers to commit 'b') - | - v -a---b---c---d branch 'master' (refers to commit 'd') - ^ - | - tag 'v2.0' (refers to commit 'b') ------------- - -Notice that regardless of which checkout command we use, HEAD now refers -directly to commit 'b'. This is known as being in detached HEAD state. -It means simply that HEAD refers to a specific commit, as opposed to -referring to a named branch. Let's see what happens when we create a commit: - ------------- -$ edit; git add; git commit - - HEAD (refers to commit 'e') - | - v - e - / -a---b---c---d branch 'master' (refers to commit 'd') - ^ - | - tag 'v2.0' (refers to commit 'b') ------------- - -There is now a new commit 'e', but it is referenced only by HEAD. We can -of course add yet another commit in this state: - ------------- -$ edit; git add; git commit - - HEAD (refers to commit 'f') - | - v - e---f - / -a---b---c---d branch 'master' (refers to commit 'd') - ^ - | - tag 'v2.0' (refers to commit 'b') ------------- - -In fact, we can perform all the normal Git operations. But, let's look -at what happens when we then checkout master: - ------------- -$ git checkout master - - HEAD (refers to branch 'master') - e---f | - / v -a---b---c---d branch 'master' (refers to commit 'd') - ^ - | - tag 'v2.0' (refers to commit 'b') ------------- - -It is important to realize that at this point nothing refers to commit -'f'. Eventually commit 'f' (and by extension commit 'e') will be deleted -by the routine Git garbage collection process, unless we create a reference -before that happens. If we have not yet moved away from commit 'f', -any of these will create a reference to it: - ------------- -$ git checkout -b foo <1> -$ git branch foo <2> -$ git tag foo <3> ------------- - -<1> creates a new branch 'foo', which refers to commit 'f', and then -updates HEAD to refer to branch 'foo'. In other words, we'll no longer -be in detached HEAD state after this command. - -<2> similarly creates a new branch 'foo', which refers to commit 'f', -but leaves HEAD detached. - -<3> creates a new tag 'foo', which refers to commit 'f', -leaving HEAD detached. - -If we have moved away from commit 'f', then we must first recover its object -name (typically by using git reflog), and then we can create a reference to -it. For example, to see the last two commits to which HEAD referred, we -can use either of these commands: - ------------- -$ git reflog -2 HEAD # or -$ git log -g -2 HEAD ------------- +include::detach-head.txt[] ARGUMENT DISAMBIGUATION ----------------------- From patchwork Thu Nov 29 21:58:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10705387 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 DA4BB13A4 for ; Thu, 29 Nov 2018 21:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD1702F9AC for ; Thu, 29 Nov 2018 21:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C17AD2F9C6; Thu, 29 Nov 2018 21:59:20 +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,FREEMAIL_FROM,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 5C6662F9AC for ; Thu, 29 Nov 2018 21:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726456AbeK3JGM (ORCPT ); Fri, 30 Nov 2018 04:06:12 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46496 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbeK3JGL (ORCPT ); Fri, 30 Nov 2018 04:06:11 -0500 Received: by mail-lj1-f193.google.com with SMTP id v15-v6so3127153ljh.13 for ; Thu, 29 Nov 2018 13:59:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Pw3wHKeJn3AyRQLTslCCQDWRCYKFVWw9mmN9u83fg5c=; b=szWWm8SMAil/LhSD9IlEkU1GFpcrJ58SuG9lAHrZV/UQ/Czmn0lRekUBAAsuQVC+2i 2OICBtMFfJhkk6K+dUJ5ASc0+qxPEdIOan/i2vIXlfOWS8vX+gXCyogeUItKZQgqQhx/ mDbYGyJ2kZ9YHUk2+Q+jW/BFLFbphJIh9m1Y39EXScBdZozj0bsf4j6cwMVidlLM9R7a 24V9RbdU3coCATlvEFKh7yBnzu6jNzAfI0wF5Wo0FZYJfo6S07dElYkksaXqOcci6MpO lNlf6nV7iEVSv1mmtntDa5x/gwx3vdKJN1+a+gA7ItRBsHsVEUKHyi775dzxyKEV7G8V GDMQ== 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=Pw3wHKeJn3AyRQLTslCCQDWRCYKFVWw9mmN9u83fg5c=; b=oyj2AqsafFyx7Uc9zTaFrYQgTZRBfXVLmTQGPmLFTw9Y1zEMn371/YRpcg1uTYaISo ftMHla4htcijJvvdXVuDtwfQ6Syjb7grkjZHwWubh8gOyZzjUICzcmBU48mgPxTpl9D2 zxxx6rzxRoZrbFHn7zbrrybAtKOKe1d4tIrEcV9h8sV1D0iHjX69Tm5QznyitmodI/9F r9jSGdKAxlNCgVojGryAt+d3xR2BldS11qUAKJahUDeoWpt5Yp0nxJ3tvet6sQy62/yJ MnEigkW/jrI/AcYyFFhSYKPzy3HslNIVP6DCavTd823XTi8H7ENWfZlV3T6Jsk8ty1iZ /o3w== X-Gm-Message-State: AA+aEWZxs7E4DPbHR3INQmAs74FtdusfAcXSEQG+sGWSc3KhOImMhxPg Rln+1Q/I65eYP/Z7bsLvwIOJPNR9 X-Google-Smtp-Source: AFSGD/UgXzjedRYG3dcQ84zUyfUT7SaB+Ix6j4JNgdMgdUW1Zx2/ToVKI8XjyBdQt2htVRW2U561EA== X-Received: by 2002:a2e:841:: with SMTP id g1-v6mr2360191ljd.21.1543528755662; Thu, 29 Nov 2018 13:59:15 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id o17sm489703lff.77.2018.11.29.13.59.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 13:59:15 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, sbeller@google.com, t.gummerer@gmail.com, sxenos@google.com Subject: [PATCH v3 03/14] checkout: factor out some code in parse_branchname_arg() Date: Thu, 29 Nov 2018 22:58:38 +0100 Message-Id: <20181129215850.7278-4-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.rc1.380.g3eb999425c.dirty In-Reply-To: <20181129215850.7278-1-pclouds@gmail.com> References: <20181127165211.24763-1-pclouds@gmail.com> <20181129215850.7278-1-pclouds@gmail.com> 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 This is in preparation for the new command restore-files, which also needs to parse opts->source_tree but does not need all the disambiguation logic. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 51 ++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index acdafc6e4c..1887c996c6 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -990,6 +990,34 @@ static int git_checkout_config(const char *var, const char *value, void *cb) return git_xmerge_config(var, value, NULL); } +static void setup_new_branch_info_and_source_tree( + struct branch_info *new_branch_info, + struct checkout_opts *opts, + struct object_id *rev, + const char *arg) +{ + struct tree **source_tree = &opts->source_tree; + struct object_id branch_rev; + + new_branch_info->name = arg; + setup_branch_path(new_branch_info); + + if (!check_refname_format(new_branch_info->path, 0) && + !read_ref(new_branch_info->path, &branch_rev)) + oidcpy(rev, &branch_rev); + else + new_branch_info->path = NULL; /* not an existing branch */ + + new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1); + if (!new_branch_info->commit) { + /* not a commit */ + *source_tree = parse_tree_indirect(rev); + } else { + parse_commit_or_die(new_branch_info->commit); + *source_tree = get_commit_tree(new_branch_info->commit); + } +} + static int parse_branchname_arg(int argc, const char **argv, int dwim_new_local_branch_ok, struct branch_info *new_branch_info, @@ -997,10 +1025,8 @@ static int parse_branchname_arg(int argc, const char **argv, struct object_id *rev, int *dwim_remotes_matched) { - struct tree **source_tree = &opts->source_tree; const char **new_branch = &opts->new_branch; int argcount = 0; - struct object_id branch_rev; const char *arg; int dash_dash_pos; int has_dash_dash = 0; @@ -1114,26 +1140,11 @@ static int parse_branchname_arg(int argc, const char **argv, argv++; argc--; - new_branch_info->name = arg; - setup_branch_path(new_branch_info); - - if (!check_refname_format(new_branch_info->path, 0) && - !read_ref(new_branch_info->path, &branch_rev)) - oidcpy(rev, &branch_rev); - else - new_branch_info->path = NULL; /* not an existing branch */ + setup_new_branch_info_and_source_tree(new_branch_info, opts, rev, arg); - new_branch_info->commit = lookup_commit_reference_gently(the_repository, rev, 1); - if (!new_branch_info->commit) { - /* not a commit */ - *source_tree = parse_tree_indirect(rev); - } else { - parse_commit_or_die(new_branch_info->commit); - *source_tree = get_commit_tree(new_branch_info->commit); - } - - if (!*source_tree) /* case (1): want a tree */ + if (!opts->source_tree) /* case (1): want a tree */ die(_("reference is not a tree: %s"), arg); + if (!has_dash_dash) { /* case (3).(d) -> (1) */ /* * Do not complain the most common case From patchwork Thu Nov 29 21:58:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10705389 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 0EA1013A4 for ; Thu, 29 Nov 2018 21:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3ED42F9AC for ; Thu, 29 Nov 2018 21:59:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E84AF2F9C6; Thu, 29 Nov 2018 21:59:22 +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,FREEMAIL_FROM,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 1B4582F9AC for ; Thu, 29 Nov 2018 21:59:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726470AbeK3JGO (ORCPT ); Fri, 30 Nov 2018 04:06:14 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:37522 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726374AbeK3JGN (ORCPT ); Fri, 30 Nov 2018 04:06:13 -0500 Received: by mail-lj1-f194.google.com with SMTP id e5-v6so3165602lja.4 for ; Thu, 29 Nov 2018 13:59:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pQB4m/QdW9WH6C2Fmg0RlHRysMK7NnTTak9ont9S4w0=; b=QhZfSEHSbMt50xWZgjRrFu/451YtoN4bFC7PFQPYuBHuQP5Shpa8p4fjY0VDpK65xA C+4WKJUW0F2vYo9dg8SXegYRw1L9MFYGUqjKaqFsZ044XDOJDx15OyHecgM6jv0S/V8r FAbwF6jK4+pZ39h2+iJ3+3glxGs+PPHCYqtnUj2UAlFV2FEX74c4bgDwYRovTdp0IJkZ BPNCIzVdivkL+7qnu+Jtkk77vZiw8X6othdfL0QsyORTQY0kCb9k8zoiGfCUNo8guLJN xCq3+Ultqgxc7Ukxt7r60iV039/hJE3v7iNwJXur0rVz0OLJv3eqXslPKvmM6qIBVuUf BR5w== 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=pQB4m/QdW9WH6C2Fmg0RlHRysMK7NnTTak9ont9S4w0=; b=fPmQJ4Qa1IYRkJPyhjN+scJeEQJDWPR9ydp1G41PHDO9YAT6EbIASUMk4UoC8BrVVd inHP8AaqUjVXlV5x3N5/3E11qXN3p1/FOUpOBE9HQXMb+UfeI1Hsk31v27iCgymrzej6 kXwZcqiKBsw8EVgXrymzHqTmCqG8UwFa48IpquvGK99UW3nlWTjY870IAruvY8DbEwuh GbeZyicy0qfDEilHrz3bjZvzxb1W4LCGwRqDIxDRrldXLIrh4a4QQk62KY9pGBG9oO3w uivXiFbLt+hCQ8lMdhShhRihjV5rVT9yg1ubemEcWx9ZI4VqcAt0UoqyhXN4xyTX3W/e aXYw== X-Gm-Message-State: AA+aEWbUbtg0lEnWlnUa4ntDw12Hy+XWf3JjEV7HvmMpd4MsVeWLLvsx +4IEaVZe2l0joczVQs9yRjk= X-Google-Smtp-Source: AFSGD/VwIoUE7vyD7zKb1k0IMBfmnnKIB6r8p8VtbPxtm2J/8/mgeieac5dIbDW3yRIqiSC5ltL/hA== X-Received: by 2002:a2e:2d4:: with SMTP id y81-v6mr2235681lje.62.1543528756800; Thu, 29 Nov 2018 13:59:16 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id o17sm489703lff.77.2018.11.29.13.59.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 13:59:16 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, sbeller@google.com, t.gummerer@gmail.com, sxenos@google.com Subject: [PATCH v3 04/14] checkout: make "opts" in cmd_checkout() a pointer Date: Thu, 29 Nov 2018 22:58:39 +0100 Message-Id: <20181129215850.7278-5-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.rc1.380.g3eb999425c.dirty In-Reply-To: <20181129215850.7278-1-pclouds@gmail.com> References: <20181127165211.24763-1-pclouds@gmail.com> <20181129215850.7278-1-pclouds@gmail.com> 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 "opts" will soon be moved out of cmd_checkout(). To keep changes in that patch smaller, convert "opts" to a pointer and keep the real thing behind "real_opts". Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 109 +++++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 1887c996c6..1b19328d0a 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1236,76 +1236,77 @@ static int checkout_branch(struct checkout_opts *opts, int cmd_checkout(int argc, const char **argv, const char *prefix) { - struct checkout_opts opts; + struct checkout_opts real_opts; + struct checkout_opts *opts = &real_opts; struct branch_info new_branch_info; char *conflict_style = NULL; int dwim_new_local_branch = 1; int dwim_remotes_matched = 0; struct option options[] = { - OPT__QUIET(&opts.quiet, N_("suppress progress reporting")), - OPT_STRING('b', NULL, &opts.new_branch, N_("branch"), + OPT__QUIET(&opts->quiet, N_("suppress progress reporting")), + OPT_STRING('b', NULL, &opts->new_branch, N_("branch"), N_("create and checkout a new branch")), - OPT_STRING('B', NULL, &opts.new_branch_force, N_("branch"), + OPT_STRING('B', NULL, &opts->new_branch_force, N_("branch"), N_("create/reset and checkout a branch")), - OPT_BOOL('l', NULL, &opts.new_branch_log, N_("create reflog for new branch")), - OPT_BOOL(0, "detach", &opts.force_detach, N_("detach HEAD at named commit")), - OPT_SET_INT('t', "track", &opts.track, N_("set upstream info for new branch"), + OPT_BOOL('l', NULL, &opts->new_branch_log, N_("create reflog for new branch")), + OPT_BOOL(0, "detach", &opts->force_detach, N_("detach HEAD at named commit")), + OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"), BRANCH_TRACK_EXPLICIT), - OPT_STRING(0, "orphan", &opts.new_orphan_branch, N_("new-branch"), N_("new unparented branch")), - OPT_SET_INT_F('2', "ours", &opts.writeout_stage, + OPT_STRING(0, "orphan", &opts->new_orphan_branch, N_("new-branch"), N_("new unparented branch")), + OPT_SET_INT_F('2', "ours", &opts->writeout_stage, N_("checkout our version for unmerged files"), 2, PARSE_OPT_NONEG), - OPT_SET_INT_F('3', "theirs", &opts.writeout_stage, + OPT_SET_INT_F('3', "theirs", &opts->writeout_stage, N_("checkout their version for unmerged files"), 3, PARSE_OPT_NONEG), - OPT__FORCE(&opts.force, N_("force checkout (throw away local modifications)"), + OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"), PARSE_OPT_NOCOMPLETE), - OPT_BOOL('m', "merge", &opts.merge, N_("perform a 3-way merge with the new branch")), - OPT_BOOL_F(0, "overwrite-ignore", &opts.overwrite_ignore, + OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")), + OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore, N_("update ignored files (default)"), PARSE_OPT_NOCOMPLETE), OPT_STRING(0, "conflict", &conflict_style, N_("style"), N_("conflict style (merge or diff3)")), - OPT_BOOL('p', "patch", &opts.patch_mode, N_("select hunks interactively")), - OPT_BOOL(0, "ignore-skip-worktree-bits", &opts.ignore_skipworktree, + OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")), + OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, N_("do not limit pathspecs to sparse entries only")), OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch, N_("second guess 'git checkout '")), - OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees, + OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, N_("do not check if another worktree is holding the given ref")), { OPTION_CALLBACK, 0, "recurse-submodules", NULL, "checkout", "control recursive updating of submodules", PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater }, - OPT_BOOL(0, "progress", &opts.show_progress, N_("force progress reporting")), + OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")), OPT_END(), }; - memset(&opts, 0, sizeof(opts)); + memset(opts, 0, sizeof(*opts)); memset(&new_branch_info, 0, sizeof(new_branch_info)); - opts.overwrite_ignore = 1; - opts.prefix = prefix; - opts.show_progress = -1; + opts->overwrite_ignore = 1; + opts->prefix = prefix; + opts->show_progress = -1; - git_config(git_checkout_config, &opts); + git_config(git_checkout_config, opts); - opts.track = BRANCH_TRACK_UNSPECIFIED; + opts->track = BRANCH_TRACK_UNSPECIFIED; argc = parse_options(argc, argv, prefix, options, checkout_usage, PARSE_OPT_KEEP_DASHDASH); - if (opts.show_progress < 0) { - if (opts.quiet) - opts.show_progress = 0; + if (opts->show_progress < 0) { + if (opts->quiet) + opts->show_progress = 0; else - opts.show_progress = isatty(2); + opts->show_progress = isatty(2); } if (conflict_style) { - opts.merge = 1; /* implied */ + opts->merge = 1; /* implied */ git_xmerge_config("merge.conflictstyle", conflict_style, NULL); } - if ((!!opts.new_branch + !!opts.new_branch_force + !!opts.new_orphan_branch) > 1) + if ((!!opts->new_branch + !!opts->new_branch_force + !!opts->new_orphan_branch) > 1) die(_("-b, -B and --orphan are mutually exclusive")); /* @@ -1313,14 +1314,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) * and new_branch_force and new_orphan_branch will tell us which one of * -b/-B/--orphan is being used. */ - if (opts.new_branch_force) - opts.new_branch = opts.new_branch_force; + if (opts->new_branch_force) + opts->new_branch = opts->new_branch_force; - if (opts.new_orphan_branch) - opts.new_branch = opts.new_orphan_branch; + if (opts->new_orphan_branch) + opts->new_branch = opts->new_orphan_branch; /* --track without -b/-B/--orphan should DWIM */ - if (opts.track != BRANCH_TRACK_UNSPECIFIED && !opts.new_branch) { + if (opts->track != BRANCH_TRACK_UNSPECIFIED && !opts->new_branch) { const char *argv0 = argv[0]; if (!argc || !strcmp(argv0, "--")) die(_("--track needs a branch name")); @@ -1329,7 +1330,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) argv0 = strchr(argv0, '/'); if (!argv0 || !argv0[1]) die(_("missing branch name; try -b")); - opts.new_branch = argv0 + 1; + opts->new_branch = argv0 + 1; } /* @@ -1348,56 +1349,56 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) if (argc) { struct object_id rev; int dwim_ok = - !opts.patch_mode && + !opts->patch_mode && dwim_new_local_branch && - opts.track == BRANCH_TRACK_UNSPECIFIED && - !opts.new_branch; + opts->track == BRANCH_TRACK_UNSPECIFIED && + !opts->new_branch; int n = parse_branchname_arg(argc, argv, dwim_ok, - &new_branch_info, &opts, &rev, + &new_branch_info, opts, &rev, &dwim_remotes_matched); argv += n; argc -= n; } if (argc) { - parse_pathspec(&opts.pathspec, 0, - opts.patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0, + parse_pathspec(&opts->pathspec, 0, + opts->patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0, prefix, argv); - if (!opts.pathspec.nr) + if (!opts->pathspec.nr) die(_("invalid path specification")); /* * Try to give more helpful suggestion. * new_branch && argc > 1 will be caught later. */ - if (opts.new_branch && argc == 1) + if (opts->new_branch && argc == 1) die(_("'%s' is not a commit and a branch '%s' cannot be created from it"), - argv[0], opts.new_branch); + argv[0], opts->new_branch); - if (opts.force_detach) + if (opts->force_detach) die(_("git checkout: --detach does not take a path argument '%s'"), argv[0]); - if (1 < !!opts.writeout_stage + !!opts.force + !!opts.merge) + if (1 < !!opts->writeout_stage + !!opts->force + !!opts->merge) die(_("git checkout: --ours/--theirs, --force and --merge are incompatible when\n" "checking out of the index.")); } - if (opts.new_branch) { + if (opts->new_branch) { struct strbuf buf = STRBUF_INIT; - if (opts.new_branch_force) - opts.branch_exists = validate_branchname(opts.new_branch, &buf); + if (opts->new_branch_force) + opts->branch_exists = validate_branchname(opts->new_branch, &buf); else - opts.branch_exists = - validate_new_branchname(opts.new_branch, &buf, 0); + opts->branch_exists = + validate_new_branchname(opts->new_branch, &buf, 0); strbuf_release(&buf); } UNLEAK(opts); - if (opts.patch_mode || opts.pathspec.nr) { - int ret = checkout_paths(&opts, new_branch_info.name); + if (opts->patch_mode || opts->pathspec.nr) { + int ret = checkout_paths(opts, new_branch_info.name); if (ret && dwim_remotes_matched > 1 && advice_checkout_ambiguous_remote_branch_name) advise(_("'%s' matched more than one remote tracking branch.\n" @@ -1416,6 +1417,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) dwim_remotes_matched); return ret; } else { - return checkout_branch(&opts, &new_branch_info); + return checkout_branch(opts, &new_branch_info); } } From patchwork Thu Nov 29 21:58:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10705391 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 8C297181D for ; Thu, 29 Nov 2018 21:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EB532F9AC for ; Thu, 29 Nov 2018 21:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 731662F9B4; Thu, 29 Nov 2018 21:59:23 +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,FREEMAIL_FROM,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 07CD72F9CA for ; Thu, 29 Nov 2018 21:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726498AbeK3JGP (ORCPT ); Fri, 30 Nov 2018 04:06:15 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:45353 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726410AbeK3JGO (ORCPT ); Fri, 30 Nov 2018 04:06:14 -0500 Received: by mail-lj1-f195.google.com with SMTP id s5-v6so3129965ljd.12 for ; Thu, 29 Nov 2018 13:59:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y02z1xIb8PRvbx6ZfVKDskuPihFlkP+eUcXqnKvHf0Q=; b=BzLYJN+Jfh+bNeJUT4quR3dxaRXJ9SzlSmp8XqDhCJ8RyC14KGf1TBIkT3wkNJ4AeZ fGl1tVMDxo9i9TdBmx/7BPAuSkQFw8Xgnw1UlKIBtjL/ykDZldMLDdKr8dVRgDpmeKq9 fEZSW3injaMx1Jbo9tTcgCLe9QhpqC53GWpCnuZOjElT6FgxiOHzftnniVJdrbKIg/TW NPut4CkgZ8EHXVXvV8ovh+feqznPFyNrsAjjaxQTb8oH5M7tA41LVoRj0nfuQYvEBXk5 Q0xExjCJCPrkp1DTc2cGFA/W7EJIlq6Rr3d4yY2qjPJc/Naq0lmVMCwgarUXJ309s17K 6cRw== 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=y02z1xIb8PRvbx6ZfVKDskuPihFlkP+eUcXqnKvHf0Q=; b=QBzd5aQKu3HABuK0+5ivAVDegFgWkZRLqCGu9xRB9viDgnoRi+VnP4natX08hZXQ16 P7pL5QDGm595NZREZkvX2IJ8lW/RZLW0CPR6k4Y6/4P3ROIdF+rIo3UrEKjF6SU2tgLd f5SjHPfRXauhYfwBfLDoYW9lvXZCZiimbXRcAHsp1/q38p8a00vItN+JbHTv47bFxiVH zh9dU8zlglAatJUzpCbItFjJ/K6u5VmNfkrRLH/4zs3Y5S/sh5ok/mfbrKhyaJ90VVb/ aOIvCc5geCFtW5YcC8AObFw1GbPL2qaavi1GAP4FiTXz/tSzw6CDnbTW9Nlb7sxZxTpi 1fig== X-Gm-Message-State: AA+aEWYFwEn5zuZIwNimQSyeBBB+9nIIOj0KUsm6RjT3oaBHvkN8AgBM Yi57+5WO9EN/eYViLZCHFpg= X-Google-Smtp-Source: AFSGD/UhUsQ3XF1wlL66UWcNMj8Cog/TLzsbHgSoLZtEuHLzwm4lCGl5xxj4304MBq25OPY6VyNSjA== X-Received: by 2002:a2e:4503:: with SMTP id s3-v6mr2274629lja.44.1543528757978; Thu, 29 Nov 2018 13:59:17 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id o17sm489703lff.77.2018.11.29.13.59.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 13:59:17 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, sbeller@google.com, t.gummerer@gmail.com, sxenos@google.com Subject: [PATCH v3 05/14] checkout: move 'confict_style' and 'dwim_..' to checkout_opts Date: Thu, 29 Nov 2018 22:58:40 +0100 Message-Id: <20181129215850.7278-6-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.rc1.380.g3eb999425c.dirty In-Reply-To: <20181129215850.7278-1-pclouds@gmail.com> References: <20181127165211.24763-1-pclouds@gmail.com> <20181129215850.7278-1-pclouds@gmail.com> 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 These local variables are referenced by struct option[]. This struct will soon be broken down, moved away and we can't rely on local variables anymore. Move these two to struct checkout_opts in preparation for that. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 1b19328d0a..2423fdbf94 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -44,6 +44,8 @@ struct checkout_opts { int ignore_skipworktree; int ignore_other_worktrees; int show_progress; + int dwim_new_local_branch; + /* * If new checkout options are added, skip_merge_working_tree * should be updated accordingly. @@ -55,6 +57,7 @@ struct checkout_opts { int new_branch_log; enum branch_track track; struct diff_options diff_options; + char *conflict_style; int branch_exists; const char *prefix; @@ -1239,8 +1242,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) struct checkout_opts real_opts; struct checkout_opts *opts = &real_opts; struct branch_info new_branch_info; - char *conflict_style = NULL; - int dwim_new_local_branch = 1; int dwim_remotes_matched = 0; struct option options[] = { OPT__QUIET(&opts->quiet, N_("suppress progress reporting")), @@ -1265,12 +1266,12 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore, N_("update ignored files (default)"), PARSE_OPT_NOCOMPLETE), - OPT_STRING(0, "conflict", &conflict_style, N_("style"), + OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"), N_("conflict style (merge or diff3)")), OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")), OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, N_("do not limit pathspecs to sparse entries only")), - OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch, + OPT_HIDDEN_BOOL(0, "guess", &opts->dwim_new_local_branch, N_("second guess 'git checkout '")), OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, N_("do not check if another worktree is holding the given ref")), @@ -1286,6 +1287,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts->overwrite_ignore = 1; opts->prefix = prefix; opts->show_progress = -1; + opts->dwim_new_local_branch = 1; git_config(git_checkout_config, opts); @@ -1301,9 +1303,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts->show_progress = isatty(2); } - if (conflict_style) { + if (opts->conflict_style) { opts->merge = 1; /* implied */ - git_xmerge_config("merge.conflictstyle", conflict_style, NULL); + git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL); } if ((!!opts->new_branch + !!opts->new_branch_force + !!opts->new_orphan_branch) > 1) @@ -1350,7 +1352,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) struct object_id rev; int dwim_ok = !opts->patch_mode && - dwim_new_local_branch && + opts->dwim_new_local_branch && opts->track == BRANCH_TRACK_UNSPECIFIED && !opts->new_branch; int n = parse_branchname_arg(argc, argv, dwim_ok, From patchwork Thu Nov 29 21:58:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10705393 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 222AC13A4 for ; Thu, 29 Nov 2018 21:59:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 144342F9AC for ; Thu, 29 Nov 2018 21:59:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08E1F2F9C6; Thu, 29 Nov 2018 21:59:25 +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,FREEMAIL_FROM,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 681662F9AC for ; Thu, 29 Nov 2018 21:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726652AbeK3JGQ (ORCPT ); Fri, 30 Nov 2018 04:06:16 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:37523 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbeK3JGP (ORCPT ); Fri, 30 Nov 2018 04:06:15 -0500 Received: by mail-lj1-f193.google.com with SMTP id e5-v6so3165664lja.4 for ; Thu, 29 Nov 2018 13:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l6+O/Ls7+tqemAUu7fh0OtdUDBxBy3V8DzIG1vgioz8=; b=afv4yz992G8q63eREbNRjsk9PF6jLi2qs1xfqVVbUc7TZDwdeB95y8DFGtKv1Js4b1 +QvbWdrWbHofO4oN6C093VzT95+QCUmEudWNh1OqS0unI52iVtIs7Ethw6d+wQGuiVHW 7F7PyVi8eZWAbhunjaHVSfRtlgFmjnWXuzrsqHDHdRX/X9zxChJboJ+ILOy9N2uYxcD+ 4HZ7XoyxnrscoFbZUsDYMdbqhXTiD8GWH40WJUdkNP/Aqjhewvj5dSGYSEfPy+9Kzicv Z9ZR9ykmOfE6vPgT6uqiiLoRzurw2WGID1raGpbnBj1jOyppGht46JdQ3ekZ469frBK7 G2gw== 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=l6+O/Ls7+tqemAUu7fh0OtdUDBxBy3V8DzIG1vgioz8=; b=tnZKqsQ61y3pEH2GMgMmxxd6kKzh8mRmuIv4fgi2fLtuDPYrcLyTYyZEhoKuj9nly6 7RF3enoyTD+9qeEQhf5UP7La0qMkG7kcQgbIumG+8QTNZG52sP8Fn1IwaaWmXH3HZzgq wL0OkYbwrK0YHRsyrfSDN+z9Vnayf4zEFrBehTGNBshhBXmz6lh8mbDOsjBVUK5F+4qG V4kX4m07agHmRdjV8epfi4Re+EwLrjMKfpRQhtpspmV+JEQNJ/BCToCQ/DZ1C0hTw7BY xTadSnhSAvDgWYzjuDwM0eLeuJgvNVC7L7b7haPMftHDhGIirBi7jGPaGg7wjEGztsZ5 x7XQ== X-Gm-Message-State: AA+aEWawDgmfbN17b1K53iQaYcbSi70rhlhs1ZPu51dqPfQg8Jns0ik4 rtxcOZNeYwKGkKRz/dcUDe4Iyw5R X-Google-Smtp-Source: AFSGD/URltFWYrY5qkR2VidyVydGkdO9TMvCIg36pqpxbwPOABJzJ2FUbh40KdJbutbFm4qHbiNrWg== X-Received: by 2002:a2e:55d3:: with SMTP id g80-v6mr2444249lje.78.1543528759159; Thu, 29 Nov 2018 13:59:19 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id o17sm489703lff.77.2018.11.29.13.59.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 13:59:18 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, sbeller@google.com, t.gummerer@gmail.com, sxenos@google.com Subject: [PATCH v3 06/14] checkout: split options[] array in three pieces Date: Thu, 29 Nov 2018 22:58:41 +0100 Message-Id: <20181129215850.7278-7-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.rc1.380.g3eb999425c.dirty In-Reply-To: <20181129215850.7278-1-pclouds@gmail.com> References: <20181127165211.24763-1-pclouds@gmail.com> <20181129215850.7278-1-pclouds@gmail.com> 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 This is a preparation step for introducing new commands that do parts of what checkout does. There will be two new commands, one is about switching branches, detaching HEAD... one about checking out paths. These share the a subset of command line options. The rest of command line options are separate. Signed-off-by: Nguyễn Thái Ngọc Duy --- builtin/checkout.c | 77 +++++++++++++++++++++++++++++++++------------- parse-options-cb.c | 16 ++++++++++ parse-options.h | 3 +- 3 files changed, 73 insertions(+), 23 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 2423fdbf94..764e1a83a1 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1237,14 +1237,31 @@ static int checkout_branch(struct checkout_opts *opts, return switch_branches(opts, new_branch_info); } -int cmd_checkout(int argc, const char **argv, const char *prefix) +static struct option *add_common_options(struct checkout_opts *opts, + struct option *prevopts) { - struct checkout_opts real_opts; - struct checkout_opts *opts = &real_opts; - struct branch_info new_branch_info; - int dwim_remotes_matched = 0; struct option options[] = { OPT__QUIET(&opts->quiet, N_("suppress progress reporting")), + { OPTION_CALLBACK, 0, "recurse-submodules", NULL, + "checkout", "control recursive updating of submodules", + PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater }, + OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")), + OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"), + PARSE_OPT_NOCOMPLETE), + OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")), + OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"), + N_("conflict style (merge or diff3)")), + OPT_END() + }; + struct option *newopts = parse_options_concat(prevopts, options); + free(prevopts); + return newopts; +} + +static struct option *add_switch_branch_options(struct checkout_opts *opts, + struct option *prevopts) +{ + struct option options[] = { OPT_STRING('b', NULL, &opts->new_branch, N_("branch"), N_("create and checkout a new branch")), OPT_STRING('B', NULL, &opts->new_branch_force, N_("branch"), @@ -1254,33 +1271,44 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"), BRANCH_TRACK_EXPLICIT), OPT_STRING(0, "orphan", &opts->new_orphan_branch, N_("new-branch"), N_("new unparented branch")), + OPT_HIDDEN_BOOL(0, "guess", &opts->dwim_new_local_branch, + N_("second guess 'git checkout '")), + OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, + N_("do not check if another worktree is holding the given ref")), + OPT_END() + }; + struct option *newopts = parse_options_concat(prevopts, options); + free(prevopts); + return newopts; +} + +static struct option *add_checkout_path_options(struct checkout_opts *opts, + struct option *prevopts) +{ + struct option options[] = { OPT_SET_INT_F('2', "ours", &opts->writeout_stage, N_("checkout our version for unmerged files"), 2, PARSE_OPT_NONEG), OPT_SET_INT_F('3', "theirs", &opts->writeout_stage, N_("checkout their version for unmerged files"), 3, PARSE_OPT_NONEG), - OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"), - PARSE_OPT_NOCOMPLETE), - OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")), - OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore, - N_("update ignored files (default)"), - PARSE_OPT_NOCOMPLETE), - OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"), - N_("conflict style (merge or diff3)")), OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")), OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree, N_("do not limit pathspecs to sparse entries only")), - OPT_HIDDEN_BOOL(0, "guess", &opts->dwim_new_local_branch, - N_("second guess 'git checkout '")), - OPT_BOOL(0, "ignore-other-worktrees", &opts->ignore_other_worktrees, - N_("do not check if another worktree is holding the given ref")), - { OPTION_CALLBACK, 0, "recurse-submodules", NULL, - "checkout", "control recursive updating of submodules", - PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater }, - OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")), - OPT_END(), + OPT_END() }; + struct option *newopts = parse_options_concat(prevopts, options); + free(prevopts); + return newopts; +} + +int cmd_checkout(int argc, const char **argv, const char *prefix) +{ + struct checkout_opts real_opts; + struct checkout_opts *opts = &real_opts; + struct branch_info new_branch_info; + int dwim_remotes_matched = 0; + struct option *options = NULL; memset(opts, 0, sizeof(*opts)); memset(&new_branch_info, 0, sizeof(new_branch_info)); @@ -1293,6 +1321,11 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts->track = BRANCH_TRACK_UNSPECIFIED; + options = parse_options_dup(options); + options = add_common_options(opts, options); + options = add_switch_branch_options(opts, options); + options = add_checkout_path_options(opts, options); + argc = parse_options(argc, argv, prefix, options, checkout_usage, PARSE_OPT_KEEP_DASHDASH); diff --git a/parse-options-cb.c b/parse-options-cb.c index 8c9edce52f..f46b3cb0a4 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -121,6 +121,22 @@ int parse_opt_tertiary(const struct option *opt, const char *arg, int unset) return 0; } +struct option *parse_options_dup(const struct option *o) +{ + struct option *opts; + int nr = 0; + + while (o && o->type != OPTION_END) { + nr++; + o++; + } + + CALLOC_ARRAY(opts, nr + 1); + memcpy(opts, o - nr, sizeof(*o) * nr); + opts[nr].type = OPTION_END; + return opts; +} + struct option *parse_options_concat(struct option *a, struct option *b) { struct option *ret; diff --git a/parse-options.h b/parse-options.h index 6c4fe2016d..584cb521f5 100644 --- a/parse-options.h +++ b/parse-options.h @@ -239,7 +239,8 @@ extern int parse_options_step(struct parse_opt_ctx_t *ctx, extern int parse_options_end(struct parse_opt_ctx_t *ctx); -extern struct option *parse_options_concat(struct option *a, struct option *b); +struct option *parse_options_dup(const struct option *a); +struct option *parse_options_concat(struct option *a, struct option *b); /*----- some often used options -----*/ extern int parse_opt_abbrev_cb(const struct option *, const char *, int); From patchwork Thu Nov 29 21:58:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10705411 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 3092F17F0 for ; Thu, 29 Nov 2018 21:59:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 220B82F9B4 for ; Thu, 29 Nov 2018 21:59:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16A9D2F9DA; Thu, 29 Nov 2018 21:59:39 +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,FREEMAIL_FROM,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 61C8C2F9B4 for ; Thu, 29 Nov 2018 21:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726825AbeK3JG3 (ORCPT ); Fri, 30 Nov 2018 04:06:29 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:36370 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726410AbeK3JGS (ORCPT ); Fri, 30 Nov 2018 04:06:18 -0500 Received: by mail-lj1-f196.google.com with SMTP id g11-v6so3161711ljk.3 for ; Thu, 29 Nov 2018 13:59:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sdBHp/nTbWrYRZ0prozY7gej5mMZwainL1ZP3Gm3Tlg=; b=ECVaRG/egZr8vkbpWlTQqgP+P4htxttlB4Z0+Kfnxlc9orzvqYi7GJBCc4dfXwgVLk Wy7F1w2DiMDtk6XpOj5MasZI3lOboD78pvnNWrckWQBU9fhpxq+sEDlOsyCkQ+7+BmS4 959KAf0zp48yvE8Bz4+X/xPvtAMBqgt7NeakYO/4Kd/CA5LgJJ9TdPYipsaRiKOc5DAU ifwrmHVSazvQbU0CymiJnXBiux9p/cleKMSUGAFVmyV0+OJUBXq2FNxlerH4KxnwHD6o POf5O59hWTcHUGiP2vOBvlwzn1Ll9nTDS+4oaXD4UBw3ILT/feGK3Hy8YLmOOOUD9qm7 7XOA== 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=sdBHp/nTbWrYRZ0prozY7gej5mMZwainL1ZP3Gm3Tlg=; b=HnKQOXSqHGI7eLP7prdvYTY1WxtvTkOYo+/emao7R6SNzK3A05nF+lWi3+/sngzdIX JaGEX5UqSAXRJ8Do+QtFSsCXZigvY9wi6Gs6Q5QNpZuK5kcP5dJAyk2/Jt5uPtVdi3/x FWHUvsQ+4LS/na7BBYeAV7hsGXsSvxYc7k8hXBDxvxXzwM3YoQEVhflt/7tupYL+HTMg AQCslTrskevd+iyP1mTVM7nBv+kzBqfB0L1g3vQYajz+5wwtN5Rblhfc+0BH9quANeyg hnm1i7PQMJawypp45O2X3GaeFDMWINpW0/qTkfIR3dp7xGIF8GphTAkWCqDG4Vw3zUiH ahDw== X-Gm-Message-State: AA+aEWbLJftEyjt8P0RbdRfxkRZzUbTMC1JhU6UuZU6RTTdHSnxl2yLx rnIjEcnfgd8hYxm71axpIYM= X-Google-Smtp-Source: AFSGD/XWSU3AQUA4gUUEEJSir1xtVIvXbfjxkT5XSIwICZD98HNP5sEA2QMFWsh6TELSa6tZjQGFdQ== X-Received: by 2002:a2e:7d15:: with SMTP id y21-v6mr1952231ljc.77.1543528760433; Thu, 29 Nov 2018 13:59:20 -0800 (PST) Received: from localhost.localdomain (c80-216-2-165.bredband.comhem.se. [80.216.2.165]) by smtp.gmail.com with ESMTPSA id o17sm489703lff.77.2018.11.29.13.59.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 13:59:19 -0800 (PST) From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: pclouds@gmail.com Cc: avarab@gmail.com, git@vger.kernel.org, gitster@pobox.com, sbeller@google.com, t.gummerer@gmail.com, sxenos@google.com Subject: [PATCH v3 07/14] checkout: split into switch-branch and restore-files Date: Thu, 29 Nov 2018 22:58:42 +0100 Message-Id: <20181129215850.7278-8-pclouds@gmail.com> X-Mailer: git-send-email 2.20.0.rc1.380.g3eb999425c.dirty In-Reply-To: <20181129215850.7278-1-pclouds@gmail.com> References: <20181127165211.24763-1-pclouds@gmail.com> <20181129215850.7278-1-pclouds@gmail.com> 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 "git checkout" doing too many things is a source of confusion for many users (and it even bites old timers sometimes). To rememdy that, the command is now split in two: switch-branch and checkout-files. The good old "git checkout" command is still here and will be until all (or most of users) are sick of it. See the new man pages for the final design of these commands. The actual implementation though is still pretty much the same as "git checkout". Following patches will adjust their behavior to match the man pages. Signed-off-by: Nguyễn Thái Ngọc Duy --- .gitignore | 2 + Documentation/git-checkout.txt | 5 + Documentation/git-restore-files.txt | 167 ++++++++++++++++ Documentation/git-switch-branch.txt | 289 ++++++++++++++++++++++++++++ Makefile | 2 + builtin.h | 2 + builtin/checkout.c | 84 ++++++-- command-list.txt | 2 + git.c | 2 + 9 files changed, 543 insertions(+), 12 deletions(-) create mode 100644 Documentation/git-restore-files.txt create mode 100644 Documentation/git-switch-branch.txt diff --git a/.gitignore b/.gitignore index 0d77ea5894..c63dcb1427 100644 --- a/.gitignore +++ b/.gitignore @@ -143,6 +143,7 @@ /git-request-pull /git-rerere /git-reset +/git-restore-files /git-rev-list /git-rev-parse /git-revert @@ -167,6 +168,7 @@ /git-submodule /git-submodule--helper /git-svn +/git-switch-branch /git-symbolic-ref /git-tag /git-unpack-file diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 25887a6087..25ec7f508f 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -406,6 +406,11 @@ $ edit frotz $ git add frotz ------------ +SEE ALSO +-------- +linkgit:git-switch-branch[1] +linkgit:git-restore-files[1] + GIT --- Part of the linkgit:git[1] suite diff --git a/Documentation/git-restore-files.txt b/Documentation/git-restore-files.txt new file mode 100644 index 0000000000..03c1250ad0 --- /dev/null +++ b/Documentation/git-restore-files.txt @@ -0,0 +1,167 @@ +git-restore-files(1) +==================== + +NAME +---- +git-restore-files - Restore working tree files + +SYNOPSIS +-------- +[verse] +'git restore-files' [-f|--ours|--theirs|-m|--conflict=