From: Yann Dirson Date: Tue, 12 Jun 2007 21:57:06 +0000 (+0100) Subject: Revert 'Changed rebasing safety check to look for reachability of X-Git-Tag: v0.13~35 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/fb1cf8ec7442c555fa9d9006f3df5d47c53353c7 Revert 'Changed rebasing safety check to look for reachability of stack base (gna bug #9181).' This patch is reverting commit bd69feaf7c3c94b6e7e216ea8091064af9cdfa97 (patch not yet ready for the master branch). Signed-off-by: Catalin Marinas --- diff --git a/stgit/commands/common.py b/stgit/commands/common.py index 88c60ef..22c78ae 100644 --- a/stgit/commands/common.py +++ b/stgit/commands/common.py @@ -318,22 +318,13 @@ def address_or_alias(addr_str): for addr in addr_str.split(',')] return ', '.join([addr for addr in addr_list if addr]) -def prepare_rebase(force=None): +def prepare_rebase(real_rebase, force=None): if not force: - # Be sure we won't loose results of stg-commit by error. - # Note: checking for refs/bases should not be necessary with - # repo format version 2, but better safe than sorry. - branchname = crt_series.get_name() - # references for anything but the current stack - refs = [ref for ref in git.all_refs() - if ref != 'refs/heads/'+branchname - and ref != 'refs/bases/'+branchname - and not re.match('^refs/patches/%s/'%branchname, ref)] - stray_commits = git._output_lines(['git-rev-list', - crt_series.get_base(), - '--not'] + refs) - if len(stray_commits) != 0: - raise CmdException, 'Rebasing would make the following commits below the stack base unreachable: %s' % stray_commits + # Be sure we won't loose results of stg-(un)commit by error. + # Do not require an existing orig-base for compatibility with 0.12 and earlier. + origbase = crt_series._get_field('orig-base') + if origbase and crt_series.get_base() != origbase: + raise CmdException, 'Rebasing would possibly lose data' # pop all patches applied = crt_series.get_applied() @@ -352,6 +343,8 @@ def rebase(target): out.done() def post_rebase(applied, nopush, merged): + # memorize that we rebased to here + crt_series._set_field('orig-base', git.get_head()) # push the patches back if not nopush: push_patches(applied, merged) diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py index b20c37e..5f72f9b 100644 --- a/stgit/commands/pull.py +++ b/stgit/commands/pull.py @@ -77,12 +77,16 @@ def func(parser, options, args): check_conflicts() check_head_top_equal() - if (policy != 'pull') \ - and (policy != 'fetch-rebase') \ - and (policy != 'rebase'): + if policy == 'pull': + must_rebase = 0 + elif policy == 'fetch-rebase': + must_rebase = 1 + elif policy == 'rebase': + must_rebase = 1 + else: raise GitConfigException, 'Unsupported pull-policy "%s"' % policy - applied = prepare_rebase(force=options.force) + applied = prepare_rebase(real_rebase=must_rebase, force=options.force) # pull the remote changes if policy == 'pull': diff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py index e47772c..2f0e660 100644 --- a/stgit/commands/rebase.py +++ b/stgit/commands/rebase.py @@ -56,7 +56,7 @@ def func(parser, options, args): if git_id(args[0]) == None: raise GitException, 'Unknown revision: %s' % git_id - applied = prepare_rebase(force=options.force) + applied = prepare_rebase(real_rebase=True, force=options.force) rebase(args[0]) post_rebase(applied, options.nopush, options.merged) diff --git a/stgit/git.py b/stgit/git.py index 047c040..6c96a16 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -1070,9 +1070,3 @@ def fetch_head(): # here we are sure to have a single fetch_head return fetch_head - -def all_refs(): - """Return a list of all refs in the current repository. - """ - - return [line.split()[1] for line in _output_lines(['git-show-ref'])] diff --git a/stgit/stack.py b/stgit/stack.py index dee8c38..634588d 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -588,6 +588,7 @@ class Series(PatchSet): self.create_empty_field('applied') self.create_empty_field('unapplied') os.makedirs(self.__refs_dir) + self._set_field('orig-base', git.get_head()) config.set(self.format_version_key(), str(FORMAT_VERSION))