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

Re: Notes on supporting Git operations in/on partial Working Directories

From
Junio C Hamano <junkio@cox.net>
Date
Sep 14, 2006, 19:50 UTC
Message-ID
<7vu03a2po8.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<4509A7EC.9090805@gmail.com>
A Large Angry SCM <gitzilla@gmail.com> writes:
Show 18 quoted lines
> The minimum required changes[*1*][*2*][*3*] to the index file to support
> partial checkouts are:
>
> 1) the addition of WD_Prefix string to hold the common path prefix of
> all objects in the working directory. For a full checkout, the WD_Prefix
> string would be empty.
>
> 2) A (new) flag for each entry in the index indicating whether or not
> the object is in the partial checkout.
>
> The contents of the index file still reflect the full tree but flag each
> object (file or symlink) separately as part of the checkout or not. The
> WD_Prefix string is so that a partial checkout consisting of only
> objects somewhere in the a/b/c/d/ tree can be found in the working
> directory without the a/b/c/d/ prefix to the path of the object.
>
> All the Git commands that use the index file will need to be changed to
> support this but the transfer protocols do not need to change.

While this may be a good start, you need a lot more than this if you want to do (1) and (2):

The tree object contained by a commit is by definition a full tree snapshot, so if you want to do a WD_Prefix, you somehow need a way to come up with the final tree that is a combination of what write-tree would write out from such a partial index (i.e. an index that describes only a subdirectory) and the rest of the tree from the current HEAD. I think you can more or less do this change to Porcelain using today's git core. The sequence to emulate it with the today's git would be:

 (1) write-tree (of the WD_Prefix part of the subtree),
 (2) read-tree HEAD (to populate the index fully),
 (3) piping a massaged output from git-ls-files WD_prefix to
     update-index --index-info, followed by read-tree
     --prefix=WD_prefix to swap the partial tree in to
     WD_prefix,
 (4) write-tree (to get the final result).

If you want to do per-path-inside-directory checkout (your 2), this combining step would need to be even more complex. You can do that by hand (reading ls-tree and ls-files and driving update-index --index-info yourself) but it certainly would be more involved. But it's just a matter of Porcelain programming ;-) [*1*].

But a good news is that today's git core lets you work in a sparsely checked out repository without any of the above crap^Wcomplexity, if you drop the WD_Prefix and per path-inside-directory checkout "expectations". Just staying within the directory you are working in, and saying "commit ." when you are tempted to say "commit -a", would be more or less what are needed.

Note. The "git checkout" Porcelain would want to check-out everythingd, so a tool to prepare such a sparsely checked out tree needs to be written if somebody wants to try this, since the above "good news" is only about "working in" a sparsely checked out tree.

[*1*] Obviously you would also need to worry about activities other than making your own changes and committing. When you are always pulling from a single upstream that never rewinds the head, the problem becomes simpler, but for other cases (read: anything that makes distributed version control more interesting and useful) you would need to worry about merges too. What happens when the upstream you based your changes on and the repository you are pulling from today had conflicting changes outside of your area of interest? Without resolving the conflicts, you cannot sanely claim you merged the two branches, and even if you wanted to resolve them yourself, an non-empty WD_prefix would get in your way.

Previous: A Large Angry SCMNext: A Large Angry SCM
Message 4 of 13 in “Notes on supporting Git operations in/on partial Working Directories”
  1. A Large Angry SCMSep 14, 2006
  2. Shawn PearceSep 14, 2006
  3. A Large Angry SCMSep 14, 2006
  4. Junio C HamanoSep 14, 2006
  5. A Large Angry SCMSep 14, 2006
  6. Junio C HamanoSep 15, 2006
  7. A Large Angry SCMSep 15, 2006
  8. Junio C HamanoSep 17, 2006
  9. A Large Angry SCMSep 17, 2006
  10. Jakub NarebskiSep 17, 2006
  11. A Large Angry SCMSep 17, 2006
  12. Jakub NarebskiSep 17, 2006
  13. A Large Angry SCMSep 17, 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.