From cd25e03d30c7b3a3a0babf039446d626dbb5607b Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Fri, 4 Nov 2005 16:05:06 +0000 Subject: [PATCH] Add a patches command This command shows the patches that modify a given file. Signed-off-by: Catalin Marinas --- TODO | 2 -- stgit/commands/patches.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ stgit/git.py | 8 ++++++ stgit/main.py | 2 ++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 stgit/commands/patches.py diff --git a/TODO b/TODO index 34adeff..b652725 100644 --- 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 index 0000000..c0f2ba8 --- /dev/null +++ b/stgit/commands/patches.py @@ -0,0 +1,69 @@ +__copyright__ = """ +Copyright (C) 2005, Catalin Marinas + +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] [...] + +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() diff --git a/stgit/git.py b/stgit/git.py index b6e47c3..a615ccf 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -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 diff --git a/stgit/main.py b/stgit/main.py index 5fba58c..b84d91d 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -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, -- 2.11.0