chiark / gitweb /
Add a patches command
authorCatalin Marinas <catalin.marinas@gmail.com>
Fri, 4 Nov 2005 16:05:06 +0000 (16:05 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Fri, 4 Nov 2005 16:05:06 +0000 (16:05 +0000)
This command shows the patches that modify a given file.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
TODO
stgit/commands/patches.py [new file with mode: 0644]
stgit/git.py
stgit/main.py

diff --git a/TODO b/TODO
index 34adeffbfcce10bbde4d81f3a0bc8d9235771bc1..b652725a05d9aaa51d2443c1daa44afe8c97a9ac 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,5 @@
 The TODO list until 1.0:
 
-- branch control command
 - prune command which preserves the unapplied patches as well
 - tag (snapshot) command
 - log command (it should also show the log per single patch)
@@ -11,7 +10,6 @@ The TODO list until 1.0:
 
 The future, when time allows or someone else does it:
 
-- patches command to show the patches modifying a file
 - patch dependency tracking
 - multiple heads in a patch - useful for forking a patch,
   synchronising with other patches (diff format or in other
diff --git a/stgit/commands/patches.py b/stgit/commands/patches.py
new file mode 100644 (file)
index 0000000..c0f2ba8
--- /dev/null
@@ -0,0 +1,69 @@
+__copyright__ = """
+Copyright (C) 2005, Catalin Marinas <catalin.marinas@gmail.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
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+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
+from optparse import OptionParser, make_option
+
+from stgit.commands.common import *
+from stgit.utils import *
+from stgit import stack, git
+
+
+help = 'show the patches modifying a file'
+usage = """%prog [options] <file> [<file>...]
+
+Show the applied patches modifying the given files. The '--diff'
+option also lists the patch log and the diff for the given files."""
+
+options = [make_option('-d', '--diff',
+                       help = 'show the diff for the given files',
+                       action = 'store_true')]
+
+
+def func(parser, options, args):
+    """Show the patches modifying a file
+    """
+    if len(args) < 1:
+        parser.error('incorrect number of arguments')
+
+    applied = crt_series.get_applied()
+    if not applied:
+        raise CmdException, 'No patches applied'
+
+    revs = git.modifying_revs(args, git_id('base'))
+    revs.reverse()
+
+    # build the patch/revision mapping
+    rev_patch = dict()
+    for name in applied:
+        patch = crt_series.get_patch(name)
+        rev_patch[patch.get_top()] = patch
+
+    # print the patch names
+    for rev in revs:
+        if rev in rev_patch:
+            patch = rev_patch[rev]
+            if options.diff:
+                print '-------------------------------------------------------------------------------'
+                print patch.get_name()
+                print '-------------------------------------------------------------------------------'
+                print patch.get_description(),
+                print '---'
+                print
+                print git.diff(args, patch.get_bottom(), patch.get_top())
+            else:
+                print patch.get_name()
index b6e47c3f95a781f6a56b81d5872bfe60c549f6c6..a615ccf8bb8dcecb9a237deb01fe6953d35bdb07 100644 (file)
@@ -661,3 +661,11 @@ def clone(repository, local_dir):
     if __run('git clone', [repository, local_dir]) != 0:
         raise GitException, 'Failed "git clone %s %s"' \
               % (repository, local_dir)
+
+def modifying_revs(files, base_rev):
+    """Return the revisions from the list modifying the given files
+    """
+    cmd = ['git-rev-list', '%s..' % base_rev, '--']
+    revs = [line.strip() for line in _output_lines(cmd + files)]
+
+    return revs
index 5fba58c394f2511a81484dfc306c7c1bff7cdf84..b84d91d39e0f5544cb74cbe3966ae957a60aa1a7 100644 (file)
@@ -44,6 +44,7 @@ import stgit.commands.imprt
 import stgit.commands.init
 import stgit.commands.mail
 import stgit.commands.new
+import stgit.commands.patches
 import stgit.commands.pick
 import stgit.commands.pop
 import stgit.commands.pull
@@ -78,6 +79,7 @@ commands = {
     'init':     stgit.commands.init,
     'mail':     stgit.commands.mail,
     'new':      stgit.commands.new,
+    'patches':  stgit.commands.patches,
     'pick':     stgit.commands.pick,
     'pop':      stgit.commands.pop,
     'pull':     stgit.commands.pull,