A few small fixes
cover A few small fixes
These are available from
git://repo.or.cz/stgit/kha.git safe
The clean test and the assimilare/repair stuff are new, the rest have been sitting in kha/safe for a while now.
David: I believe the repair patch should fix the situation you encountered.
---
Note how the actual patch that renames assimilate to repair looks fine -- I gave stg mail --diff-opts='-M -C -C'. But the diffstats apparently don't get those flags, neither the aggregate one below nor the one just for that patch. We ought to fix that ...
Karl Hasselström (5):
stg repair: Patchify non-patch commits between patches Rename "stg assimilate" to "stg repair"
Let some commands work with detached HEAD Cogito is deprecated, so don't point to it Simple test for "stg clean"
Documentation/stg.txt | 4 - README | 4 - contrib/stgit-completion.bash | 2 stgit/commands/add.py | 2 stgit/commands/assimilate.py | 198 ----------------------------------------- stgit/commands/common.py | 2 stgit/commands/repair.py | 192 ++++++++++++++++++++++++++++++++++++++++ stgit/commands/resolved.py | 2 stgit/commands/status.py | 2 stgit/main.py | 4 - t/t1301-assimilate.sh | 84 ----------------- t/t1301-repair.sh | 80 +++++++++++++++++ t/t1302-assimilate-interop.sh | 59 ------------ t/t1302-repair-interop.sh | 59 ++++++++++++ t/t2500-clean.sh | 27 ++++++ 15 files changed, 368 insertions(+), 353 deletions(-) delete mode 100644 stgit/commands/assimilate.py create mode 100644 stgit/commands/repair.py delete mode 100755 t/t1301-assimilate.sh create mode 100755 t/t1301-repair.sh delete mode 100755 t/t1302-assimilate-interop.sh create mode 100755 t/t1302-repair-interop.sh create mode 100755 t/t2500-clean.sh
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/5 Simple test for "stg clean"
---
t/t2500-clean.sh | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) create mode 100755 t/t2500-clean.sh
t/t2500-clean.sh new file +27 -0
@@ -0,0 +1,27 @@ +#!/bin/sh + +test_description='Run "stg clean"' + +. ./test-lib.sh + +test_expect_success 'Initialize StGit stack' ' + stg init && + stg new e0 -m e0 && + stg new p0 -m p0 && + echo foo > foo.txt && + git add foo.txt && + stg refresh && + stg new e1 -m e1 && + stg new e2 -m e2 && + stg pop +' + +test_expect_success 'Clean empty patches' ' + [ "$(echo $(stg applied))" = "e0 p0 e1" ] && + [ "$(echo $(stg unapplied))" = "e2" ] && + stg clean && + [ "$(echo $(stg applied))" = "p0" ] && + [ "$(echo $(stg unapplied))" = "" ] +' + +test_done
PATCH 2/5 Cogito is deprecated, so don't point to it
In reply to Karl Hasselström---
README | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
README +1 -3
@@ -6,9 +6,7 @@ other repositories using standard GIT functionality. Note that StGIT is not an SCM interface on top of GIT and it expects a previously initialised GIT repository (unless it is cloned using StGIT -directly). For standard SCM operations, either use plain GIT commands -or the Cogito tool but it is not recommended to mix them with the -StGIT commands. +directly). For standard SCM operations, use plain GIT commands. For the latest version see http://www.procode.org/stgit/ For a tutorial see http://wiki.procode.org/cgi-bin/wiki.cgi/StGIT_Tutorial
PATCH 3/5 Let some commands work with detached HEAD
In reply to Karl Hasselströmadd, resolved, and status didn't use the crt_series that was initialized for them. So don't initialize it, since that means (1) less work and (2) they won't fail when HEAD is detached.
Note that this doesn't completely fix the problem with detached HEAD:
a number of other commands (e.g. branch) don't always need to refer to a current series, but currently fails on a detached HEAD even in those situations.
---
stgit/commands/add.py | 2 +- stgit/commands/resolved.py | 2 +- stgit/commands/status.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
stgit/commands/add.py +1 -1
@@ -31,7 +31,7 @@ Add the files or directories passed as arguments to the repository. When a directory name is given, all the files and subdirectories are recursively added.""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = []
stgit/commands/resolved.py +1 -1
@@ -34,7 +34,7 @@ Mark a merge conflict as resolved. The conflicts can be seen with the 'C'. This command also removes any <file>.{ancestor,current,patched} files.""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = [make_option('-a', '--all', help = 'mark all conflicts as solved', action = 'store_true'),
stgit/commands/status.py +1 -1
@@ -40,7 +40,7 @@ under revision control. The files are prefixed as follows: A 'refresh' command clears the status of the modified, new and deleted files.""" -directory = DirectoryHasRepository() +directory = DirectoryHasRepository(needs_current_series = False) options = [make_option('-m', '--modified', help = 'show modified files only', action = 'store_true'),
PATCH 4/5 Rename "stg assimilate" to "stg repair"
In reply to Karl HasselströmWith the capabilities it's gained lately, this is a better name.
---
Documentation/stg.txt | 4 - contrib/stgit-completion.bash | 2 stgit/commands/assimilate.py | 198 ----------------------------------------- stgit/commands/common.py | 2 stgit/commands/repair.py | 197 +++++++++++++++++++++++++++++++++++++++++ stgit/main.py | 4 - t/t1301-assimilate.sh | 84 ----------------- t/t1301-repair.sh | 80 +++++++++++++++++ t/t1302-assimilate-interop.sh | 59 ------------ t/t1302-repair-interop.sh | 59 ++++++++++++ 10 files changed, 342 insertions(+), 347 deletions(-) delete mode 100644 stgit/commands/assimilate.py create mode 100644 stgit/commands/repair.py delete mode 100755 t/t1301-assimilate.sh create mode 100755 t/t1301-repair.sh delete mode 100755 t/t1302-assimilate-interop.sh create mode 100755 t/t1302-repair-interop.sh
Documentation/stg.txt +2 -2
@@ -146,8 +146,8 @@ stglink:commit[]:: stgdesc:commit[] stglink:uncommit[]:: stgdesc:uncommit[] -stglink:assimilate[]:: - stgdesc:assimilate[] +stglink:repair[]:: + stgdesc:repair[] Controlling what patches are applied ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
contrib/stgit-completion.bash +1 -1
@@ -13,7 +13,6 @@ _stg_commands=" add applied - assimilate branch delete diff
@@ -42,6 +41,7 @@ _stg_commands=" rebase refresh rename + repair resolved rm series
stgit/commands/common.py +1 -1
@@ -114,7 +114,7 @@ def check_head_top_equal(crt_series): if not crt_series.head_top_equal(): raise CmdException( """HEAD and top are not the same. This can happen if you - modify a branch with git. The "assimilate" command can + modify a branch with git. The "repair" command can fix this situation.""") def check_conflicts():
stgit/commands/repair.py renamed from stgit/commands/assimilate.py +11 -12
@@ -29,28 +29,28 @@ from stgit import stack, git help = 'StGit-ify any git commits made on top of your StGit stack' usage = """%prog [options] -"assimilate" will repair three kinds of inconsistencies in your StGit +"repair" will repair three kinds of inconsistencies in your StGit stack, all of them caused by using plain git commands on the branch: 1. If you have made regular git commits on top of your stack of - StGit patches, "assimilate" converts them to StGit patches, + StGit patches, "repair" converts them to StGit patches, preserving their contents. 2. Merge commits cannot become patches; if you have committed a - merge on top of your stack, "assimilate" will simply mark all + merge on top of your stack, "repair" will simply mark all patches below the merge unapplied, since they are no longer reachable. If this is not what you want, use "git reset" to get - rid of the merge and run "assimilate" again. + rid of the merge and run "repair" again. 3. The applied patches are supposed to be precisely those that are reachable from the branch head. If you have used e.g. "git reset" to move the head, some applied patches may no longer be reachable, and some unapplied patches may have become reachable. - "assimilate" will correct the appliedness of such patches. + "repair" will correct the appliedness of such patches. Note that these are "inconsistencies", not "errors"; furthermore, -"assimilate" will repair them reliably. As long as you are satisfied -with the way "assimilate" handles them, you have no reason to avoid +"repair" will repair them reliably. As long as you are satisfied +with the way "repair" handles them, you have no reason to avoid causing them in the first place if that is convenient for you.""" directory = DirectoryGotoToplevel()
@@ -99,11 +99,10 @@ def read_commit_dag(branch): return commits, patches def func(parser, options, args): - """Assimilate a number of patches. - """ + """Repair inconsistencies in StGit metadata.""" def nothing_to_do(): - out.info('No commits to assimilate') + out.info('Nothing to repair') orig_applied = crt_series.get_applied() orig_unapplied = crt_series.get_unapplied()
@@ -118,7 +117,7 @@ def func(parser, options, args): raise CmdException( 'This branch is protected. Modification is not permitted.') - # Find commits to assimilate, and applied patches. + # Find commits that aren't patches, and applied patches. commits, patches = read_commit_dag(crt_series.get_name()) c = commits[head] patchify = []
@@ -149,7 +148,7 @@ def func(parser, options, args): % (len(hidden), ['es', ''][len(hidden) == 1])), '%s,' % merge.id, 'and will be considered unapplied.') - # Assimilate any linear sequence of commits on top of a patch. + # Make patches of any linear sequence of commits on top of a patch. names = set(p.patch for p in patches) def name_taken(name): return name in names
stgit/main.py +2 -2
@@ -60,7 +60,6 @@ class Commands(dict): commands = Commands({ 'add': 'add', 'applied': 'applied', - 'assimilate': 'assimilate', 'branch': 'branch', 'delete': 'delete', 'diff': 'diff',
@@ -89,6 +88,7 @@ commands = Commands({ 'rebase': 'rebase', 'refresh': 'refresh', 'rename': 'rename', + 'repair': 'repair', 'resolved': 'resolved', 'rm': 'rm', 'series': 'series',
@@ -109,7 +109,6 @@ repocommands = ( ) stackcommands = ( 'applied', - 'assimilate', 'branch', 'clean', 'commit',
@@ -122,6 +121,7 @@ stackcommands = ( 'pull', 'push', 'rebase', + 'repair', 'series', 'sink', 'top',
t/t1301-repair.sh renamed from t/t1301-assimilate.sh +13 -17
@@ -1,19 +1,19 @@ #!/bin/sh # Copyright (c) 2006 Karl Hasselström -test_description='Test the assimilate command.' +test_description='Test the repair command.' . ./test-lib.sh test_expect_success \ - 'Assimilate in a non-initialized repository' \ - '! stg assimilate' + 'Repair in a non-initialized repository' \ + '! stg repair' test_expect_success \ 'Initialize the StGIT repository' \ 'stg init' test_expect_success \ - 'Assimilate in a repository without patches' \ - 'stg assimilate' + 'Repair in a repository without patches' \ + 'stg repair' test_expect_success \ 'Create a patch' \
@@ -25,8 +25,8 @@ test_expect_success \ ' test_expect_success \ - 'Assimilate when there is nothing to do' \ - 'stg assimilate' + 'Repair when there is nothing to do' \ + 'stg repair' test_expect_success \ 'Create a GIT commit' \
@@ -36,11 +36,9 @@ test_expect_success \ git commit -a -m bar ' -test_expect_success \ - 'Assimilate one GIT commit' \ - ' +test_expect_success 'Turn one GIT commit into a patch' ' [ $(stg applied | wc -l) -eq 1 ] && - stg assimilate && + stg repair && [ $(stg applied | wc -l) -eq 2 ] '
@@ -56,11 +54,9 @@ test_expect_success \ git commit -a -m three ' -test_expect_success \ - 'Assimilate three GIT commits' \ - ' +test_expect_success 'Turn three GIT commits into patches' ' [ $(stg applied | wc -l) -eq 2 ] && - stg assimilate && + stg repair && [ $(stg applied | wc -l) -eq 5 ] '
@@ -75,9 +71,9 @@ test_expect_success \ git pull . br ' -test_expect_success 'Assimilate in the presence of a merge commit' ' +test_expect_success 'Repair in the presence of a merge commit' ' [ $(stg applied | wc -l) -eq 5 ] && - stg assimilate && + stg repair && [ $(stg applied | wc -l) -eq 0 ] '
t/t1302-repair-interop.sh renamed from t/t1302-assimilate-interop.sh +4 -4
@@ -1,5 +1,5 @@ #!/bin/sh -test_description='Test git/StGit interoperability with "stg assimilate"' +test_description='Test git/StGit interoperability with "stg repair"' . ./test-lib.sh test_expect_success 'Create some git-only history' '
@@ -28,7 +28,7 @@ test_expect_success 'Create five patches' ' test_expect_success 'Pop two patches with git-reset' ' git reset --hard HEAD~2 && ! stg refresh && - stg assimilate && + stg repair && stg refresh && [ "$(echo $(stg applied))" = "p0 p1 p2" ] && [ "$(echo $(stg unapplied))" = "p3 p4" ]
@@ -43,7 +43,7 @@ test_expect_success 'Create a new patch' ' test_expect_success 'Go to an unapplied patch with with git-reset' ' git reset --hard $(stg id p3) && ! stg refresh && - stg assimilate && + stg repair && stg refresh && [ "$(echo $(stg applied))" = "p0 p1 p2 p3" ] && [ "$(echo $(stg unapplied))" = "q0 p4" ]
@@ -51,7 +51,7 @@ test_expect_success 'Go to an unapplied patch with with git-reset' ' test_expect_success 'Go back to below the stack base with git-reset' ' git reset --hard foo-tag && - stg assimilate && + stg repair && [ "$(echo $(stg applied))" = "" ] && [ "$(echo $(stg unapplied))" = "p0 p1 p2 p3 q0 p4" ] '
PATCH 5/5 stg repair: Patchify non-patch commits between patches
In reply to Karl HasselströmThis teaches "stg repair" to find non-patch commits that sit between patches, and turn them into patches. This situation can happen e.g. like this:
stg new -m A && stg new -m B && stg new -m C
stg pop A B C
stg push B
echo foo > foo && git add foo && stg refresh
git reset --hard $(stg id C)
The old "stg repair" would at this point simply conclude that A and C are applied, and B unapplied. However, B's old commit is still between them even though it's not a patch, which will cause problems later -- StGit generally assumes that the applied patches are a consecutive string of commits. The new "stg repair", on the other hand, will find B's old commit, and create a new patch for it.
One downside of this change is that we can no longer conclude that all is well just because head == top, so no-op runs of "stg repair" just got more expensive.
---
stgit/commands/repair.py | 19 +++++++------------ 1 files changed, 7 insertions(+), 12 deletions(-)
stgit/commands/repair.py +7 -12
@@ -101,33 +101,28 @@ def read_commit_dag(branch): def func(parser, options, args): """Repair inconsistencies in StGit metadata.""" - def nothing_to_do(): - out.info('Nothing to repair') - orig_applied = crt_series.get_applied() orig_unapplied = crt_series.get_unapplied() - # If head == top, we're done. - head = git.get_commit(git.get_head()).get_id_hash() - top = crt_series.get_current_patch() - if top and head == top.get_top(): - return nothing_to_do() - if crt_series.get_protected(): raise CmdException( 'This branch is protected. Modification is not permitted.') # Find commits that aren't patches, and applied patches. + head = git.get_commit(git.get_head()).get_id_hash() commits, patches = read_commit_dag(crt_series.get_name()) c = commits[head] - patchify = [] + patchify = [] # commits to definitely patchify + maybe_patchify = [] # commits to patchify if we find a patch below them applied = [] while len(c.parents) == 1: parent, = c.parents if c.patch: applied.append(c) - elif not applied: - patchify.append(c) + patchify.extend(maybe_patchify) + maybe_patchify = [] + else: + maybe_patchify.append(c) c = parent applied.reverse() patchify.reverse()
Quoted 3 lines · Karl Hasselström
These are available from
git://repo.or.cz/stgit/kha.gitsafe
Thanks. Merged.
Quoted 1 line
Let some commands work with detached HEAD
[...]
Quoted 1 line
stgit/commands/add.py | 2
My plan after 0.14 is to remove the implementation of add/rm etc. commands. I'd like to keep them as just synonyms to the equivalent git commands which stgit would invoke (this is mainly for convenience as I usually type "stg" rather than "git").
BTW, I'll review this week the bugs already logged and clean as many as possible (help appreciated :-)) and try to release 0.14 in 1-2 weeks.
Signature · 1 line
Catalin
Quoted 2 lines · Catalin Marinas
My plan after 0.14 is to remove the implementation of add/rm etc. commands.
There are patches for this in kha/experimental. :-) They are on top of David's conflict representation series, and I think there might be a reason for that. But it was quite a while ago ...
On top of David's series, "stg resolved" should also be superfluous -- I just haven't gotten around to removing it yet.
Quoted 3 lines
I'd like to keep them as just synonyms to the equivalent git commands which stgit would invoke (this is mainly for convenience as I usually type "stg" rather than "git").
OK, I can live with that. But I'd like them to be well hidden, so the apparent command set doesn't become too large.
Quoted 2 lines
BTW, I'll review this week the bugs already logged and clean as many as possible (help appreciated :-))
I think there might be a fair number of bugs that are still open in the bug tracker even though they are fixed.
Quoted 1 line
and try to release 0.14 in 1-2 weeks.
All right!
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle