From: "Karl Hasselström" <kha@treskal.com>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH 14/14] Make "stg log" show stack log instead of patch log
Date: Thu, 12 Jun 2008 07:35:31 +0200 [thread overview]
Message-ID: <20080612053531.23549.77890.stgit@yoghurt> (raw)
In-Reply-To: <20080612052913.23549.69687.stgit@yoghurt>
Make "stg log" show the new stack log instead of the old patch logs,
which is now obsolete. Delete t1400-patch-history, which is specific
to the old "stg log".
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/commands/log.py | 169 ++++++++++++++--------------------------------
stgit/commands/reset.py | 15 +---
stgit/lib/log.py | 3 +
t/t1400-patch-history.sh | 103 ----------------------------
4 files changed, 58 insertions(+), 232 deletions(-)
delete mode 100755 t/t1400-patch-history.sh
diff --git a/stgit/commands/log.py b/stgit/commands/log.py
index 13e0baa..cf15c7d 100644
--- a/stgit/commands/log.py
+++ b/stgit/commands/log.py
@@ -1,5 +1,8 @@
+# -*- coding: utf-8 -*-
+
__copyright__ = """
Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
+Copyright (C) 2008, Karl Hasselström <kha@treskal.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
@@ -15,133 +18,67 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-import sys, os, time
-from optparse import OptionParser, make_option
-from pydoc import pager
-from stgit.commands.common import *
-from stgit import stack, git
-from stgit.out import *
-from stgit.run import Run
+import os.path
+from optparse import make_option
+from stgit import run
+from stgit.commands import common
+from stgit.lib import log
+from stgit.out import out
help = 'display the patch changelog'
-usage = """%prog [options] [patch]
-
-List all the current and past commit ids of the given patch. The
---graphical option invokes gitk instead of printing. The changelog
-commit messages have the form '<action> <new-patch-id>'. The <action>
-can be one of the following:
+usage = """%prog [options] [<patchnames>]
- new - new patch created
- refresh - local changes were added to the patch
- push - the patch was cleanly pushed onto the stack
- push(m) - the patch was pushed onto the stack with a three-way merge
- push(f) - the patch was fast-forwarded
- undo - the patch boundaries were restored to the old values
+List the history of the patch stack: the stack log. If one or more
+patch names are given, limit the list to the log entries that touch
+the named patches.
-Note that only the diffs shown in the 'refresh', 'undo' and 'sync'
-actions are meaningful for the patch changes. The 'push' actions
-represent the changes to the entire base of the current
-patch. Conflicts reset the patch content and a subsequent 'refresh'
-will show the entire patch."""
+"stg undo" and "stg redo" let you step back and forth in the patch
+stack. "stg reset" lets you go directly to any state."""
-directory = DirectoryHasRepository(log = False)
+directory = common.DirectoryHasRepositoryLib()
options = [make_option('-b', '--branch',
help = 'use BRANCH instead of the default one'),
- make_option('-p', '--patch',
- help = 'show the refresh diffs',
- action = 'store_true'),
+ make_option('-d', '--diff', action = 'store_true',
+ help = 'show diff to previous state'),
make_option('-n', '--number', type = 'int',
- help = 'limit the output to NUMBER commits'),
- make_option('-f', '--full',
- help = 'show the full commit ids',
- action = 'store_true'),
- make_option('-g', '--graphical',
- help = 'run gitk instead of printing',
- action = 'store_true')]
-
-def show_log(log, options):
- """List the patch changelog
- """
- commit = git.get_commit(log)
- if options.number != None:
- n = options.number
- else:
- n = -1
- diff_list = []
- while commit:
- if n == 0:
- # limit the output
- break
-
- log = commit.get_log().split('\n')
-
- cmd_rev = log[0].split()
- if len(cmd_rev) >= 2:
- cmd = cmd_rev[0]
- rev = cmd_rev[1]
- elif len(cmd_rev) == 1:
- cmd = cmd_rev[0]
- rev = ''
- else:
- cmd = rev = ''
-
- if options.patch:
- if cmd in ['refresh', 'undo', 'sync', 'edit']:
- diff_list.append(git.pretty_commit(commit.get_id_hash()))
-
- # limiter decrement
- n -= 1
- else:
- if len(log) >= 3:
- notes = log[2]
- else:
- notes = ''
- author_name, author_email, author_date = \
- name_email_date(commit.get_author())
- secs, tz = author_date.split()
- date = '%s %s' % (time.ctime(int(secs)), tz)
-
- if options.full:
- out.stdout('%-7s %-40s %s' % (cmd[:7], rev[:40], date))
- else:
- out.stdout('%-8s [%-7s] %-28s %s' % \
- (rev[:8], cmd[:7], notes[:28], date))
-
- # limiter decrement
- n -= 1
-
- parent = commit.get_parent()
- if parent:
- commit = git.get_commit(parent)
- else:
- commit = None
-
- if options.patch and diff_list:
- pager('\n'.join(diff_list).rstrip())
+ help = 'limit the output to NUMBER entries'),
+ make_option('-f', '--full', action = 'store_true',
+ help = 'show the log in more detail'),
+ make_option('-g', '--graphical', action = 'store_true',
+ help = 'run gitk instead of printing')]
+
+def show_log(stacklog, pathlim, num, full, show_diff):
+ cmd = ['git', 'log']
+ if num != None and num > 0:
+ cmd.append('-%d' % num)
+ if show_diff:
+ cmd.append('-p')
+ elif not full:
+ cmd.append('--pretty=format:%h %aD %s')
+ run.Run(*(cmd + [stacklog.sha1, '--'] + pathlim)).run()
def func(parser, options, args):
- """Show the patch changelog
- """
- if len(args) == 0:
- name = crt_series.get_current()
- if not name:
- raise CmdException, 'No patches applied'
- elif len(args) == 1:
- name = args[0]
- if not name in crt_series.get_applied() + crt_series.get_unapplied() + \
- crt_series.get_hidden():
- raise CmdException, 'Unknown patch "%s"' % name
+ if options.branch:
+ stack = directory.repository.get_stack(options.branch)
else:
- parser.error('incorrect number of arguments')
-
- patch = crt_series.get_patch(name)
-
- log = patch.get_log()
- if not log:
- raise CmdException, 'No changelog for patch "%s"' % name
+ stack = directory.repository.current_stack
+ patches = common.parse_patches(args, list(stack.patchorder.all))
+ logref = log.log_ref(stack.name)
+ try:
+ logcommit = stack.repository.refs.get(logref)
+ except KeyError:
+ out.info('Log is empty')
+ return
+ stacklog = log.Log(stack.repository, logref, logcommit)
+ pathlim = [os.path.join('patches', pn) for pn in patches]
if options.graphical:
- # discard the exit codes generated by SIGINT, SIGKILL, SIGTERM
- Run('gitk', log).returns([0, -2, -9, -15]).run()
+ for o in ['diff', 'number', 'full']:
+ if getattr(options, o):
+ parser.error('cannot combine --graphical and --%s' % o)
+ # Discard the exit codes generated by SIGINT, SIGKILL, and SIGTERM.
+ run.Run(*(['gitk', stacklog.pretty.sha1, '--'] + pathlim)
+ ).returns([0, -2, -9, -15]).run()
else:
- show_log(log, options)
+ show_log(stacklog.pretty, pathlim,
+ options.number, options.full, options.diff)
diff --git a/stgit/commands/reset.py b/stgit/commands/reset.py
index 22d7731..bbe5dda 100644
--- a/stgit/commands/reset.py
+++ b/stgit/commands/reset.py
@@ -26,19 +26,8 @@ help = 'reset the patch stack to an earlier state'
usage = """%prog [options] <state> [<patchnames>]
Reset the patch stack to an earlier state. The state is specified with
-a commit from a stack log; for a branch foo, StGit stores the stack
-log in foo.stgit^. So to undo the last N StGit commands (or rather,
-the last N log entries; there is not an exact one-to-one
-relationship), you would say
-
- stg reset foo.stgit^~N
-
-or, if you are not sure how many steps to undo, you can view the log
-with "git log" or gitk
-
- gitk foo.stgit^
-
-and then reset to any sha1 you see in the log.
+a commit id from a stack log; "stg log" lets you view this log, and
+"stg reset" lets you reset to any state you see in the log.
If one or more patch names are given, reset only those patches, and
leave the rest alone."""
diff --git a/stgit/lib/log.py b/stgit/lib/log.py
index 8c0516b..61e9cf2 100644
--- a/stgit/lib/log.py
+++ b/stgit/lib/log.py
@@ -270,6 +270,9 @@ class Log(object):
def parents(self):
num_refs = len(set([self.top, self.head]))
return self.commit.data.parents[(1 + num_refs):]
+ @property
+ def pretty(self):
+ return self.commit.data.parents[0]
class FullLog(Log):
full_log = property(lambda self: self.commit)
diff --git a/t/t1400-patch-history.sh b/t/t1400-patch-history.sh
deleted file mode 100755
index a693e75..0000000
--- a/t/t1400-patch-history.sh
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2006 Catalin Marinas
-#
-
-test_description='Test the patch history generation.
-
-'
-
-. ./test-lib.sh
-
-test_expect_success \
- 'Initialize the StGIT repository' \
- '
- stg init
- '
-
-test_expect_success \
- 'Create the first patch' \
- '
- stg new foo -m "Foo Patch" &&
- echo foo > test && echo foo2 >> test &&
- git add test &&
- stg refresh --annotate="foo notes"
- '
-
-test_expect_success \
- 'Create the second patch' \
- '
- stg new bar -m "Bar Patch" &&
- echo bar >> test &&
- stg refresh
- '
-
-test_expect_success \
- 'Check the "new" and "refresh" logs' \
- '
- stg log --full foo | grep -q -e "^refresh" &&
- stg log --full | grep -q -e "^refresh"
- '
-
-test_expect_success \
- 'Check the log annotation' \
- '
- stg log foo | grep -q -e "\[refresh\] foo notes " &&
- stg log bar | grep -q -e "\[refresh\] " &&
- stg refresh -p foo --annotate="foo notes 2" &&
- stg log foo | grep -q -v -e "\[refresh\] foo notes " &&
- stg log foo | grep -q -e "\[refresh\] foo notes 2"
- '
-
-test_expect_success \
- 'Check the "push" log' \
- '
- stg pop &&
- echo foo > test2 && git add test2 && stg refresh &&
- stg push &&
- stg log --full | grep -q -e "^push "
- '
-
-test_expect_success \
- 'Check the "push(f)" log' \
- '
- stg pop &&
- stg edit -m "Foo2 Patch" &&
- stg push &&
- stg log --full | grep -q -e "^push(f) "
- '
-
-test_expect_success \
- 'Check the "push(m)" log' \
- '
- stg pop &&
- echo foo2 > test && stg refresh &&
- stg push &&
- stg log --full | grep -q -e "^push(m) "
- '
-
-test_expect_success \
- 'Check the "push(c)" log' \
- '
- echo bar > test && stg refresh &&
- stg pop &&
- echo foo > test && stg refresh &&
- ! stg push &&
- stg log --full | grep -q -e "^push(c) "
- '
-
-test_expect_success \
- 'Check the push "undo" log' \
- '
- stg push --undo &&
- stg log --full bar | grep -q -e "^undo "
- '
-
-test_expect_success \
- 'Check the refresh "undo" log' \
- '
- stg refresh --undo &&
- stg log --full | grep -q -e "^undo "
- '
-
-test_done
prev parent reply other threads:[~2008-06-12 5:37 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-12 5:34 [StGit PATCH 00/14] Undo series Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 01/14] Fix typo Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 02/14] Library functions for tree and blob manipulation Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 03/14] Write to a stack log when stack is modified Karl Hasselström
2008-06-17 10:24 ` Catalin Marinas
2008-06-17 12:31 ` Karl Hasselström
2008-06-17 12:55 ` Karl Hasselström
2008-06-17 14:11 ` Catalin Marinas
2008-06-17 15:32 ` Karl Hasselström
2008-06-18 13:03 ` Catalin Marinas
2008-06-18 14:36 ` Karl Hasselström
2008-06-18 16:16 ` Catalin Marinas
2008-06-18 17:32 ` Karl Hasselström
2008-06-19 9:24 ` Catalin Marinas
2008-06-19 10:07 ` Karl Hasselström
2008-06-20 9:14 ` Catalin Marinas
2008-06-23 12:36 ` Karl Hasselström
2008-07-12 10:09 ` Catalin Marinas
2008-07-14 6:32 ` Karl Hasselström
2008-07-01 20:13 ` Karl Hasselström
2008-07-03 22:05 ` Catalin Marinas
2008-06-12 5:34 ` [StGit PATCH 04/14] Add utility function for reordering patches Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 05/14] New command: stg reset Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 06/14] Log conflicts separately Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 07/14] Log conflicts separately for all commands Karl Hasselström
2008-06-12 5:34 ` [StGit PATCH 08/14] Add a --hard flag to stg reset Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 09/14] Don't write a log entry if there were no changes Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 10/14] Move stack reset function to a shared location Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 11/14] New command: stg undo Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 12/14] New command: stg redo Karl Hasselström
2008-06-12 5:35 ` [StGit PATCH 13/14] Log and undo external modifications Karl Hasselström
2008-06-12 5:35 ` Karl Hasselström [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080612053531.23549.77890.stgit@yoghurt \
--to=kha@treskal.com \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).