aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Marinas <catalin.marinas@gmail.com>2010-03-25 11:25:45 +0000
committerCatalin Marinas <catalin.marinas@gmail.com>2010-03-25 11:25:45 +0000
commiteec51c11ce97af48c6d8dc0841afb5e055be8d30 (patch)
tree4887e664f454f07292b9498a04053a288300683a
parent25aae9dd9b269983e55ab653fb9a7bb7f46d2315 (diff)
downloadstgit-eec51c11ce97af48c6d8dc0841afb5e055be8d30.tar.gz
publish: Add the --unpublished options to list not yet published patches
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
-rw-r--r--stgit/commands/publish.py29
-rw-r--r--stgit/lib/transaction.py13
2 files changed, 36 insertions, 6 deletions
diff --git a/stgit/commands/publish.py b/stgit/commands/publish.py
index 93e4d28..b312157 100644
--- a/stgit/commands/publish.py
+++ b/stgit/commands/publish.py
@@ -19,7 +19,7 @@ from stgit import argparse
from stgit.argparse import opt
from stgit.commands import common
from stgit.config import config
-from stgit.lib import git, stack
+from stgit.lib import git, stack, transaction
from stgit.out import out
from stgit import utils
@@ -54,6 +54,11 @@ described above are separated by a publish command in order to keep the public
branch history cleaner (otherwise StGit would generate a big commit including
several stack modifications).
+The '--unpublished' option can be used to check if there are applied patches
+that have not been published to the public branch. This is done by trying to
+revert the patches in the public tree (similar to the 'push --merged'
+detection).
+
The public branch name can be set via the branch.<branch>.public configuration
variable (defaulting to "<branch>.public").
"""
@@ -61,7 +66,9 @@ variable (defaulting to "<branch>.public").
args = [argparse.all_branches]
options = [
opt('-b', '--branch', args = [argparse.stg_branches],
- short = 'Use BRANCH instead of the default branch')
+ short = 'Use BRANCH instead of the default branch'),
+ opt('-u', '--unpublished', action = 'store_true',
+ short = 'Show applied patches that have not been published')
] + (argparse.author_options()
+ argparse.message_options(save_template = False)
+ argparse.sign_options())
@@ -77,6 +84,14 @@ def __create_commit(repository, tree, parents, options, message = ''):
return repository.commit(cd)
+def __get_published(stack, tree):
+ """Check the patches that were already published."""
+ trans = transaction.StackTransaction(stack, 'publish')
+ published = trans.check_merged(trans.applied, tree = tree, quiet = True)
+ trans.abort()
+
+ return published
+
def func(parser, options, args):
"""Publish the stack changes."""
repository = directory.repository
@@ -94,6 +109,8 @@ def func(parser, options, args):
# just clone the stack if the public ref does not exist
if not repository.refs.exists(public_ref):
+ if options.unpublished:
+ raise common.CmdException('"%s" does not exist' % public_ref)
repository.refs.set(public_ref, stack.head, 'publish')
out.info('Created "%s"' % public_ref)
return
@@ -106,6 +123,14 @@ def func(parser, options, args):
out.info('"%s" already up to date' % public_ref)
return
+ # check for unpublished patches
+ if options.unpublished:
+ published = set(__get_published(stack, public_tree))
+ for p in stack.patchorder.applied:
+ if p not in published:
+ print p
+ return
+
# check for rebased stack. In this case we emulate a merge with the stack
# base by setting two parents.
merge_bases = repository.get_merge_bases(public_head, stack.base)
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index e76f5ab..f4c105a 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -414,11 +414,15 @@ class StackTransaction(object):
self.unapplied = unapplied
self.hidden = hidden
- def check_merged(self, patches):
+ def check_merged(self, patches, tree = None, quiet = False):
"""Return a subset of patches already merged."""
- out.start('Checking for patches merged upstream')
+ if not quiet:
+ out.start('Checking for patches merged upstream')
merged = []
- if self.temp_index_tree != self.stack.head.data.tree:
+ if tree:
+ self.temp_index.read_tree(tree)
+ self.temp_index_tree = tree
+ elif self.temp_index_tree != self.stack.head.data.tree:
self.temp_index.read_tree(self.stack.head.data.tree)
self.temp_index_tree = self.stack.head.data.tree
for pn in reversed(patches):
@@ -435,5 +439,6 @@ class StackTransaction(object):
self.temp_index_tree = None
except git.MergeException:
pass
- out.done('%d found' % len(merged))
+ if not quiet:
+ out.done('%d found' % len(merged))
return merged