aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Marinas <catalin.marinas@gmail.com>2010-03-29 10:48:16 +0100
committerCatalin Marinas <catalin.marinas@gmail.com>2010-03-29 10:48:16 +0100
commit064161c3687ce594842f4187657b6e79b729192e (patch)
tree4ae40d7444ff8b33ac331c2282b73f9bd7d14305
parentce12f5252e41d2931ee4520809a6c0897a7ffc96 (diff)
downloadstgit-064161c3687ce594842f4187657b6e79b729192e.tar.gz
publish: Add '--last' option to show the last published patch
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
-rw-r--r--stgit/commands/publish.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/stgit/commands/publish.py b/stgit/commands/publish.py
index b312157..3aa83a2 100644
--- a/stgit/commands/publish.py
+++ b/stgit/commands/publish.py
@@ -57,7 +57,9 @@ 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).
+detection). The '--last' option tries to find the last published patch by
+checking the SHA1 of the patch tree agains the public tree. This may fail if
+the stack was rebased since the last publish command.
The public branch name can be set via the branch.<branch>.public configuration
variable (defaulting to "<branch>.public").
@@ -67,6 +69,8 @@ args = [argparse.all_branches]
options = [
opt('-b', '--branch', args = [argparse.stg_branches],
short = 'Use BRANCH instead of the default branch'),
+ opt('-l', '--last', action = 'store_true',
+ short = 'Show the last published patch'),
opt('-u', '--unpublished', action = 'store_true',
short = 'Show applied patches that have not been published')
] + (argparse.author_options()
@@ -92,6 +96,15 @@ def __get_published(stack, tree):
return published
+def __get_last(stack, tree):
+ """Return the name of the last published patch."""
+ for p in reversed(stack.patchorder.applied):
+ pc = stack.patches.get(p).commit
+ if tree.sha1 == pc.data.tree.sha1:
+ return p
+
+ return None
+
def func(parser, options, args):
"""Publish the stack changes."""
repository = directory.repository
@@ -109,7 +122,7 @@ 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:
+ if options.unpublished or options.last:
raise common.CmdException('"%s" does not exist' % public_ref)
repository.refs.set(public_ref, stack.head, 'publish')
out.info('Created "%s"' % public_ref)
@@ -118,6 +131,15 @@ def func(parser, options, args):
public_head = repository.refs.get(public_ref)
public_tree = public_head.data.tree
+ # find the last published patch
+ if options.last:
+ last = __get_last(stack, public_tree)
+ if not last:
+ raise common.CmdException('Unable to find the last published patch '
+ '(possibly rebased stack)')
+ out.info('%s' % last)
+ return
+
# check for same tree (already up to date)
if public_tree.sha1 == stack.head.data.tree.sha1:
out.info('"%s" already up to date' % public_ref)