Article View: linux.kernel.git
Article #905[PATCH v3 3/7] stash push: remove duplicate changes detection
From: Phillip Wood
Date: Tue, 20 Oct 2026 15:20
Date: Tue, 20 Oct 2026 15:20
90 lines
14091 bytes
14091 bytes
From: Phillip Wood <phillip.wood@dunelm.org.uk>
Before it creates a stash, git checks if there are any unstaged, or
uncommitted changes. If there isn't anything to stash it bails out. "git
stash push" checks for changes twice, once in do_push_stash() and then
again in do_create_stash(). While duplicating the checks for staged and
unstaged charges is fairly cheap because they stop after finding the
first changed path, if we're stashing untracked files then we visit
them all twice. Avoid that by removing the call to check_changes()
from do_push_stash() and checking the return value of do_create_stash()
to see if there were any changes to stash. If check_changes() finds
there are no changes do_create_stash() now returns CREATE_NO_CHANGES
rather than CREATE_EMPTY. This enables us to distinguish between there
being no changes and there being nothing stashed, so that "git stash
push --patch" when nothing is selected, and "git stash push --staged"
when the index matches HEAD, still exit 1 rather than 0.
As we're not calling check_changes() in do_push_stash() anymore, we do
not need to refresh the index there either because do_create_stash()
refreshes it again before calling check_changes(). Avoiding the extra
index refresh saves us two lstat() calls per changed path.
There is still one small change in behavior as, if there is nothing
to stash, we'll now try to create the reflog for stashes before we
realize that there is nothing to stash. I don't think that should
matter in practice.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
builtin/stash.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/builtin/stash.c b/builtin/stash.c
index f461f002e5..aec79ed473 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1338,6 +1338,8 @@ enum create_result {
CREATE_SUCCESS,
/* No changes were stashed */
CREATE_EMPTY,
+ /* There were no changes to stash */
+ CREATE_NO_CHANGES,
};
static enum create_result stash_staged(struct stash_info *info,
@@ -1542,7 +1544,7 @@ static enum create_result do_create_stash(const struct pathspec *ps,
}
if (!check_changes(ps, include_untracked, &untracked_files)) {
- ret = CREATE_EMPTY;
+ ret = CREATE_NO_CHANGES;
goto done;
}
@@ -1724,18 +1726,6 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
free(ps_matched);
}
- if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
- NULL, NULL, NULL)) {
- ret = error(_("could not write index"));
- goto done;
- }
-
- if (!check_changes(ps, include_untracked, &untracked_files)) {
- if (!quiet)
- printf_ln(_("No local changes to save"));
- goto done;
- }
-
if (!refs_reflog_exists(get_main_ref_store(the_repository), ref_stash) && do_clear_stash()) {
ret = -1;
if (!quiet)
@@ -1748,7 +1738,12 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
create_res = do_create_stash(ps, &stash_msg_buf, include_untracked,
patch_mode, interactive_opts, only_staged,
&info, &patch, quiet);
- if (create_res != CREATE_SUCCESS) {
+ if (create_res == CREATE_NO_CHANGES) {
+ if (!quiet)
+ printf_ln(_("No local changes to save"));
+ ret = 0;
+ goto done;
+ } else if (create_res != CREATE_SUCCESS) {
ret = -1;
goto done;
}
--
2.56.0.134.g299a3c16181
Technical Details
Message-ID:
<36fc0eb9130bda0ccae507433b6780c01fb28509.1792509606.git.phillip.wood@dunelm.org.uk>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72551-linux-kernel-git=dewy.ruReferences:
<cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1792509606.git.phillip.wood@dunelm.org.uk>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-72551-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: [PATCH v3 3/7] stash push: remove duplicate changes detection
Date: Tue, 20 Oct 2026 16:20:38 +0100
Organization: Usenet Network
Message-ID: <36fc0eb9130bda0ccae507433b6780c01fb28509.1792509606.git.phillip.wood@dunelm.org.uk>
References: <cover.1791218125.git.phillip.wood@dunelm.org.uk> <cover.1792509606.git.phillip.wood@dunelm.org.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="3883116"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VxzWvjo7wa/IQ1BWj+vw7b0p/Sk= sha256:JrUICGHsf4Q4r9c+n3sb21zAaXJFk9adCF/cC5CE4xg=
sha1:ijQwjkJ1LyREONl1KR3++lTga+s= sha256:LgiUVj+D4AoHVFG/vGiJ4FTHPjjMPJe17jB/iU93lWc=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id AF4B6110D4D; Tue, 20 Oct 2026 18:27:50 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id qzwLOHdERg0e;
Tue, 20 Oct 2026 18:27:48 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72551-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id B8694110D19; Tue, 20 Oct 2026 18:27:38 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 968A3480B4; Tue, 20 Oct 2026 15:21:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1792509663;
b=e8CiisL8opyyZVg9b5S9JO8H3cMDJZnCFMs88fIS3LyLgKSQSfcPOqcONayVGrQ1fDGU
WMt/kG2byj7vXJGuy5oMRfVbS2532UKhjTfRZmqTzmXrcDDVxXrS134LZTzU9yKciEUnK
q8WuMzThhqFjbmxIjJfUcHlbBFhhwmCLzfwZqFZZQdayZ9k7Z9OSkvkmTKcQZZtIHWtDZ
q2DSswFd++G1tsLhG8pE5Fs0/fNo1vT0z3cOrgX8MaoN0kcmXj+kqZbgl2ewZSKeRjrCD
AF+etznZDvB9fACyy+seOd97UNEypecaB1qnieHeTb9nlKrbK+PYeudmzSzJyaiArLA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792509663;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:Reply-To:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=X0fr6zOqrFNU1/4gCCKANeLjTcQcsgshxq8vko/FYa4=;
b=fz+lhVOjs1VhBPgzctqh2YeaUyMnGd9PXFkWpPWSWZEWL56sOkzXQp2CVy6VcIwrwkpG
eQ8ZjAH4jCVV9VbZ2aR4ECX5gKbilLAex8v7iLUE4BPffYnKYHIkR4TNTZ22/OrmOgWX1
6zI7fwHkHNKUevGFgU/vIIBige/LIcJi66pdwC7X4h6spnHxmZoFmIN3eZl5wbu4igjFE
KVNda21RTaGOy90Qlox3XWH2WwCue4dwJT2nYI6Nr6qbfPnzcXDGow19SkASnAdQM38SR
GjjR2j17OoWEhESslXZAgN0VBXmnrXZ4enjSS8B6kVtwZ0ZTK2M2qQfdpgavKkrM+gQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=Kbv9HeLw;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id B420160A380C;
Tue, 20 Oct 2026 15:21:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=Kbv9HeLw
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1792509662;
b=ejtCZiHqH44Tt4+wvYt4rl54JBteZqYFlI1EiydTkLVDSUpP6N5p7vYm+4Fl/kdi41os
AQ9OIply52v7dSvUKMDcrkLZaMlG0hMV1FWEGUNT8YY2zufrDvGizdHyxbFtabb1uLUeY
QCB45BEOWQR82f8a4nLI1y07IvKvujmgStvKdxbm3SHT+m6pFDrV3UQ9FhYrTwtTaqx4s
Zlf9l1pIQ0LIxuHIuJAUuczK1Vraj72DeoMSXHRGB1ORbl1GLORIZpu1km7UixtcQwDvJ
lieWx599wL76MHYTUPYFH0TKSAFWkeMoQ7LMlIIuUh0pviMBATcRyPtE9QjF7caZ4JQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1792509662;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:Reply-To:MIME-Version:
Content-Transfer-Encoding;
bh=X0fr6zOqrFNU1/4gCCKANeLjTcQcsgshxq8vko/FYa4=;
b=qkVyLoyDpeCCqAqDDStMdokWLfOfb33dSsToleCcXy0o7Kv+i5DkamgUKNehPP6TkAEU
VnA5fK9jahEXO6pW9+QM/XfHm8V0GLWoa4cQ5CDbhuq61/D4qlC3To2v94ZCDSvTWSOOX
s3sk1B2/oe9e+nPGQk3O50tcYpeNWorl4zdvAtcZJxAnUOP/pGwdpbishu5bUjDZddtUd
ek7Lrc2mBzxpo+mPpeMzaZrIg88i/vy2y6jK7Xol2FJZzymWXYoHWxfxr/UXTlt6nvJIW
gid6FbmsWQyvpKE8WOmfSVb5getY6ePEZSZzcIS8sD7/vrDEOrzMRJnd4vsPziRPR7g==
X-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=20251104 header.b=Kbv9HeLw;
arc=none smtp.remote-ip=209.85.221.43
X-Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43])
(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 7F2EF60A2637
for <git@vger.kernel.org>; Tue, 20 Oct 2026 15:21:02 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F2EF60A2637
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-48b060ec084so2417573f8f.0
for <git@vger.kernel.org>; Tue, 20 Oct 2026 08:21:02 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1792509661; x=1793114461; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:reply-to:references
:in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=X0fr6zOqrFNU1/4gCCKANeLjTcQcsgshxq8vko/FYa4=;
b=Kbv9HeLwkQN1G7+/O1gyDlFWulvKFzY/tXQ10KXpty7sDxgf4QKw83a1PqdpIEhve2
PAm4rb1kMvZGel148N/cVV1PGFPV6KZv2QUjTVSKcMti8aF+s3zUCL8WwKLxSIx5Tdpn
gxnPcS+I1a06B5IVdt1a11hNclgsvN0li/UEjCGWqVULRcKVEaD9HcAR6xn+q4F+nu7M
xaHeDqeLSvZ5kt2hB9wBSCGO1zZ1eg+dvrfNAi3iJGqb6KaeoRQD+yGluyJrAeZEsFId
UoN+753QqQEmU2/JaCn0biPj9z7dWarDpKW7DfVB+THs2hn6NSy//4PMVnM4xJBWHMkc
NySg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1792509661; x=1793114461;
h=content-transfer-encoding:mime-version:reply-to:references
:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=X0fr6zOqrFNU1/4gCCKANeLjTcQcsgshxq8v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id ffacd0b85a97d-48e07fa96e2mr22403030f8f.44.1792509659396;
Tue, 20 Oct 2026 08:20:59 -0700 (PDT)
X-Received: from berwick ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e1d823ca7sm6307355f8f.38.2026.10.20.08.20.58
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 20 Oct 2026 08:20:58 -0700 (PDT)
X-Cc: ιη°δΈθ <kazumasa.shigeta@kanamei.com>,
Phillip Wood <phillip.wood123@gmail.com>
X-Mailer: git-send-email 2.56.0.134.g299a3c16181
X-In-Reply-To: <cover.1792509606.git.phillip.wood@dunelm.org.uk>
X-Reply-To: Phillip Wood <phillip.wood@dunelm.org.uk>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list