Compute patch appliedness from commit DAG
PATCH 1/1 Compute patch appliedness from commit DAG
Don't rely on cached metadata in the "applied" and "unapplied" files to tell which patches are applied. Instead, consider the patches reachable from the branch head to be applied, and the rest unapplied.
The order of the applied patches is also taken from the DAG, but we can't do that for the unapplied patches. So the patch order is saved to a file whenever it changes, and that file is consulted whenever we need to compute the order of the unapplied patches.
The point of this excercise is to let users do things such as "git reset" without confusing stgit. This gives incrased flexibility to power users, and increased safety to other users. The advantages come from the removal of redundant metadata: it is no longer possible for StGIT's appliedness status to get out of sync with the underlying git commit DAG.
This is how the appliedness and order is computed:
* First, a single call to git-show-ref gives the hashes of all patches and the branch head.
* Then, "git-rev-list patch1 patch2 patch3 ^branch" lists a small set of hashes that contains all the unapplied patches and none of the applied patches.
* Last, "git-rev-list head" lists all commits in the branch. The applied patches are listed in the correct order.
This is efficient because none of the two rev-list calls need to look at more than a small part of the DAG. The first call returns a small set of commits, and the last call is abandoned before it has time to look far back in the DAG.
---
I've done some performance testing. First, I ran "stg series" in a Linus kernel tree with 50 applied and 50 unapplied patches (all empty). The performance diff was in the noise, indicating that the DAG walking is indeed cheap per patch, and only has to walk a small part of the commit DAG. Second, I timed stgit's entire test suite: the time increased from 1.5 to 2 minutes. So there is a small overhead that can be seen when you run a gazillion cheap commands, but it remains small even for big trees and doesn't ruin your day.
Comments and suggestions on the algorithm welcome.
stgit/commands/commit.py | 7 - stgit/commands/float.py | 2 stgit/commands/imprt.py | 2 stgit/commands/refresh.py | 2 stgit/commands/sync.py | 2 stgit/git.py | 5 + stgit/stack.py | 324 ++++++++++++++++++++++++++++----------------- 7 files changed, 214 insertions(+), 130 deletions(-)
stgit/commands/commit.py +1 -6
@@ -52,15 +52,10 @@ def func(parser, options, args): if crt_series.get_protected(): raise CmdException, 'This branch is protected. Commit is not permitted' - crt_head = git.get_head() - print 'Committing %d patches...' % len(applied), sys.stdout.flush() - crt_series.pop_patch(applied[0]) - git.switch(crt_head) - for patch in applied: - crt_series.delete_patch(patch) + crt_series.delete_patch_data(patch) print 'done'
stgit/commands/float.py +1 -1
@@ -48,7 +48,7 @@ def func(parser, options, args): check_head_top_equal() unapplied = crt_series.get_unapplied() - applied = crt_series.get_applied() + applied = list(crt_series.get_applied()) # a copy, since we'll modify it all = unapplied + applied if options.series:
stgit/commands/imprt.py +1 -1
@@ -297,7 +297,7 @@ def __create_patch(filename, message, author_name, author_email, else: git.apply_patch(diff = diff) - crt_series.refresh_patch(edit = options.edit, + crt_series.refresh_patch(patch, edit = options.edit, show_patch = options.showpatch) print 'done'
stgit/commands/refresh.py +1 -1
@@ -133,7 +133,7 @@ def func(parser, options, args): if autoresolved == 'yes': resolved_all() - crt_series.refresh_patch(files = args, + crt_series.refresh_patch(patch, files = args, message = options.message, edit = options.edit, show_patch = options.showpatch,
stgit/commands/sync.py +1 -1
@@ -165,7 +165,7 @@ def func(parser, options, args): if git.local_changes(verbose = False): # index (cache) already updated by the git merge. The # backup information was already reset above - crt_series.refresh_patch(cache_update = False, backup = False, + crt_series.refresh_patch(p, cache_update = False, backup = False, log = 'sync') print 'done (updated)' else:
stgit/git.py +4 -1
@@ -189,8 +189,11 @@ def _output_one_line(cmd, file_desc = None): p.childerr.read().strip()) return output -def _output_lines(cmd): +def _output_lines(cmd, input = []): p=popen2.Popen3(cmd, True) + for line in input: + p.tochild.write(line) + p.tochild.close() lines = p.fromchild.readlines() if p.wait(): raise GitException, '%s failed (%s)' % (str(cmd),
stgit/stack.py +205 -119
475 lines not on this page · raw message
PATCH 1/1 Test the new DAG appliedness machinery
---
And here's a test that demonstrates situations where it's useful.
t/t3000-git-interop.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 60 insertions(+), 0 deletions(-)
t/t3000-git-interop.sh new file +60 -0
@@ -0,0 +1,60 @@ +#!/bin/sh +# Copyright (c) 2007 Karl Hasselström +test_description='Test git/StGIT interoperability' +. ./test-lib.sh + +test_expect_success \ + 'Create some git-only history' ' + echo foo > foo.txt && + git add foo.txt && + git commit -a -m foo && + git tag foo-tag && + for i in 0 1 2 3 4; do + echo foo$i >> foo.txt && + git commit -a -m foo$i; + done +' + +test_expect_success \ + 'Initialize the StGIT repository' ' + stg init +' + +test_expect_success \ + 'Create five patches' ' + for i in 0 1 2 3 4; do + stg new p$i -m p$i; + done && + [ "$(echo $(stg applied))" = "p0 p1 p2 p3 p4" ] && + [ "$(echo $(stg unapplied))" = "" ] +' + +test_expect_success \ + 'Pop two patches with git-reset' ' + git reset --hard HEAD~2 && + [ "$(echo $(stg applied))" = "p0 p1 p2" ] && + [ "$(echo $(stg unapplied))" = "p3 p4" ] +' + +test_expect_success \ + 'Create a new patch' ' + stg new q0 -m q0 && + [ "$(echo $(stg applied))" = "p0 p1 p2 q0" ] && + [ "$(echo $(stg unapplied))" = "p3 p4" ] +' + +test_expect_success \ + 'Go to an unapplied patch with with git-reset' ' + git reset --hard $(stg id p3) && + [ "$(echo $(stg applied))" = "p0 p1 p2 p3" ] && + [ "$(echo $(stg unapplied))" = "q0 p4" ] +' + +test_expect_success \ + 'Go back to below the stack base with git-reset' ' + git reset --hard foo-tag && + [ "$(echo $(stg applied))" = "" ] && + [ "$(echo $(stg unapplied))" = "p0 p1 p2 q0 p3 p4" ] +' + +test_done