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

Re: Modifying a bare repo directly

From
Jeff King <peff@peff.net>
Date
Apr 12, 2017, 00:48 UTC
Message-ID
<20170412004818.xcguj3ndyfixnthy@sigill.intra.peff.net>
In-Reply-To
<CAG_DJY=3Q1hcGnD72hwhdHxVReD4g7JZou=cm32_WECoJf+5nA@mail.gmail.com>
On Tue, Apr 11, 2017 at 10:35:17PM +0100, Julian Goacher wrote:
> Thanks for the replies; is there anything that needs to be known about
> concurrent updates on a repo when using plumbing commands?

Concurrent writes to the object database are always safe (so hash-object, write-tree, commit-tree are fine). Updates to the index will take a lock on the index; use a unique GIT_INDEX_FILE if you want multiple independent updates to avoid conflicting with each other.

So all of that should be able to proceed independently. The place where you might see conflicts is when you actually update the branch. The locking there uses a "lease" system:

  1. At the start of the operation, you note that the branch is at some
     sha1 X.
  2. When you're ready to write, you feed update-ref the refname, the
     new sha1, and that original sha1.
  3. Update-ref takes a lock, checks that we are still at the old sha1,
     and then atomically writes the new sha1.

So if you have updates to multiple independent branches, they'll never conflict. If you have multiple updates to the same branch, they may race, but you'll never "lose" an update; each one will either succeed or fail. Just make sure you pass the "old" sha1 to update-ref (the example I posted did so).

-Peff
Previous: Julian Goacher
Message 6 of 6 in “Modifying a bare repo directly”
  1. Julian GoacherApr 10, 2017
  2. Ævar Arnfjörð BjarmasonApr 10, 2017
  3. Jeff KingApr 10, 2017
  4. Eric WongApr 10, 2017
  5. Julian GoacherApr 11, 2017
  6. Jeff KingApr 12, 2017

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.