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

Re: Darcs-git: a few notes for Git hackers

From
Daniel Barkalow <barkalow@iabervon.org>
Date
May 10, 2005, 00:07 UTC
Message-ID
<Pine.LNX.4.21.0505091913250.30848-100000@iabervon.org>
In-Reply-To
<7ihdhc5le2.fsf@lanthane.pps.jussieu.fr>
On Mon, 9 May 2005, Juliusz Chroboczek wrote:
Show 18 quoted lines
> Hi,
> 
> Here are a few notes about Git that should probably be taken into
> account by people working on Git itself or on Git wrappers.  The notes
> apply to Linus' Git-0.6, which is the code I'm using in Darcs-git;
> some of them might no longer be applicable to Darcs.
> 
> 
> 1. Darcs-git uses the fact that Git updates are atomic when reading
> from a Git repository.  Darcs-git almost writes to Git repositories
> atomically, with one exception: it performs a non-atomic
> read/update/write cycle on .git/HEAD.
> 
> For that reason, I'm taking a high-level lock on .git repositories
> whenever I write them.  The lockfile is ``.git/lock''.  I haven't
> thought about whether Darcs can be easily coerced into accessing Git
> repos atomically; have people writing Git wrappers found the need for
> a global lock?

I think most things are using the O_CREAT | O_EXCL write to a file and then rename or link/unlink to the desired location. I have some code to do this with refs/*/* as well, and I think people have generally settled on symlinking HEAD to something in refs/heads/. So it shouldn't be necessary to lock the whole repository, unless you're doing some operation like swapping two heads.

Show 10 quoted lines
> 2. The files git.h and git.c in Darcs-git are a simple ``libgit'' that
> contains just enough functionality for Darcs-git; they use the
> functionality of sha1_file.c and read_cache.c from Git-0.6.
> 
> I've found a few problems with the interfaces in these files:
> 
>  - the global variables sha1_file_directory, active_cache, active_nr
>    and active_alloc are not marked ``extern'' in cache.h.  This breaks
>    linkers that don't grok common symbols, such as the one in GHCi
>    (silly GHCi).
Should be trivial to fix.
Show 7 quoted lines
>  - the function write_sha1_file takes the metadata and the data in a
>    contiguous buffer, which is a problem when the data has been
>    allocated by a higher layer.  I'm currently working around the
>    problem by memcpy-ing everything into a temp buffer, but that's
>    obviously not a good thing.  I don't care whether write_sha1_file
>    is changed to use a writev-like interface, or to take the metadata
>    explicitly (as in char *type, unsigned long length).

I've got some patches to make new functions of the write_sha1_file sort easier to write cleanly (for making git-*-pull clean); it wouldn't be too hard to have an open/write/close set.

>  - there is no (usable) function to write a tree; there's the code in
>    write_tree.c, but it's not generally useful.  See the function
>    ``git_write_tree_done'' in git.c for the type of interface I'm
>    thinking of.

I'm working on making this cleaner. Are you wanting to write a tree from something other than a cache?

I can post my patches, but Linus is on vacation, so they couldn't go into the mainline until Friday or so anyway.

	-Daniel
*This .sig left intentionally blank*
Previous: Brad Roberts
Message 12 of 12 in “Darcs-git: a few notes for Git hackers”
  1. Juliusz ChroboczekMay 9, 2005
  2. Petr BaudisMay 9, 2005
  3. Juliusz ChroboczekMay 9, 2005
  4. H. Peter AnvinMay 9, 2005
  5. Juliusz ChroboczekMay 9, 2005
  6. H. Peter AnvinMay 9, 2005
  7. Juliusz ChroboczekMay 9, 2005
  8. Brad RobertsMay 9, 2005
  9. Petr BaudisMay 9, 2005
  10. Junio C HamanoMay 9, 2005
  11. Brad RobertsMay 10, 2005
  12. Daniel BarkalowMay 10, 2005

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.