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

Re: git (commit|tag) atomicity

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 28, 2012, 17:41 UTC
Message-ID
<m3aa42vosb.fsf@localhost.localdomain>
In-Reply-To
<CADWOt=ig5=Bhhkjs9-wbm2djtwWPOfPGtYt9pH-U3YuQ+iyXzg@mail.gmail.com>
Jon Jagger <jon@jaggersoft.com> writes:
Show 26 quoted lines
> On Tue, Feb 28, 2012 at 4:46 PM, Holger Hellmuth <hellmuth@ira.uka.de> wrote:
> > On 28.02.2012 16:40, Jon Jagger wrote:
>>>
>>> I don't know a lot about git - I use it as a tool behind
>>> http://cyber-dojo.com
>>> which is an online coding dojo server.
>>> I have a quick question...
>>> If I do a
>>>    git commit ....
>>> in one thread and a
>>>    git tag | sort -g
>>> in another thread is the output of the git tag guaranteed to be atomic?
>>
>> Can a "git commit" add or remove tags? AFAIK it can't and so the two
>> commands don't conflict in any way.
> 
> Sorry, I failed to ask the question I really wanted to ask...
> 
> I mean in one thread
>    git tag -m 'AAA' BBB HEAD
> and in another thread
>    git tag | sort -g
> 
> and the question is whether the output of the git tag|sort -g command
> is guaranteed to be from before the git tag -m... or from after the
> git tag -m... but not "interleaved" in any way....

Creating a tag or a commit is guaranteed to be atomic. Git first atomically adds tag or a commit to object database (atomic file write) as loose object, then atomically writes tag reference as loose tag ('.git/refs/tags/foo' file, containing SHA-1 id of newly created tag).

"git tag", which list all tags, recursively scans (reads) 'refs/tags/' directory, so it could theoretically happen that if you have very large number of loose (unpacked) tags, "git tag" might theoretically list tag 'zzz' created after start of command, but not list 'aaa' tag created after start of command.

But I am not sure... that probably depends on how opendir(3) and readdir(3) works on given filesystem wrt. updates to opened directory. I think VFS on Linux ensures that you see view of filesystem as it was on opendir().

-- 
Jakub Narebski
Previous: Jon JaggerNext: Zach Brown
Message 4 of 6 in “git (commit|tag) atomicity”
  1. Jon JaggerFeb 28, 2012
  2. Holger HellmuthFeb 28, 2012
  3. Jon JaggerFeb 28, 2012
  4. Jakub NarebskiFeb 28, 2012
  5. Zach BrownFeb 28, 2012
  6. Jon JaggerFeb 28, 2012

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.