From a9f3a9fc26bfad2168af83997e088247acccb1ee Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Tue, 20 Feb 2007 01:14:03 +0100 Subject: [PATCH] Factorize rebasing behaviour. Signed-off-by: Yann Dirson --- stgit/commands/common.py | 23 +++++++++++++++++++++++ stgit/commands/pull.py | 20 ++++---------------- stgit/commands/rebase.py | 17 +++-------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 0d99992..aa0409a 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -347,3 +347,26 @@ def make_patch_name(msg, unacceptable, default_name = 'patch', suffix += 1 patchname = '%s-%d' % (patchname, suffix) return patchname + +def prepare_rebase(): + # pop all patches + applied = crt_series.get_applied() + if len(applied) > 0: + print 'Popping all applied patches...', + sys.stdout.flush() + crt_series.pop_patch(applied[0]) + print 'done' + return applied + +def rebase(target): + if target == git.get_head(): + print 'Already at "%s", no need for rebasing.' % target + return + + print 'Rebasing to "%s"...' % target + git.reset(tree_id = git_id(target)) + +def post_rebase(applied, nopush, merged): + # push the patches back + if not nopush: + push_patches(applied, merged) diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py index 2d4a782..83a2725 100644 --- a/stgit/commands/pull.py +++ b/stgit/commands/pull.py @@ -61,27 +61,15 @@ def func(parser, options, args): check_conflicts() check_head_top_equal() - # pop all patches - applied = crt_series.get_applied() - if len(applied) > 0: - print 'Popping all applied patches...', - sys.stdout.flush() - crt_series.pop_patch(applied[0]) - print 'done' + applied = prepare_rebase() # pull the remote changes print 'Pulling from "%s"...' % repository git.fetch(repository) if (config.get('stgit.pull-does-rebase') == 'yes'): - fetch_head = git.fetch_head() - if fetch_head != git.get_head(): - print 'rebasing to "%s"...' % fetch_head - git.reset(tree_id = fetch_head) - print 'done' - - # push the patches back - if not options.nopush: - push_patches(applied, options.merged) + rebase(git.fetch_head()) + + post_rebase(applied, options.nopush, options.merged) # maybe tidy up if config.get('stgit.keepoptimized') == 'yes': diff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py index 2951421..63f18ec 100644 --- a/stgit/commands/rebase.py +++ b/stgit/commands/rebase.py @@ -49,19 +49,8 @@ def func(parser, options, args): check_conflicts() check_head_top_equal() - # pop all patches - applied = crt_series.get_applied() - if len(applied) > 0: - print 'Popping all applied patches...', - sys.stdout.flush() - crt_series.pop_patch(applied[0]) - print 'done' - - print 'Rebasing to "%s"...' % args[0] - git.reset(tree_id = git_id(args[0])) - - # push the patches back - if not options.nopush: - push_patches(applied, options.merged) + applied = prepare_rebase() + rebase(args[0]) + post_rebase(applied, options.nopush, options.merged) print_crt_patch() -- 2.11.0