From 0618ea9c955bc7015ec5a7cccac66760738c9644 Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Tue, 27 Sep 2005 17:29:48 +0100 Subject: [PATCH] Implement a 'pick' command for cherry-picking The initial cherry-picking implementation in import was quite hard to find and the import command became pretty hard to use. Signed-off-by: Catalin Marinas --- stgit/commands/pick.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ stgit/git.py | 2 +- stgit/main.py | 2 ++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 stgit/commands/pick.py diff --git a/stgit/commands/pick.py b/stgit/commands/pick.py new file mode 100644 index 0000000..e8f4dfa --- /dev/null +++ b/stgit/commands/pick.py @@ -0,0 +1,87 @@ +__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 = 'import a patch from a different branch or a commit object' +usage = """%prog [options] [|] + +Import a patch from a different branch or a commit object into the +current series. By default, the name of the imported patch is used as +the name of the current patch. It can be overriden with the '--name' +option. A commit object can be reverted with the '--reverse' +option. The log and author information are those of the commit object.""" + +options = [make_option('-n', '--name', + help = 'use NAME as the patch name'), + make_option('-r', '--reverse', + help = 'reverse the commit object before importing', + action = 'store_true')] + + +def func(parser, options, args): + """Import a commit object as a new patch + """ + if len(args) != 1: + parser.error('incorrect number of arguments') + + check_local_changes() + check_conflicts() + check_head_top_equal() + + commit_str = args[0] + patch_branch = commit_str.split('@') + + if len(patch_branch) == 2: + patch = patch_branch[0] + elif options.name: + patch = options.name + else: + raise CmdException, 'Unkown patch name' + + commit_id = git_id(commit_str) + commit = git.Commit(commit_id) + + if not options.reverse: + bottom = commit.get_parent() + top = commit_id + else: + bottom = commit_id + top = commit.get_parent() + + message = commit.get_log() + author_name, author_email, author_date = \ + name_email_date(commit.get_author()) + + print 'Importing commit %s...' % commit_id, + sys.stdout.flush() + + crt_series.new_patch(patch, message = message, can_edit = False, + unapplied = True, bottom = bottom, top = top, + author_name = author_name, + author_email = author_email, + author_date = author_date) + crt_series.push_patch(patch) + + print 'done' + print_crt_patch() diff --git a/stgit/git.py b/stgit/git.py index a45671b..0fee709 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -59,7 +59,7 @@ class Commit: self.__author = field[1] if field[0] == 'committer': self.__committer = field[1] - self.__log = ''.join(lines[i:]) + self.__log = ''.join(lines[i+1:]) def get_id_hash(self): return self.__id_hash diff --git a/stgit/main.py b/stgit/main.py index ed57668..857e60b 100644 --- a/stgit/main.py +++ b/stgit/main.py @@ -42,6 +42,7 @@ import stgit.commands.imprt import stgit.commands.init import stgit.commands.mail import stgit.commands.new +import stgit.commands.pick import stgit.commands.pop import stgit.commands.pull import stgit.commands.push @@ -73,6 +74,7 @@ commands = { 'init': stgit.commands.init, 'mail': stgit.commands.mail, 'new': stgit.commands.new, + 'pick': stgit.commands.pick, 'pop': stgit.commands.pop, 'pull': stgit.commands.pull, 'push': stgit.commands.push, -- 2.11.0