From: Phillip Wood <phillip.wood123@gmail.com>
To: Karthik Nayak <karthik.188@gmail.com>,
Abhijeet Sonar <abhijeet.nkt@gmail.com>,
git@vger.kernel.org
Cc: Paul Millar <paul.millar@desy.de>,
Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: Re: [PATCH] describe: refresh the index when 'broken' flag is used
Date: Mon, 24 Jun 2024 12:20:40 +0100 [thread overview]
Message-ID: <054c6ac1-4714-4600-afa5-7e9b6e9b0e72@gmail.com> (raw)
In-Reply-To: <CAOLa=ZRGramQ3MdzzXzZ19yeUB_rQZPbZ3u=eA=T2SfV3nhYOA@mail.gmail.com>
Hi Abhijeet and Karthik
On 24/06/2024 11:56, Karthik Nayak wrote:
> Abhijeet Sonar <abhijeet.nkt@gmail.com> writes:
>
>> When describe is run with 'dirty' flag, we refresh the index
>> to make sure it is in sync with the filesystem before
>> determining if the working tree is dirty. However, this is
>> not done for the codepath where the 'broken' flag is used.
>>
>> This causes `git describe --broken --dirty` to false
>> positively report the worktree being dirty. Refreshing the
>> index before running diff-index fixes the problem.
This is a good description of the problem the patch fixes.
>> Signed-off-by: Abhijeet Sonar <abhijeet.nkt@gmail.com>
>> Reported-by: Paul Millar <paul.millar@desy.de>
>> Suggested-by: Junio C Hamano <gitster@pobox.com>
>> ---
>> builtin/describe.c | 14 ++++++++++++++
>> 1 file changed, 14 insertions(+)
>>
>> diff --git a/builtin/describe.c b/builtin/describe.c
>> index e5287eddf2..2b443c155e 100644
>> --- a/builtin/describe.c
>> +++ b/builtin/describe.c
>> @@ -645,6 +645,20 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
>> if (argc == 0) {
>> if (broken) {
>> struct child_process cp = CHILD_PROCESS_INIT;
>> + struct lock_file index_lock = LOCK_INIT;
>> + int fd;
>> +
>> + setup_work_tree();
>> + prepare_repo_settings(the_repository);
>> + repo_read_index(the_repository);
>> + refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED,
>> + NULL, NULL, NULL);
>> + fd = repo_hold_locked_index(the_repository,
>> + &index_lock, 0);
>> + if (0 <= fd)
>> + repo_update_index_if_able(the_repository, &index_lock);
>> +
As we're dealing with a repository that might be broken I suspect we'd
be better to run "git update-index --unmerged -q --refresh" as a
subprocess in the same way that we run "git diff-index" so that "git
describe --broken" does not die if the index cannot be refreshed.
> I'm wondering why this needs to be done, as I can see, when we use the
> '--broken' flag, we create a child process to run `git diff-index
> --quiet HEAD`. As such, we shouldn't have to refresh the index here.
"git diff-index" and "git diff-files" do not refresh the index. This is
by design so that a script can refresh the index once and run "git
diff-index" several times without wasting time updating the index each time.
> Also apart from that, we should add a test to capture the changes.
That would be nice
Best Wishes
Phillip
>> cp.git_cmd = 1;
>> cp.no_stdin = 1;
>> --
>> 2.45.GIT
next prev parent reply other threads:[~2024-06-24 11:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-23 21:42 [PATCH] describe: refresh the index when 'broken' flag is used Abhijeet Sonar
2024-06-23 21:56 ` Abhijeet Sonar
2024-06-24 10:56 ` Karthik Nayak
2024-06-24 11:20 ` Phillip Wood [this message]
2024-06-24 12:20 ` Abhijeet Sonar
2024-06-24 13:48 ` Abhijeet Sonar
2024-06-24 16:34 ` Junio C Hamano
2024-06-24 17:37 ` Abhijeet Sonar
2024-06-24 17:58 ` Junio C Hamano
2024-06-25 6:40 ` Abhijeet Sonar
2024-06-25 6:44 ` [PATCH v2] " Abhijeet Sonar
2024-06-25 12:27 ` Karthik Nayak
2024-06-25 13:22 ` Abhijeet Sonar
2024-06-25 12:28 ` [PATCH] " Karthik Nayak
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=054c6ac1-4714-4600-afa5-7e9b6e9b0e72@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=abhijeet.nkt@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=paul.millar@desy.de \
--cc=peff@peff.net \
--cc=phillip.wood@dunelm.org.uk \
/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.
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 NNTP newsgroup(s).