From 2d0f10fb98274e3b3827bf227e42e420f878f1d1 Mon Sep 17 00:00:00 2001 From: Juergen Wieferink Date: Fri, 22 Oct 2010 16:44:13 +0100 Subject: [PATCH] Fix stg repair for hidden patches Signed-off-by: Juergen Wieferink Signed-off-by: Catalin Marinas --- stgit/commands/repair.py | 19 ++++++++++++++----- stgit/stack.py | 3 +++ t/t1304-repair-hidden.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100755 t/t1304-repair-hidden.sh diff --git a/stgit/commands/repair.py b/stgit/commands/repair.py index 5804a12..2e22150 100644 --- a/stgit/commands/repair.py +++ b/stgit/commands/repair.py @@ -121,6 +121,7 @@ def func(parser, options, args): orig_applied = crt_series.get_applied() orig_unapplied = crt_series.get_unapplied() + orig_hidden = crt_series.get_hidden() if crt_series.get_protected(): raise CmdException( @@ -184,22 +185,29 @@ def func(parser, options, args): names.add(name) out.done() + # Figure out hidden + orig_patches = orig_applied + orig_unapplied + orig_hidden + orig_applied_name_set = set(orig_applied) + orig_unapplied_name_set = set(orig_unapplied) + orig_hidden_name_set = set(orig_hidden) + orig_patches_name_set = set(orig_patches) + hidden = [p for p in patches if p.patch in orig_hidden_name_set] + # Write the applied/unapplied files. out.start('Checking patch appliedness') - unapplied = patches - set(applied) + unapplied = patches - set(applied) - set(hidden) applied_name_set = set(p.patch for p in applied) unapplied_name_set = set(p.patch for p in unapplied) + hidden_name_set = set(p.patch for p in hidden) patches_name_set = set(p.patch for p in patches) - orig_patches = orig_applied + orig_unapplied - orig_applied_name_set = set(orig_applied) - orig_unapplied_name_set = set(orig_unapplied) - orig_patches_name_set = set(orig_patches) for name in orig_patches_name_set - patches_name_set: out.info('%s is gone' % name) for name in applied_name_set - orig_applied_name_set: out.info('%s is now applied' % name) for name in unapplied_name_set - orig_unapplied_name_set: out.info('%s is now unapplied' % name) + for name in hidden_name_set - orig_hidden_name_set: + out.info('%s is now hidden' % name) orig_order = dict(zip(orig_patches, xrange(len(orig_patches)))) def patchname_cmp(p1, p2): i1 = orig_order.get(p1, len(orig_order)) @@ -207,4 +215,5 @@ def func(parser, options, args): return cmp((i1, p1), (i2, p2)) crt_series.set_applied(p.patch for p in applied) crt_series.set_unapplied(sorted(unapplied_name_set, cmp = patchname_cmp)) + crt_series.set_hidden(sorted(hidden_name_set, cmp = patchname_cmp)) out.done() diff --git a/stgit/stack.py b/stgit/stack.py index 93647f2..f166aea 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -438,6 +438,9 @@ class Series(PatchSet): return [] return read_strings(self.__hidden_file) + def set_hidden(self, hidden): + write_strings(self.__hidden_file, hidden) + def get_base(self): # Return the parent of the bottommost patch, if there is one. if os.path.isfile(self.__applied_file): diff --git a/t/t1304-repair-hidden.sh b/t/t1304-repair-hidden.sh new file mode 100755 index 0000000..ffbcef8 --- /dev/null +++ b/t/t1304-repair-hidden.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# +# Copyright (c) 2010 Juergen Wieferink +# + +test_description='Test repair with hidden patches + +' + +. ./test-lib.sh + +test_expect_success \ + 'Initialize the StGIT repository' \ + 'stg init && + stg new A -m "a" && echo A >a.txt && stg add a.txt && stg refresh && + stg new B -m "b" && echo B >b.txt && stg add b.txt && stg refresh && + stg new C -m "c" && echo C >c.txt && stg add c.txt && stg refresh && + stg new D -m "d" && echo D >d.txt && stg add d.txt && stg refresh && + stg pop && stg hide D && + stg pop && + test "$(echo $(stg series --applied --noprefix))" = "A B" && + test "$(echo $(stg series --unapplied --noprefix))" = "C" && + test "$(echo $(stg series --hidden --noprefix))" = "D" + ' + +test_expect_success \ + 'Repair and check that nothing has changed' \ + 'stg repair && + test "$(echo $(stg series --applied --noprefix))" = "A B" && + test "$(echo $(stg series --unapplied --noprefix))" = "C" && + test "$(echo $(stg series --hidden --noprefix))" = "D" + ' + +test_expect_success \ + 'Nontrivial repair' \ + 'echo Z >z.txt && git add z.txt && git commit -m z && + stg repair && + test "$(echo $(stg series --applied --noprefix))" = "A B z" && + test "$(echo $(stg series --unapplied --noprefix))" = "C" && + test "$(echo $(stg series --hidden --noprefix))" = "D" + ' + +test_done -- 2.11.0