From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796250986; b=HquO6dxA3+ujT07XluT5CSRsBdw+iGKcPQE/O0ibgumBcD5NsM+zHkRNtnPYXAenwJNh hiYEDRpqcRXCjlkVNN1ckQu7P/Kj+/jODUahHDjXzQhNnq7OvYoqa4wSvRhZnsQeFD+nr Y0PXrX4IYgSjmkMKNs0UkeCunwrO8N9gR9KIpXija8cNB5K5mKcyfPLWcnbwc9bNBcEMH x2IqFPjDYr7d63SnvcmZzgz7CKEsgqNDvgXMGfhNHtvOVDIeb9h40J8RAVKk67EB/Ky0/ Tc0j6WY5khVj+j6IzGkPPVm6JspTjk/ChpvRAA1Yw2398+jFdeVbIGIz7CYbKOOjeVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796250986; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:From:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=0G3Sz+OdeLwB5HPC8kVOX0b8K2+nxZC2rIcvoGw8m/s=; b=iem/WsGMbh/QjymgfZu/tefuCCkVNo1NRte4AIEpQvAX3ABbHUP727LoHAgKIPEhqU0A ttIsrEXic9TkEhWSxjVTATe+Tf52d+3Ew+8wK5utQSq8IRXdyIK58msaBpCOk+WiwSF6X MhYrTZVCbpa7Xvu8LfYAy0lMgDUAiajK7ifrEUULzQdVJymiHYHcqTJkAty7siG2241Xt mCP2wTUgUhio2FIbBpco1at5wM1f1/dBXQOcH/6MsRcR1n+K4QWj5i3iEn5a0Iz+pruUP hxQ4094yoO0noFosaqVAJc7FSOFVhpO5YGYZK3S3xfNH8sUUA23DFbfcFPp3fzVxv4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CyHC8Nfr; arc=none smtp.remote-ip=74.125.82.50 Received: from mail-dl1-f50.google.com (mail-dl1-f50.google.com [74.125.82.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82316606A330 for ; Wed, 2 Dec 2026 22:36:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 82316606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CyHC8Nfr Received: by mail-dl1-f50.google.com with SMTP id a92af1059eb24-1b59dfe466bso7287089c88.1 for ; Wed, 02 Dec 2026 14:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796250985; x=1796855785; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=0G3Sz+OdeLwB5HPC8kVOX0b8K2+nxZC2rIcvoGw8m/s=; b=CyHC8NfrIADvfG9QKlvyFVnu/sWv9sjl6uRXltzsC92JMdVOV0cWejSJNOLGRCRhVG 5skOEYEMpX5qN56Hj6yNgPEIbh+2exrQvQ4/98IB8bc5tNE/fTBAlHVwKYtilgaL2rEq X8oZFrdPNIAdI6CijucDIZJdY4g8YzFnv7MIPLdpsEnuBVNTyw5FV6yHUzG58M5FQL9l qQM0AD/eJdAdbRm59SuNcgsqSd6Gpux7Rt0IcizNe4rAeFeFEHyprclB6YD12AfAuIhD 2MEq256TY1BMlJSm/rvkiTgVPGgDzSf06bF/jL/ds50tcISmVPth4UWkWo3TDzbQRfLR apug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796250985; x=1796855785; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:from:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0G3Sz+OdeLwB5HPC8kVOX0b8K2+nxZC2rIcvoGw8m/s=; b=bgOWBcIcgalmJeK0Hh+0aTDlJw98SzrECNrGwxVcLqiiHpe9eR2Y0J5xeXQwKHk2QL X8c2GI7YIp5CaipA44gGpaml1FPAlIPi+xKtWFWL5UXrWqzoCHm50fnnnedzql+oU4Hl PMBPS+LB0hpeTXqG/4i4Y35HFKfdBQOXUFaau7nE9Obo7N/ptoONMvj9nUsEiL8itpJg LmLTtoFVn7+OHgOWsjNnvXZoDb6uF820FPuR0f4uaKySqYkY/wDeypiTNWCRgA27ngBA 0hFaB70dD5pPueRlGQmyRFgpYK7eERPF+oOSYXpjJTsK9EdCipVS+1QRbuvHWthhWt21 0FnA== X-Forwarded-Encrypted: i=1; AL+hErH6gS6R3UZELzLvnoOao7JQref5u+HoVwAFyXleZ+Z3rNImhsQGCzaeMAPKUWwAZmzQFiM=@vger.kernel.org X-Gm-Message-State: APuU4Z/dLCHc4m6wH+880GMpsfqau/4TCMpTsOkAmEy79ZIna9nhPFWZ ICNyvohyNSguzfIWTwRAfHOa5ef9MbCOaQtX6Lnl6CdY5D4A8JLzyvYb X-Gm-Gg: AZFdTZfUcXRvlJ3AYMPrrLoFjCqafmEjBVnDtfq6Vwnru/q5lYTtwYHa5VvyzmB1Kx6 t5+ahlXpSQ81wa4R4iWCdZvqUbUkeLqnPrFBOaRqmH2mNzPWq1aa32CJMfrpiUs5TFE/evxoT81 IOVTkU3RnGEligxIwT73pD37XodaX8uhPTV6ZqhmqBMsznDa9Q6Sj6oobOQSTsUs16i0ba+bxqQ EjRG70MocQaHq7MlVmYU39Pom8I2g8Z1J94jFiXfQ1Qfa6OZ5J/Nh4fBP9WW+Bm+TH5Z2CCyd1E Sa9C4rA7cGHH3VAwVr2TYFaYdEPHvFEv2YVBu/t2rJwKB6/JUMCdx0I2oQCOyQkZc1hrtjYbJSc eefTW0e6ovesTJIe9rWkHRYqVsowofmDwD/UcJTOd7BdYlrvX4LXvCeQ8rd7RhN4X+yrI/V8po+ 7lHsvUVoyU2ae1PwNj5NeyUhUwu+qbWR1ojfdD4q4F2OnVKgweJ+xD6VkR05Rgk6K0X86VhatFz FU81kCkqes+y7NpOCNVqTh46W8d9dPmlHMo7COWDMc2nlpegifYidacwwfICVPsWOYuwsqqO00j Zx4BW22f9Lq1EcvcYOjW2bV+bjENy2Cc3U945tEKwrU9Kg== X-Received: by 2002:a05:7022:299:20b0:1b5:877b:4894 with SMTP id a92af1059eb24-1b5877b4ae8mr25844346c88.14.1796250985397; Wed, 02 Dec 2026 14:36:25 -0800 (PST) Received: from [10.0.0.168] ([24.10.242.206]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556829d31sm157334939c88.9.2026.12.02.14.36.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 14:36:25 -0800 (PST) Message-ID: <58366597-b3d0-4fd2-9ae5-2cfe1df8dfdc@gmail.com> Date: Wed, 2 Dec 2026 14:36:26 -0800 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] checkout: make orphaned commit checks configurable From: Wyatt Holden To: Junio C Hamano Cc: Wyatt Holden via GitGitGadget , git@vger.kernel.org, stolee@gmail.com, Wyatt Holden References: <6aad1a1cd34a65939be6f64a0d8950e0bc23870a.1794337920.git.gitgitgadget@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Junio, thank you so much for taking a look. My previous email responding to your feedback wasn't in plain text mode. Sorry about that. Here's what I sent over - > What factors are involved in making this > "orphaned commits" check more expensive?  The total number of > branches?  The length of commit chain we are leaving behind? > So, in short, the answer to my earlier question is "we don't know". Yes, we haven't separated the cost of ref enumeration from history traversal in the affected repository. The stack samples at roughly 15, 45, and 75 seconds showed loose-ref filesystem operations inside orphaned_commit_warning(). Skipping the routine with --quiet reduced the observed checkout time from about 204 seconds to 14 seconds. That points to ref enumeration as a contributor, but doesn't tell us how much of the total time it accounts for. I wouldn't want to rule out improving the check based on those observations. The opt-out would let callers that don't need the warning avoid the work, while leaving the default behavior unchanged for ordinary Git users. > I am not sure how justifiable the design decision to leave the > command line option out is. Yeah, I agree. I initially intended the configuration setting for persistent use and git -c for individual invocations, but a dedicated option is more convenient and follows the status.aheadBehind precedent more closely. I've added --[no-]orphaned-commit-warning for both checkout and switch. It overrides checkout.orphanedCommitWarning, so users can also enable the check for an individual invocation when Scalar has disabled it. --quiet retains its existing behavior of skipping the check. I'll include the option, documentation, and tests in v2. > But for human users, what are they losing by passing "-q" when they > do not want to pay the cost of this check because we are not giving > them an easy to use command line option?  What other output are they > declining by "--quiet"?  "The following paths have local changes" > list?  Anything else? Yes, the local change summary, along with the previous HEAD description, branch-switch/reset messages, the new HEAD description when detaching, and upstream tracking information. For our automated runs, the output is also useful to people inspecting the logs, even though the automation itself doesn't consume it. There is a qualification to the progress argument: --quiet --progress can restore progress reporting. Retaining progress alone therefore isn't sufficient justification for the option. The targeted opt-out lets callers retain the other feedback as well. > Another thing I noticed is that the loop in suggest_reattach() stops > showing each commit after showing ORPHAN_CUTOFF but keeps counting. > I wonder if it becomes palatable to introduce a configuration to > stop it early, instead of disabling the orphaned_commit_warning() > altogether? Thanks, that seems worth exploring, especially if we can keep a useful warning while reducing the cost. Looking through the code, I noticed that ref enumeration happens before suggest_reattach(). The UNINTERESTING commits supplied to the walk also cause prepare_revision_walk() to run limit_list(), so reachability traversal happens before the counting loop begins. That makes me unsure how much stopping the counting loop early would save in this case, particularly given the ref enumeration seen in the stack samples. I'd like to measure those parts separately to understand where an early exit would help most. Would it make sense to keep the opt-out in this series and explore a bounded check as a follow-up? That could preserve the warning for users who want it, while callers that don't need it could still skip the work entirely. Thanks again for the thoughtful review and the encouraging comments ⁠:) Wyatt On Tue, Nov 10, 2026 at 2:05 PM Junio C Hamano wrote: "Wyatt Holden via GitGitGadget" writes: > From: Wyatt Holden > > When leaving a detached HEAD, checkout enumerates refs and walks > history to warn about commits left behind. This work can dominate > checkout time even after the working tree has been updated. Interesting. I often am on a detached HEAD but never realized this particular check was expensive.  The size of changes between the HEAD and the next branch would affect the time it needs to update the working tree (the larger the difference, the more expensive to complete the branch switching).  What factors are involved in making this "orphaned commits" check more expensive?  The total number of branches?  The length of commit chain we are leaving behind? I am trying to see if this is something we can aim to optimize or if it is a lost cause and a cop-out to introduce an option to disable the check altogether is the best we can do. > In an automated checkout of an internal monorepo, unpack_trees ended > about 12 seconds into a roughly 204-second run. Stack dumps captured > the main thread in orphaned_commit_warning(), enumerating loose refs > and opening ref files. Using --quiet reduced the observed checkout > time to about 14 seconds, but also suppressed unrelated output. > These observations motivate an opt-out; they do not establish how > much of the delay came from enumeration versus history traversal. So, in short, the answer to my earlier question is "we don't know". > Add checkout.orphanedCommitWarning, enabled by default, so checkout > and switch can skip the check while retaining normal checkout output. > Automated callers can opt out when they do not need a warning about > leaving detached commits behind. Sounds sensible. > Follow the configuration precedent of 06b324c1d71 (status: add > status.aheadbehind setting, 2019-06-18). Unlike status, introduce no > dedicated command-line option; callers can use git -c for a one-off > override. I am not sure how justifiable the design decision to leave the command line option out is. The automation can run with "-q" to omit the overhead altogether, as well as squelching any other output the automation would not read anyway, so I would not worry too much about them. But for human users, what are they losing by passing "-q" when they do not want to pay the cost of this check because we are not giving them an easy to use command line option?  What other output are they declining by "--quiet"?  "The following paths have local changes" list?  Anything else? > Add a Trace2 region around the check to make its cost visible in > future investigations and to verify that disabling the setting skips > the routine rather than merely hiding its warning. Document the > setting and test both checkout and switch. Sounds sensible. > @@ -1132,6 +1134,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne >       struct rev_info revs; >       struct object *object = &old_commit->object; > > +     trace2_region_enter("checkout", "orphaned_commit_warning", the_repository); >       repo_init_revisions(the_repository, &revs, NULL); >       setup_revisions(0, NULL, &revs, NULL); > > @@ -1155,6 +1158,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne >       /* Clean up objects used, as they will be reused. */ >       repo_clear_commit_marks(the_repository, ALL_REV_FLAGS); >       release_revisions(&revs); > +     trace2_region_leave("checkout", "orphaned_commit_warning", the_repository); >  } Quite straightforward.  There is no early return in the middle, so entering at the beginning with leaving at the end is the only change necessary. > @@ -1253,8 +1257,14 @@ static int switch_branches(const struct checkout_opts *opts, >               } >       } > > -     if (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit) > -  orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit); > +     if (!opts->quiet && !old_branch_info.path && old_branch_info.commit && > +         new_branch_info->commit != old_branch_info.commit) { > +             if (opts->orphaned_commit_warning) > +  orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit); > +             else > +                     describe_detached_head(_("Previous HEAD position was"), > + old_branch_info.commit); > +     } OK.  The call into suggest_reattach() via orphaned_commit_warning() is the more expensive part, and it also is where "Previous HEAD was" comes, which we do not want to lose.  It makes sense. Another thing I noticed is that the loop in suggest_reattach() stops showing each commit after showing ORPHAN_CUTOFF but keeps counting. I wonder if it becomes palatable to introduce a configuration to stop it early, instead of disabling the orphaned_commit_warning() altogether?