From: John Garry <john.garry@huawei.com>
To: Glen Choo <chooglen@google.com>, <git@vger.kernel.org>
Subject: Re: [Question] .git folder file updates for changing head commit
Date: Thu, 24 Mar 2022 12:59:45 +0000 [thread overview]
Message-ID: <5ceff005-bbe4-37f5-c453-17008c2167bc@huawei.com> (raw)
In-Reply-To: <kl6la6dgtmv8.fsf@chooglen-macbookpro.roam.corp.google.com>
On 23/03/2022 20:50, Glen Choo wrote:
> Hi John, I'm not a big expert on Make (or even Git :p) but think I can
> answer some of your questions.
>
> John Garry <john.garry@huawei.com> writes:
>
>> Hi guys,
>>
>> I have a question about which files in the .git folder are updated as we
>> change the head commit. I could check the codebase myself but prob will
>> make a mistake and maybe some expert would be so kind as to just kindly
>> tell me.
>>
>> For building the linux perf tool we use the git head commit id as part
>> of the tool version sting. To save time in re-building, the Makefile
>> rule has a dependency on .git/HEAD for rebuilding. An alternative
>> approach would be to compare git log output to check current versus
>> previous build head commit, but that is seen as inefficient time-wise.
>
> You're on the right track because if .git/HEAD doesn't change, the HEAD
> is still pointing to either the same commit (if in detached HEAD) or
> branch (if not in detached HEAD).
>
> The problem is that when HEAD points to a branch, the branch's 'head
> commit' can change, implicitly changing the commit that .git/HEAD
> actually points to.
>
ok
>> The problem is that actions like git cherry-pick and git reset --hard
>> HEAD^ may not update .git/HEAD (so don't trigger a rebuild).
>
> That's what's happening here. If your HEAD is pointing to
> "refs/heads/main", "cherry-pick" and "reset --hard" will change where
> "refs/heads/main" points, but HEAD still points to "refs/heads/main".
>
> Branches are often located in "loose form" under .git/refs/heads/*,
> *but* refs can also be stored in a "packed form" under .git/packed-refs
> (https://git-scm.com/docs/git-pack-refs). There is also a relatively
> new ref storage format called reftable that I'm not familiar with, but
> presumably stores its refs in other locations too.
>
> All of this is to say that depending on specific files under .git/
> exposes you to a lot of Git internals that really aren't meant for
> external consumption. I suggest finding a different approach than
> watching Git-internal files for changes.
Thanks for the detailed explanation.
I agree with your suggestion to find a new method (which may be
reverting to the old method to just run proper git commands).
>
>> Is there some more suitable file(s) which we could use as a dependency?
>> From my limited experimentation, .git/index seems to always update when
>> the changing head commit.
>
> I think users typically expect the index (and therefore .git/index) to
> change when the head commit changes, but this isn't always true e.g.
> "reset --soft" will move the branch without changing the index.
ok, good to know. I was going to try that...
>
> P.S. Even if you knew the value of .git/index or .git/HEAD, that
> wouldn't tell you whether or not the files in your working directory
> have changed, so I'm not sure if you want to use either as Makefile
> dependency.
>
ok, thanks again for all this info,
John
next prev parent reply other threads:[~2022-03-24 12:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-23 15:19 [Question] .git folder file updates for changing head commit John Garry
2022-03-23 20:25 ` Taylor Blau
2022-03-24 12:56 ` John Garry
2022-03-27 15:48 ` Ævar Arnfjörð Bjarmason
2022-03-30 10:48 ` John Garry
2022-03-23 20:50 ` Glen Choo
2022-03-24 12:59 ` John Garry [this message]
2022-03-23 21:28 ` Andreas Schwab
2022-03-24 13:00 ` John Garry
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=5ceff005-bbe4-37f5-c453-17008c2167bc@huawei.com \
--to=john.garry@huawei.com \
--cc=chooglen@google.com \
--cc=git@vger.kernel.org \
/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).