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

Re: Question about possible git races

From
Andreas Ericsson <ae@op5.se>
Date
Mar 22, 2006, 23:28 UTC
Message-ID
<4421DD9E.7030201@op5.se>
In-Reply-To
<200603201724.12442.astralstorm@o2.pl>
Radoslaw Szkodzinski wrote:
> I'd like to write a multithreaded application using git,

Why on earth? The git tools aren't written to be thread-safe in that manner, so you'll run into all sorts of problems. Unless you're talking about managing the code for a multithreaded application with git, in which case you should just go read the tutorial. However, feeling slightly tipsy and in a distinctly good mood, I shall try to answer your questions anyway.

Show 7 quoted lines
> so I'd like to see if 
> there are any races:
> 
> - push vs pull
> One thread pushes to the repository while another is pulling from it at the 
> same time. I should get the older commit.
> 

You will. Git atomizes (atomicizes? atomicifies?) pushes by updating the branch head being pushed to after all the commit-, tree- and blob-objects are written. Tags are handled separately but equally atomically.

Show 8 quoted lines
> - push vs push
> Both threads push at the same time. What happens?
> Any good way to merge those pushes?
> (I have full access to both repos)
> 
> Possibly those two aren't fast-forward of each other.
> I think one of the pushes should abort in this case unless I force it.
> 

Read the source to find out if it's locking the repo while updating or not (I think it is, but I'm not sure). If it isn't the last one to finish pushing wins out since the branch head update from that push will overwrite the previous one.

Show 6 quoted lines
> - fetch vs fetch
> I mean that two threads try to fetch from different repositories to a single 
> one. Possibly those two aren't fast-forward of each other.
> Any good way to merge those fetches?
> (I have full access to both repos)
> 
git help octopus

You can fetch those two remote branch heads to local branches simultaneously and then do the octopus in the master-thread while no other updates are happening. Doing several simultanous merges to a single branch is quite frankly so insane I have to go get myself a drink just from thinking about it.

> I'm meaning really bare git there, w/o bash+perl scripts.
> 

I don't think you can do it without Python. The default merge strategy is written in python, so.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Previous: Andreas EricssonNext: Radoslaw Szkodzinski
Message 4 of 10 in “Question about possible git races”
  1. Radoslaw SzkodzinskiMar 20, 2006
  2. Radoslaw SzkodzinskiMar 22, 2006
  3. Andreas EricssonMar 22, 2006
  4. Andreas EricssonMar 22, 2006
  5. Radoslaw SzkodzinskiMar 23, 2006
  6. Andreas EricssonMar 23, 2006
  7. Radoslaw SzkodzinskiMar 23, 2006
  8. Junio C HamanoMar 23, 2006
  9. Radoslaw SzkodzinskiMar 23, 2006
  10. Junio C HamanoMar 23, 2006

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.