Add a --tree flag to stg push
PATCH 1/1 Add a --tree flag to stg push
This flag makes the push simply restore the tree that the patch used before, rather than doing any kind of merge.
---
This scratches a long-time itch for me. The typical use case is when you want to break up a larg patch inte smaller ones. You back out the orignal patch, apply a small set of changes from it and then push the patch back again. But then you don't want to do a merge, with the possibility of conflict. You simply want to restore to the tree that the patch had before so you can see what's left to create cleaned-up patches of. The command "stg push --tree" does just that.
The naming of flags and functions isn't very obvious, and suggestions for improvements are welcome.
stgit/commands/push.py | 26 ++++++++++++------- stgit/lib/transaction.py | 28 ++++++++++++++++++++ t/t1207-push-tree.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 10 deletions(-) create mode 100755 t/t1207-push-tree.sh
stgit/commands/push.py +16 -10
@@ -43,7 +43,9 @@ options = [ opt('-n', '--number', type = 'int', short = 'Push the specified number of patches'), opt('--reverse', action = 'store_true', - short = 'Push the patches in reverse order') + short = 'Push the patches in reverse order'), + opt('--tree', action = 'store_true', + short = 'Push the patch with the original tree') ] + argparse.keep_option() + argparse.merged_option() directory = common.DirectoryHasRepositoryLib()
@@ -74,14 +76,18 @@ def func(parser, options, args): if options.reverse: patches.reverse() - try: - if options.merged: - merged = set(trans.check_merged(patches)) - else: - merged = set() + if options.tree: for pn in patches: - trans.push_patch(pn, iw, allow_interactive = True, - already_merged = pn in merged) - except transaction.TransactionHalted: - pass + trans.push_tree(pn) + else: + try: + if options.merged: + merged = set(trans.check_merged(patches)) + else: + merged = set() + for pn in patches: + trans.push_patch(pn, iw, allow_interactive = True, + already_merged = pn in merged) + except transaction.TransactionHalted: + pass return trans.run(iw)
stgit/lib/transaction.py +28 -0
@@ -372,6 +372,34 @@ class StackTransaction(object): # Update immediately. update() + def push_tree(self, pn): + """Push the named patch without updating its tree.""" + orig_cd = self.patches[pn].data + cd = orig_cd.set_committer(None) + oldparent = cd.parent + cd = cd.set_parent(self.top) + + s = '' + if any(getattr(cd, a) != getattr(orig_cd, a) for a in + ['parent', 'tree', 'author', 'message']): + comm = self.__stack.repository.commit(cd) + self.head = comm + else: + comm = None + s = ' (unmodified)' + if cd.is_nochange(): + s = ' (empty)' + out.info('Pushed %s%s' % (pn, s)) + + if comm: + self.patches[pn] = comm + if pn in self.hidden: + x = self.hidden + else: + x = self.unapplied + del x[x.index(pn)] + self.applied.append(pn) + def reorder_patches(self, applied, unapplied, hidden = None, iw = None): """Push and pop patches to attain the given ordering.""" if hidden is None:
t/t1207-push-tree.sh new file +64 -0
64 lines not on this page · raw message
Quoted 7 lines · David Kågedal
This scratches a long-time itch for me. The typical use case is when you want to break up a larg patch inte smaller ones. You back out the orignal patch, apply a small set of changes from it and then push the patch back again. But then you don't want to do a merge, with the possibility of conflict. You simply want to restore to the tree that the patch had before so you can see what's left to create cleaned-up patches of. The command "stg push --tree" does just that.
Thanks!
There's no sign-off.
Quoted 2 lines
The naming of flags and functions isn't very obvious, and suggestions for improvements are welcome.
--set-tree maybe?
Quoted 1 line
t/t1207-push-tree.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++
A test! Very good.
stgit/commands/push.py options = [ · line 48
Quoted 2 lines
stgit/commands/push.py +2
-0+ opt('--tree', action = 'store_true', + short = 'Push the patch with the original tree')
This probably deserves a long description as well. (That most existing options lack them is unfortunate---the support for long descriptions was added rather recently.)
stgit/lib/transaction.py class StackTransaction(object): · line 389
Quoted 7 lines
stgit/lib/transaction.py +7
-0+ if any(getattr(cd, a) != getattr(orig_cd, a) for a in + ['parent', 'tree', 'author', 'message']): + comm = self.__stack.repository.commit(cd) + self.head = comm + else: + comm = None + s = ' (unmodified)'
Shouldn't self.head be set in both cases?
Quoted 1 line
+# Copyright (c) 2006 David Kågedal
Been sitting on this patch long? :-)
t/t1207-push-tree.sh line 14
Quoted 5 lines
t/t1207-push-tree.sh new file +5
-0+# don't need this repo, but better not drop it, see t1100 +#rm -rf .git + +# Need a repo to clone +test_create_repo foo
Umm, your test doesn't seem to depend on using this separate repo instead of the default one.
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH v2 1/1 Add a --set-tree flag to stg push
This flag makes the push simply restore the tree that the patch used before, rather than doing any kind of merge.
---
Here's an updated patch, based on feedback and discussion with Karl.
stgit/commands/push.py | 34 ++++++++++++++++++++++++---------- stgit/lib/transaction.py | 22 ++++++++++++++++++++++ t/t1207-push-tree.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 10 deletions(-) create mode 100755 t/t1207-push-tree.sh
stgit/commands/push.py +24 -10
@@ -43,7 +43,17 @@ options = [ opt('-n', '--number', type = 'int', short = 'Push the specified number of patches'), opt('--reverse', action = 'store_true', - short = 'Push the patches in reverse order') + short = 'Push the patches in reverse order'), + opt('--set-tree', action = 'store_true', + short = 'Push the patch with the original tree', long = """ + Push the patches, but don't perform a merge. Instead, the + resulting tree will be identical to the tree that the patch + previously created. This can be useful when splitting a patch + by first popping the patch and creating a new patch with some + of the changes. Pushing the original patch with --set-tree + will avoid conflicts and only the remaining changes will be in + the patch. + """) ] + argparse.keep_option() + argparse.merged_option() directory = common.DirectoryHasRepositoryLib()
@@ -74,14 +84,18 @@ def func(parser, options, args): if options.reverse: patches.reverse() - try: - if options.merged: - merged = set(trans.check_merged(patches)) - else: - merged = set() + if options.set_tree: for pn in patches: - trans.push_patch(pn, iw, allow_interactive = True, - already_merged = pn in merged) - except transaction.TransactionHalted: - pass + trans.push_tree(pn) + else: + try: + if options.merged: + merged = set(trans.check_merged(patches)) + else: + merged = set() + for pn in patches: + trans.push_patch(pn, iw, allow_interactive = True, + already_merged = pn in merged) + except transaction.TransactionHalted: + pass return trans.run(iw)
stgit/lib/transaction.py +22 -0
@@ -372,6 +372,28 @@ class StackTransaction(object): # Update immediately. update() + def push_tree(self, pn): + """Push the named patch without updating its tree.""" + orig_cd = self.patches[pn].data + cd = orig_cd.set_committer(None).set_parent(self.top) + + s = '' + if any(getattr(cd, a) != getattr(orig_cd, a) for a in + ['parent', 'tree', 'author', 'message']): + self.patches[pn] = self.__stack.repository.commit(cd) + else: + s = ' (unmodified)' + if cd.is_nochange(): + s = ' (empty)' + out.info('Pushed %s%s' % (pn, s)) + + if pn in self.hidden: + x = self.hidden + else: + x = self.unapplied + del x[x.index(pn)] + self.applied.append(pn) + def reorder_patches(self, applied, unapplied, hidden = None, iw = None): """Push and pop patches to attain the given ordering.""" if hidden is None:
t/t1207-push-tree.sh new file +46 -0
46 lines not on this page · raw message
Re: [StGit PATCH v2] Add a --set-tree flag to stg push
stgit/commands/push.py options = [ · line 51
Quoted 5 lines · David Kågedal
stgit/commands/push.py +5
-0+ opt('--set-tree', action = 'store_true', + short = 'Push the patch with the original tree', long = """ + Push the patches, but don't perform a merge. Instead, the + resulting tree will be identical to the tree that the patch + previously created. This can be useful when splitting a patch
Paragraph break after "created"?
stgit/commands/push.py options = [ · line 54
Quoted 3 lines
stgit/commands/push.py +3
-0+ by first popping the patch and creating a new patch with some + of the changes. Pushing the original patch with --set-tree + will avoid conflicts and only the remaining changes will be in
The long description is fed to asciidoc, which will translate -- to an en dash if I recall correctly. The long descriptions of other commands' flags enclose flags in single quotes.
stgit/commands/push.py options = [ · line 56
Quoted 2 lines
stgit/commands/push.py +2
-0+ the patch. + """)
Unnecessary line break.
Apart from those nitpicks,
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
Quoted 10 lines · Karl Hasselström
Quoted 7 lines · David Kågedal
This scratches a long-time itch for me. The typical use case is when you want to break up a larg patch inte smaller ones. You back out the orignal patch, apply a small set of changes from it and then push the patch back again. But then you don't want to do a merge, with the possibility of conflict. You simply want to restore to the tree that the patch had before so you can see what's left to create cleaned-up patches of. The command "stg push --tree" does just that.
Quoted 3 lines
Thanks!
There's no sign-off.
I counted on getting comments, so it's not finished yet...
Quoted 4 lines
Quoted 2 lines
The naming of flags and functions isn't very obvious, and suggestions for improvements are welcome.
--set-tree maybe?
Probably better. But perhaps there is a way to not have to talk about "trees" at all?
Quoted 10 lines
Quoted 1 line
t/t1207-push-tree.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++A test! Very good.
stgit/commands/push.py options = [ · line 48
Quoted 2 lines
stgit/commands/push.py +2
-0+ opt('--tree', action = 'store_true', + short = 'Push the patch with the original tree')This probably deserves a long description as well. (That most existing options lack them is unfortunate---the support for long descriptions was added rather recently.)
I didn't look putside push.py, and just followed the pattern there. But a long description sounds like a good idea. It won't be obvious what this does with just a short one.
Quoted 9 lines
stgit/lib/transaction.py class StackTransaction(object): · line 389
Quoted 7 lines
stgit/lib/transaction.py +7
-0+ if any(getattr(cd, a) != getattr(orig_cd, a) for a in + ['parent', 'tree', 'author', 'message']): + comm = self.__stack.repository.commit(cd) + self.head = comm + else: + comm = None + s = ' (unmodified)'Shouldn't self.head be set in both cases?
I guess so. I'm a bit unsure about the correctness of that whole function.
Quoted 3 lines
Quoted 1 line
+# Copyright (c) 2006 David Kågedal
Been sitting on this patch long? :-)
Copy/paste error.
Quoted 8 lines
t/t1207-push-tree.sh line 14
Quoted 5 lines
t/t1207-push-tree.sh new file +5
-0+# don't need this repo, but better not drop it, see t1100 +#rm -rf .git + +# Need a repo to clone +test_create_repo fooUmm, your test doesn't seem to depend on using this separate repo instead of the default one.
Call it copy/paste programming or cargo cult programming. I will clean up.
Signature · 1 line
David Kågedal
Quoted 5 lines · David Kågedal
Quoted 1 line · Karl Hasselström
There's no sign-off.
I counted on getting comments, so it's not finished yet...
The sign-off has nothing to do with the patch being finished. It's simply you saying "I promise I have the right to distribute the following patch under GPLv2." See Documentation/SubmittingPatches (which we've stolen from git and hardly changed).
Quoted 4 lines
Quoted 1 line
--set-tree maybe?
Probably better. But perhaps there is a way to not have to talk about "trees" at all?
Hmm, maybe. Personally, I find that "tree" is a very descriptive word for this operation, but that may be because I know git too well.
Something like "overwrite" maybe?
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle