Re: Support with finding git objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-03-01 at 19:06:29, Ayoub, Toufic wrote:
> Hello everyone,

Hey,

> Hope this message finds you. I need your support regarding an issue my team is facing.
> We have a code in our SW which shall display the date of the git commit. There is a path in the code that if it is executed on a platform where git is not installed, that this commit date shall be found by looking at:
> 1.      Reading from HEAD file the commit hash
> 2.      Searching for this commit hash under .git/objects
> The problem we are facing is that sometimes, when the default master branch is updated with the newest commit, this commit will not be found locally, even after doing git pull and so on...
> The commit can be found with:
> 1.      git log
> 2.      git cat-file -t <commit hash> -> it returns "commit"
> 3.      git reflog
> 
> but the strange thing is that we can neither find it under .git/objects/ nor under .git/objects/pack (although that is the newest commit and shall not be packed).

I think you're maybe making some assumptions about when loose objects
are and are not created that Git doesn't guarantee.  For example, if
you're doing a `git pull` or `git fetch`, it is entirely possible that
the objects downloaded remain in a pack.  In fact, by default, Git will
leave large fetches as packs to avoid an explosion of loose objects.

Note that the name of a pack is based on the hash of the entire pack
contents, not based on the items it contains (although obviously those
influence the pack contents).

> Can you please provide support by:
> 1.      telling me it that is an issue or is it expected?

I believe this is expected.

> 2.      If that is expected, where shall we find this commit object to retrieve the commit message and date from it (without running git commands)?

Sorry, but you're going to need to use Git commands to do this.  You
could also use libgit2, but that doesn't work with SHA-256 repositories
or certain other features.

> 3.      Or recommending me some other solution

I assume that you're building this software on a machine that _does_
have Git, so you could generate a file during the build process that
includes the commit date, commit hash, and any other information you
want.  This is easy to do for compiled languages, but it's also possible
to generate something like a version.rb file for Ruby or the like as
part of your build process.

In the interests of reproducible builds, you will of course want to use
the commit metadata and not the actual timestamp of building.

If that doesn't work for you, maybe you could tell us a little bit about
your goal with this process and what you're using it for, and we can
help you more then.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux