From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: git.mexon@spamgourmet.com, git@vger.kernel.org
Subject: Re: [PATCH] add: don't write objects with --dry-run
Date: Tue, 12 Oct 2021 13:15:15 -0700 [thread overview]
Message-ID: <xmqqr1cq2e5o.fsf@gitster.g> (raw)
In-Reply-To: <0131d21f-dabd-3da5-34bd-a570e990f9e0@web.de> ("René Scharfe"'s message of "Tue, 12 Oct 2021 21:15:50 +0200")
René Scharfe <l.s.r@web.de> writes:
> When the option --dry-run/-n is given, "git add" doesn't change the
> index, but still writes out new object files. Only hash the latter
> without writing instead to make the run as dry as possible.
>
> Use this opportunity to also make the hash_flags variable unsigned,
> to match the index_path() parameter it is used as.
>
> Reported-by: git.mexon@spamgourmet.com
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> Am I missing something? Do we sometimes rely on the written objects
> within the "git add --dry-run" command?
Good question. I do not think of anything offhand, but this obvious
"omission" makes me suspect that we may be forgetting something.
Thanks.
> read-cache.c | 2 +-
> t/t2200-add-update.sh | 3 +++
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index a78b88a41b..7fcc948077 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -738,7 +738,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
> int intent_only = flags & ADD_CACHE_INTENT;
> int add_option = (ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE|
> (intent_only ? ADD_CACHE_NEW_ONLY : 0));
> - int hash_flags = HASH_WRITE_OBJECT;
> + unsigned hash_flags = pretend ? 0 : HASH_WRITE_OBJECT;
> struct object_id oid;
>
> if (flags & ADD_CACHE_RENORMALIZE)
> diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
> index 45ca35d60a..94c4cb0672 100755
> --- a/t/t2200-add-update.sh
> +++ b/t/t2200-add-update.sh
> @@ -129,12 +129,15 @@ test_expect_success 'add -n -u should not add but just report' '
> echo "remove '\''top'\''"
> ) >expect &&
> before=$(git ls-files -s check top) &&
> + git count-objects -v >objects_before &&
> echo changed >>check &&
> rm -f top &&
> git add -n -u >actual &&
> after=$(git ls-files -s check top) &&
> + git count-objects -v >objects_after &&
>
> test "$before" = "$after" &&
> + test_cmp objects_before objects_after &&
> test_cmp expect actual
>
> '
> --
> 2.33.0
next prev parent reply other threads:[~2021-10-12 20:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 14:55 [BUG] git add -A --dry-run adds files to .git directory git.mexon
2021-10-12 19:15 ` [PATCH] add: don't write objects with --dry-run René Scharfe
2021-10-12 20:15 ` Junio C Hamano [this message]
2021-10-12 20:17 ` Ævar Arnfjörð Bjarmason
2021-10-12 20:37 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqr1cq2e5o.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git.mexon@spamgourmet.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).