git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RE: Calculating major.minor.patch from commit hash

From
Randall S. Becker <rsbecker@nexbridge.com>
Date
Feb 13, 2020, 14:46 UTC
Message-ID
<014f01d5e27c$5f5166d0$1df43470$@nexbridge.com>
In-Reply-To
<CAJFfRmt65DV5bZa5yTvg9sDb8SS8dFFyX7Zm23T7mAHL58v1Lw@mail.gmail.com>
On February 13, 2020 9:41 AM, Martin Vejnár wrote:
Show 25 quoted lines
> To: git@vger.kernel.org
> Subject: Calculating major.minor.patch from commit hash
> 
> I'd like my releases to have major.minor.patch version number. While
> increments of major.minor are something one has to do manually, I don't
> want to do that for patch.
> 
> So I was thinking of having a VERSION file in the repo containing major.minor
> and then calculate patch at the given commit C automatically as the length
> of the longest path starting at C in the subgraph containing only commits in
> which VERSION is the same as C's.
> 
> I can do that pretty easily right now by
> 
> * identifying commits in which VERSION changes with `git log -- VERSION`
> and then
> * walking the graph in topo order with `git log --format=format:"%H %P"`.
> 
> The latter step can terminate early, so it doesn't have to walk the entire
> repo, but the latter walks everything and can be quite slow.
> 
> Is there a more efficient way to do this?
> 
> If not, would there be an interest in a new builtin (git-depth?) that would
> calculate the value?
You should consider using annotated tags and the git describe command to derive your release number. We do this for all of our products and it works very well. For example:
$ git tag -a 1.6.4 commit-hash
Then, when building your release:
$ git describe --long --first-parent

Good luck, Randall

-- Brief whoami:
 NonStop developer since approximately 211288444200000000
 UNIX developer since approximately 421664400
-- In my real life, I talk too much.
Previous: Martin VejnárNext: Martin Vejnár
Message 2 of 4 in “Calculating major.minor.patch from commit hash”
  1. Martin VejnárFeb 13, 2020
  2. Randall S. BeckerFeb 13, 2020
  3. Martin VejnárFeb 13, 2020
  4. brian m. carlsonFeb 14, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.