threads / discuss / 3339

StGIT refreshes all added files - limitation of git-write-tree?

Subject: StGIT refreshes all added files - limitation of git-write-tree?

## tl;dr

4 messages between Feb 15, 2006 and Feb 15, 2006.

replies: 3people: 3as markdown or json

Pavel Roskin· Feb 15, 2006, 04:42 UTC · lore
Hello!

Current StGIT would refresh all added files on "stg refresh", even if they are not specified on the command line. I believe the same is true for removed files.

That's when it can hurt. I apply a large patch that modifies and adds several files. I want to split the patch into several StGIT patches by selecting which files belong to which patch. All files that need to be modified are already modifies. It's natural that I add new files using "stg add" at this stage. To me, adding files looks very similar to modifying them. However, then I create a patch by "stg new" and commit _some_ files to it using "stg refresh" with those files on the command line, I discover that _all_ added files have been refreshed.

The only workaround seems to be to add only those files that will be included in the current patch. The same should be true for renamed files.

Debugging StGIT shows that it builds correct lists of the files to be included in the current patch (update_cache in git.py), but they are never used. Instead, StGIT runs "git-write-tree" without arguments (commit in git.py). While StGIT is careful to only add user-specified modified files to the directory cache, it does nothing to the added files, which are in the cache already.

Purely StGIT way of handling this problem would be to remove added files from the directory cache if they are not being committed. The problem is, "stg add" uses the cache, so this would undo "stg add" on files unused in the current operation. Either StGIT should restore files in the cache after the refresh, or there should be a separate StGIT cache that "stg add" would work on. The former is potentially unreliable (what if refresh is interrupted), the later creates an extra layer, another directory cache no less, this reducing usability of the pure git commands.

Another approach would be to get rid of "stg add" and "stg rm" and use "stg refresh --add" and "stg refresh --rm" to add files to the current patch or to remove them. It does feel like removal of a useful feature, since "stg diff" without arguments will no longer show added or removed files. Adding and removing files would be too immediate compared to modifying them.

What I really hope to hear is that there is or there will be a git based solution. Either git-write-tree could be changed to only process files specified on the command line, or there should be some other command doing that.

Or maybe git-write-tree and other utilities could be changed to work on a copy of the index file? I would prefer not to move the actual .git/index away, but to make a copy for the current "stg refresh" operation.

-- 
Regards,
Pavel Roskin
Junio C Hamano· Feb 15, 2006, 06:20 UTC · re: Pavel Roskin · lore

Re: StGIT refreshes all added files - limitation of git-write-tree?

Pavel Roskin <proski@gnu.org> writes:
> Or maybe git-write-tree and other utilities could be changed to work on
> a copy of the index file?  I would prefer not to move the
> actual .git/index away, but to make a copy for the current "stg refresh"
> operation.
There is no need to change the core side.  
	GIT_INDEX_FILE=temporary-index git-write-tree

would do the job. See the current round of git-commit and how it handles "git commit --only these files" case.

Pavel Roskin· Feb 15, 2006, 09:06 UTC · re: Junio C Hamano · lore

Re: StGIT refreshes all added files - limitation of git-write-tree?

On Tue, 2006-02-14 at 22:20 -0800, Junio C Hamano wrote:
Show 13 quoted lines
> Pavel Roskin <proski@gnu.org> writes:
> 
> > Or maybe git-write-tree and other utilities could be changed to work on
> > a copy of the index file?  I would prefer not to move the
> > actual .git/index away, but to make a copy for the current "stg refresh"
> > operation.
> 
> There is no need to change the core side.  
> 
> 	GIT_INDEX_FILE=temporary-index git-write-tree
> 
> would do the job.  See the current round of git-commit and how
> it handles "git commit --only these files" case.

Thank you! It's comforting to know that the issue is not unique to StGIT.

-- 
Regards,
Pavel Roskin
Shawn Pearce· Feb 15, 2006, 06:28 UTC · re: Pavel Roskin · lore

Re: StGIT refreshes all added files - limitation of git-write-tree?

Pavel Roskin <proski@gnu.org> wrote:
> Or maybe git-write-tree and other utilities could be changed to work on
> a copy of the index file?  I would prefer not to move the
> actual .git/index away, but to make a copy for the current "stg refresh"
> operation.

git-write-tree pays attention to the GIT_INDEX_FILE environment variable; if this, GIT_DIR and GIT_OBJECT_DIRECTORY are set you can redirect git-write-tree to look at a different index. One way to create a tree from a mixture of your current index and the current HEAD's tree is to set GIT_INDEX_FILE to a temporary file name (which doesn't exist), use git-read-tree to load the current tree unmodified into that index, copy the modified records of interest from the current index to the temporary index, then git-write-tree from the temporary index. But now you need to update your current index with the real SHA1s of the written files.

Somewhat convoluted. I think that git-commit.sh and cg-commit.sh play such games to do partial commits based on what the user has passed on the command line or modified in their editor (which is actually a rather cool feature of Cogito). I'm using a similar trick in pg to load binary objects from a patch directory (for a specific use case that I have). git-am.sh uses a similar trick to perform a 3 way merge if git-apply fails.

-- 
Shawn.

← back to recent threads