{"thread":{"id":"8618","subject":"[StGIT PATCH 0/9] Refactoring of command handling","startedAt":"2007-06-16T22:00:28Z","lastAt":"2007-06-19T22:41:17Z","messageCount":10,"participants":["Yann Dirson"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"45183","messageId":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":null,"subject":"[StGIT PATCH 0/9] Refactoring of command handling","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:00:28Z","receivedAt":"2007-06-16T22:00:28Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"While working on hydra support, I've hit a couple of issues which I\nhave handled with a set of relatively large patches: nearly every line\nof code under stgit/commands/ gets reindented, because of functions\nbeing changed to instance methods.\n\nI submit this patchset early, despite it being very young, because of\nthe high risk of conflict with other work and the large amount work it\nwould require to maintain in parallel - also, since the testsuite does\nnot cover everything, it is likely that I left a couple of errors\nsomewhere, and I'd be grateful to have other people shake the code as\nwell.  Now this set of patches would be a great candidate for a \"pu\"\nbranch :)\n\nThe next refactoring pass (already in the works but with no\nstabilized design yet) will tackle git_id(), which should be\navailable at generic level, not at the command level.  I'm heading\ntowards changing it to be a method of a new stgit.Repository class,\npointed to by Commands and PatchSets.\n\nHere is a quick summary:\n\n      Refactor command definition with a Command class.\n      Promote more common functions to Command methods.\n      Replace crt_series uses with a method call.\n\t=> those are the heart of the refactoring: we suppress the\n\t   crt_series global and only create the Series object when\n\t   needed.  This is a step towards a PatchSet factory which\n\t   will be able to instantiate a Series or an Hydra from a\n\t   head name, without a need for the called to be aware of the\n\t   existence of PatchSet subclasses.\n\n      Fixed thinko in error message.\n      Add a constructor to PatchSet.\n      Cleanup the use of the Series class.\n      Changed sync not to use -b which has other semantics.\n\t=> cleanup needs discovered while refactoring\n\n      Fix contrib/stg-whatchanged way of identifying a conflict.\n\t=> fixing the tools that help getting the patches done :)\n      Revert part of the reverted commit that we want to keep.\n\t=> mostly here so we don't loose it, and limit the conflicts\n\t  when I pulled from you :)\n\nBest regards,\n-- \nYann Dirson    <ydirson@altern.org> |\nDebian-related: <dirson@debian.org> |   Support Debian GNU/Linux:\n                                    |  Freedom, Power, Stability, Gratis\n     http://ydirson.free.fr/        | Check <http://www.debian.org/>\n"},{"id":"45184","messageId":"20070616220034.14941.949.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 1/9] Fix contrib/stg-whatchanged way of identifying a conflict.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:00:34Z","receivedAt":"2007-06-16T22:00:34Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Signed-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n contrib/stg-whatchanged |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/stg-whatchanged b/contrib/stg-whatchanged\nindex d5b6965..27513d9 100755\n--- a/contrib/stg-whatchanged\n+++ b/contrib/stg-whatchanged\n@@ -24,7 +24,7 @@ fi\n # Merges via \"push\" leave top=bottom so we must look at old patch\n # in this case (unlike, eg., \"pick --fold\")\n patchdir=\"$(git-rev-parse --git-dir)/patches/$(stg branch)/patches/$(stg top)\"\n-if [ $(cat \"$patchdir/bottom\") = $(cat \"$patchdir/top\") ];\n+if [ -e \"$(git-rev-parse --git-dir)/conflicts\" ];\n then\n     current_cmd=\"stg show //top.old\"\n else\n"},{"id":"45185","messageId":"20070616220039.14941.41891.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 2/9] Revert part of the reverted commit that we want to keep.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:00:39Z","receivedAt":"2007-06-16T22:00:39Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"- get rid of unused real_rebase parameter\n- revive git.all_refs()\n\nThis commit can freely be used to demonstrate the usefulness of\n_always_ separating different issues in different patches :)\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/common.py |    2 +-\n stgit/commands/pull.py   |    2 +-\n stgit/commands/rebase.py |    2 +-\n stgit/git.py             |    6 ++++++\n 4 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/stgit/commands/common.py b/stgit/commands/common.py\nindex 22c78ae..b05979b 100644\n--- a/stgit/commands/common.py\n+++ b/stgit/commands/common.py\n@@ -318,7 +318,7 @@ def address_or_alias(addr_str):\n                  for addr in addr_str.split(',')]\n     return ', '.join([addr for addr in addr_list if addr])\n \n-def prepare_rebase(real_rebase, force=None):\n+def prepare_rebase(force=None):\n     if not force:\n         # Be sure we won't loose results of stg-(un)commit by error.\n         # Do not require an existing orig-base for compatibility with 0.12 and earlier.\ndiff --git a/stgit/commands/pull.py b/stgit/commands/pull.py\nindex 5f72f9b..fe3b67d 100644\n--- a/stgit/commands/pull.py\n+++ b/stgit/commands/pull.py\n@@ -86,7 +86,7 @@ def func(parser, options, args):\n     else:\n         raise GitConfigException, 'Unsupported pull-policy \"%s\"' % policy\n \n-    applied = prepare_rebase(real_rebase=must_rebase, force=options.force)\n+    applied = prepare_rebase(force=options.force)\n \n     # pull the remote changes\n     if policy == 'pull':\ndiff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py\nindex 2f0e660..e47772c 100644\n--- a/stgit/commands/rebase.py\n+++ b/stgit/commands/rebase.py\n@@ -56,7 +56,7 @@ def func(parser, options, args):\n     if git_id(args[0]) == None:\n         raise GitException, 'Unknown revision: %s' % git_id\n         \n-    applied = prepare_rebase(real_rebase=True, force=options.force)\n+    applied = prepare_rebase(force=options.force)\n     rebase(args[0])\n     post_rebase(applied, options.nopush, options.merged)\n \ndiff --git a/stgit/git.py b/stgit/git.py\nindex 6c96a16..047c040 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -1070,3 +1070,9 @@ def fetch_head():\n \n     # here we are sure to have a single fetch_head\n     return fetch_head\n+\n+def all_refs():\n+    \"\"\"Return a list of all refs in the current repository.\n+    \"\"\"\n+\n+    return [line.split()[1] for line in _output_lines(['git-show-ref'])]\n"},{"id":"45186","messageId":"20070616220049.14941.26563.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 4/9] Fixed thinko in error message.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:00:50Z","receivedAt":"2007-06-16T22:00:50Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Signed-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/rebase.py |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py\nindex 1cde2ad..111d78e 100644\n--- a/stgit/commands/rebase.py\n+++ b/stgit/commands/rebase.py\n@@ -55,7 +55,7 @@ class concreteCommand(Command):\n \n         # ensure an exception is raised before popping on non-existent target\n         if git_id(self.args[0]) == None:\n-            raise GitException, 'Unknown revision: %s' % git_id\n+            raise GitException, 'Unknown revision: %s' % git_id(self.args[0])\n \n         applied = prepare_rebase(force=self.flags.force)\n         rebase(self.args[0])\n"},{"id":"45188","messageId":"20070616220055.14941.77446.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 5/9] Promote more common functions to Command methods.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:00:55Z","receivedAt":"2007-06-16T22:00:55Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Signed-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/branch.py  |   10 +-\n stgit/commands/clean.py   |    4 -\n stgit/commands/commit.py  |    2 \n stgit/commands/common.py  |  270 +++++++++++++++++++++++----------------------\n stgit/commands/delete.py  |    4 -\n stgit/commands/diff.py    |    4 -\n stgit/commands/files.py   |    4 -\n stgit/commands/float.py   |    6 +\n stgit/commands/fold.py    |    4 -\n stgit/commands/goto.py    |    8 +\n stgit/commands/id.py      |    2 \n stgit/commands/imprt.py   |    6 +\n stgit/commands/mail.py    |    8 +\n stgit/commands/new.py     |    2 \n stgit/commands/pick.py    |   12 +-\n stgit/commands/pop.py     |    8 +\n stgit/commands/pull.py    |   12 +-\n stgit/commands/push.py    |    8 +\n stgit/commands/rebase.py  |   14 +-\n stgit/commands/refresh.py |    6 +\n stgit/commands/series.py  |    4 -\n stgit/commands/show.py    |    2 \n stgit/commands/sink.py    |    6 +\n stgit/commands/sync.py    |    8 +\n 24 files changed, 207 insertions(+), 207 deletions(-)\n\ndiff --git a/stgit/commands/branch.py b/stgit/commands/branch.py\nindex 9777fad..e243830 100644\n--- a/stgit/commands/branch.py\n+++ b/stgit/commands/branch.py\n@@ -98,7 +98,7 @@ class concreteCommand(Command):\n         if self.__is_current_branch(doomed_name):\n             check_local_changes()\n             check_conflicts()\n-            check_head_top_equal()\n+            self.check_head_top_equal()\n \n             if doomed_name != 'master':\n                 git.switch_branch('master')\n@@ -119,7 +119,7 @@ class concreteCommand(Command):\n \n             check_local_changes()\n             check_conflicts()\n-            check_head_top_equal()\n+            self.check_head_top_equal()\n \n             tree_id = None\n             if len(self.args) >= 2:\n@@ -143,7 +143,7 @@ class concreteCommand(Command):\n                              ' from \"%s\"' % self.args[1])\n                     parentbranch = None\n \n-                tree_id = git_id(self.args[1])\n+                tree_id = self.git_id(self.args[1])\n             else:\n                 # branch stack off current branch\n                 parentbranch = git.get_head_file()\n@@ -178,7 +178,7 @@ class concreteCommand(Command):\n \n             check_local_changes()\n             check_conflicts()\n-            check_head_top_equal()\n+            self.check_head_top_equal()\n \n             out.start('Cloning current branch to \"%s\"' % clone)\n             crt_series.clone(clone)\n@@ -293,7 +293,7 @@ class concreteCommand(Command):\n \n             check_local_changes()\n             check_conflicts()\n-            check_head_top_equal()\n+            self.check_head_top_equal()\n \n             out.start('Switching to branch \"%s\"' % self.args[0])\n             git.switch_branch(self.args[0])\ndiff --git a/stgit/commands/clean.py b/stgit/commands/clean.py\nindex 10ee89e..3e9d829 100644\n--- a/stgit/commands/clean.py\n+++ b/stgit/commands/clean.py\n@@ -60,7 +60,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         if not (self.flags.applied or self.flags.unapplied):\n             self.flags.applied = self.flags.unapplied = True\n@@ -73,4 +73,4 @@ class concreteCommand(Command):\n             unapplied = crt_series.get_unapplied()\n             self.__delete_empty(unapplied, False)\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/commit.py b/stgit/commands/commit.py\nindex 6e7bf13..56f3943 100644\n--- a/stgit/commands/commit.py\n+++ b/stgit/commands/commit.py\n@@ -42,7 +42,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         applied = crt_series.get_applied()\n         if not applied:\ndiff --git a/stgit/commands/common.py b/stgit/commands/common.py\nindex 60a6a7a..1ed5086 100644\n--- a/stgit/commands/common.py\n+++ b/stgit/commands/common.py\n@@ -71,6 +71,141 @@ class Command:\n         self.parser = OptionParser(usage = shortusage, option_list = self.options)\n         self.flags, self.args = self.parser.parse_args()\n \n+    def git_id(self, rev):\n+        \"\"\"Return the GIT id\n+        \"\"\"\n+        if not rev:\n+            return None\n+        try:\n+            patch, branch, patch_id = parse_rev(rev)\n+            if branch == None:\n+                series = crt_series\n+            else:\n+                series = stack.Series(branch)\n+            if patch == None:\n+                patch = series.get_current()\n+                if not patch:\n+                    raise CmdException, 'No patches applied'\n+            if patch in series.get_applied() or patch in series.get_unapplied():\n+                if patch_id in ['top', '', None]:\n+                    return series.get_patch(patch).get_top()\n+                elif patch_id == 'bottom':\n+                    return series.get_patch(patch).get_bottom()\n+                elif patch_id == 'top.old':\n+                    return series.get_patch(patch).get_old_top()\n+                elif patch_id == 'bottom.old':\n+                    return series.get_patch(patch).get_old_bottom()\n+                elif patch_id == 'log':\n+                    return series.get_patch(patch).get_log()\n+            if patch == 'base' and patch_id == None:\n+                return series.get_base()\n+        except RevParseException:\n+            pass\n+        return git.rev_parse(rev + '^{commit}')\n+\n+    def check_head_top_equal(self):\n+        if not crt_series.head_top_equal():\n+            raise CmdException(\n+                'HEAD and top are not the same. You probably committed\\n'\n+                '  changes to the tree outside of StGIT. To bring them\\n'\n+                '  into StGIT, use the \"assimilate\" command')\n+\n+    def print_crt_patch(self, branch = None):\n+        if not branch:\n+            patch = crt_series.get_current()\n+        else:\n+            patch = stack.Series(branch).get_current()\n+\n+        if patch:\n+            out.info('Now at patch \"%s\"' % patch)\n+        else:\n+            out.info('No patches applied')\n+\n+    def push_patches(self, patches, check_merged = False):\n+        \"\"\"Push multiple patches onto the stack. This function is shared\n+        between the push and pull commands\n+        \"\"\"\n+        forwarded = crt_series.forward_patches(patches)\n+        if forwarded > 1:\n+            out.info('Fast-forwarded patches \"%s\" - \"%s\"'\n+                     % (patches[0], patches[forwarded - 1]))\n+        elif forwarded == 1:\n+            out.info('Fast-forwarded patch \"%s\"' % patches[0])\n+\n+        names = patches[forwarded:]\n+\n+        # check for patches merged upstream\n+        if names and check_merged:\n+            out.start('Checking for patches merged upstream')\n+\n+            merged = crt_series.merged_patches(names)\n+\n+            out.done('%d found' % len(merged))\n+        else:\n+            merged = []\n+\n+        for p in names:\n+            out.start('Pushing patch \"%s\"' % p)\n+\n+            if p in merged:\n+                crt_series.push_patch(p, empty = True)\n+                out.done('merged upstream')\n+            else:\n+                modified = crt_series.push_patch(p)\n+\n+                if crt_series.empty_patch(p):\n+                    out.done('empty patch')\n+                elif modified:\n+                    out.done('modified')\n+                else:\n+                    out.done()\n+\n+    def pop_patches(self, patches, keep = False):\n+        \"\"\"Pop the patches in the list from the stack. It is assumed that\n+        the patches are listed in the stack reverse order.\n+        \"\"\"\n+        if len(patches) == 0:\n+            out.info('Nothing to push/pop')\n+        else:\n+            p = patches[-1]\n+            if len(patches) == 1:\n+                out.start('Popping patch \"%s\"' % p)\n+            else:\n+                out.start('Popping patches \"%s\" - \"%s\"' % (patches[0], p))\n+            crt_series.pop_patch(p, keep)\n+            out.done()\n+\n+    def prepare_rebase(self, force=None):\n+        if not force:\n+            # Be sure we won't loose results of stg-(un)commit by error.\n+            # Do not require an existing orig-base for compatibility with 0.12 and earlier.\n+            origbase = crt_series._get_field('orig-base')\n+            if origbase and crt_series.get_base() != origbase:\n+                raise CmdException, 'Rebasing would possibly lose data'\n+\n+        # pop all patches\n+        applied = crt_series.get_applied()\n+        if len(applied) > 0:\n+            out.start('Popping all applied patches')\n+            crt_series.pop_patch(applied[0])\n+            out.done()\n+        return applied\n+\n+    def rebase(self, target):\n+        if target == git.get_head():\n+            out.info('Already at \"%s\", no need for rebasing.' % target)\n+            return\n+        out.start('Rebasing to \"%s\"' % target)\n+        git.reset(tree_id = self.git_id(target))\n+        out.done()\n+\n+    def post_rebase(self, applied, nopush, merged):\n+        # memorize that we rebased to here\n+        crt_series._set_field('orig-base', git.get_head())\n+        # push the patches back\n+        if not nopush:\n+            self.push_patches(applied, merged)\n+\n # Utility functions\n def parse_rev(rev):\n     \"\"\"Parse a revision specification into its\n@@ -108,67 +243,17 @@ def parse_rev(rev):\n     # No, we can't parse that.\n     raise RevParseException\n \n-def git_id(rev):\n-    \"\"\"Return the GIT id\n-    \"\"\"\n-    if not rev:\n-        return None\n-    try:\n-        patch, branch, patch_id = parse_rev(rev)\n-        if branch == None:\n-            series = crt_series\n-        else:\n-            series = stack.Series(branch)\n-        if patch == None:\n-            patch = series.get_current()\n-            if not patch:\n-                raise CmdException, 'No patches applied'\n-        if patch in series.get_applied() or patch in series.get_unapplied():\n-            if patch_id in ['top', '', None]:\n-                return series.get_patch(patch).get_top()\n-            elif patch_id == 'bottom':\n-                return series.get_patch(patch).get_bottom()\n-            elif patch_id == 'top.old':\n-                return series.get_patch(patch).get_old_top()\n-            elif patch_id == 'bottom.old':\n-                return series.get_patch(patch).get_old_bottom()\n-            elif patch_id == 'log':\n-                return series.get_patch(patch).get_log()\n-        if patch == 'base' and patch_id == None:\n-            return series.get_base()\n-    except RevParseException:\n-        pass\n-    return git.rev_parse(rev + '^{commit}')\n-\n def check_local_changes():\n     if git.local_changes():\n         raise CmdException, \\\n               'local changes in the tree. Use \"refresh\" or \"status --reset\"'\n \n-def check_head_top_equal():\n-    if not crt_series.head_top_equal():\n-        raise CmdException(\n-            'HEAD and top are not the same. You probably committed\\n'\n-            '  changes to the tree outside of StGIT. To bring them\\n'\n-            '  into StGIT, use the \"assimilate\" command')\n-\n def check_conflicts():\n     if os.path.exists(os.path.join(basedir.get(), 'conflicts')):\n         raise CmdException, \\\n               'Unsolved conflicts. Please resolve them first or\\n' \\\n               '  revert the changes with \"status --reset\"'\n \n-def print_crt_patch(branch = None):\n-    if not branch:\n-        patch = crt_series.get_current()\n-    else:\n-        patch = stack.Series(branch).get_current()\n-\n-    if patch:\n-        out.info('Now at patch \"%s\"' % patch)\n-    else:\n-        out.info('No patches applied')\n-\n def resolved(filename, reset = None):\n     if reset:\n         reset_file = filename + file_extensions()[reset]\n@@ -191,60 +276,6 @@ def resolved_all(reset = None):\n             resolved(filename, reset)\n         os.remove(os.path.join(basedir.get(), 'conflicts'))\n \n-def push_patches(patches, check_merged = False):\n-    \"\"\"Push multiple patches onto the stack. This function is shared\n-    between the push and pull commands\n-    \"\"\"\n-    forwarded = crt_series.forward_patches(patches)\n-    if forwarded > 1:\n-        out.info('Fast-forwarded patches \"%s\" - \"%s\"'\n-                 % (patches[0], patches[forwarded - 1]))\n-    elif forwarded == 1:\n-        out.info('Fast-forwarded patch \"%s\"' % patches[0])\n-\n-    names = patches[forwarded:]\n-\n-    # check for patches merged upstream\n-    if names and check_merged:\n-        out.start('Checking for patches merged upstream')\n-\n-        merged = crt_series.merged_patches(names)\n-\n-        out.done('%d found' % len(merged))\n-    else:\n-        merged = []\n-\n-    for p in names:\n-        out.start('Pushing patch \"%s\"' % p)\n-\n-        if p in merged:\n-            crt_series.push_patch(p, empty = True)\n-            out.done('merged upstream')\n-        else:\n-            modified = crt_series.push_patch(p)\n-\n-            if crt_series.empty_patch(p):\n-                out.done('empty patch')\n-            elif modified:\n-                out.done('modified')\n-            else:\n-                out.done()\n-\n-def pop_patches(patches, keep = False):\n-    \"\"\"Pop the patches in the list from the stack. It is assumed that\n-    the patches are listed in the stack reverse order.\n-    \"\"\"\n-    if len(patches) == 0:\n-        out.info('Nothing to push/pop')\n-    else:\n-        p = patches[-1]\n-        if len(patches) == 1:\n-            out.start('Popping patch \"%s\"' % p)\n-        else:\n-            out.start('Popping patches \"%s\" - \"%s\"' % (patches[0], p))\n-        crt_series.pop_patch(p, keep)\n-        out.done()\n-\n def parse_patches(patch_args, patch_list, boundary = 0, ordered = False):\n     \"\"\"Parse patch_args list for patch names in patch_list and return\n     a list. The names can be individual patches and/or in the\n@@ -351,34 +382,3 @@ def address_or_alias(addr_str):\n     addr_list = [__address_or_alias(addr.strip())\n                  for addr in addr_str.split(',')]\n     return ', '.join([addr for addr in addr_list if addr])\n-\n-def prepare_rebase(force=None):\n-    if not force:\n-        # Be sure we won't loose results of stg-(un)commit by error.\n-        # Do not require an existing orig-base for compatibility with 0.12 and earlier.\n-        origbase = crt_series._get_field('orig-base')\n-        if origbase and crt_series.get_base() != origbase:\n-            raise CmdException, 'Rebasing would possibly lose data'\n-\n-    # pop all patches\n-    applied = crt_series.get_applied()\n-    if len(applied) > 0:\n-        out.start('Popping all applied patches')\n-        crt_series.pop_patch(applied[0])\n-        out.done()\n-    return applied\n-\n-def rebase(target):\n-    if target == git.get_head():\n-        out.info('Already at \"%s\", no need for rebasing.' % target)\n-        return\n-    out.start('Rebasing to \"%s\"' % target)\n-    git.reset(tree_id = git_id(target))\n-    out.done()\n-\n-def post_rebase(applied, nopush, merged):\n-    # memorize that we rebased to here\n-    crt_series._set_field('orig-base', git.get_head())\n-    # push the patches back\n-    if not nopush:\n-        push_patches(applied, merged)\ndiff --git a/stgit/commands/delete.py b/stgit/commands/delete.py\nindex 5a958ca..6d10895 100644\n--- a/stgit/commands/delete.py\n+++ b/stgit/commands/delete.py\n@@ -70,7 +70,7 @@ class concreteCommand(Command):\n         if applied and not self.flags.branch:\n             check_local_changes()\n             check_conflicts()\n-            check_head_top_equal()\n+            self.check_head_top_equal()\n \n         # delete the patches\n         for patch in applied + patches:\n@@ -78,4 +78,4 @@ class concreteCommand(Command):\n             out.info('Patch \"%s\" successfully deleted' % patch)\n \n         if not self.flags.branch:\n-            print_crt_patch()\n+            self.print_crt_patch()\ndiff --git a/stgit/commands/diff.py b/stgit/commands/diff.py\nindex a015be7..1344953 100644\n--- a/stgit/commands/diff.py\n+++ b/stgit/commands/diff.py\n@@ -85,9 +85,9 @@ class concreteCommand(Command):\n             diff_flags = []\n \n         if self.flags.stat:\n-            out.stdout_raw(git.diffstat(self.args, git_id(rev1), git_id(rev2)) + '\\n')\n+            out.stdout_raw(git.diffstat(self.args, self.git_id(rev1), self.git_id(rev2)) + '\\n')\n         else:\n-            diff_str = git.diff(self.args, git_id(rev1), git_id(rev2),\n+            diff_str = git.diff(self.args, self.git_id(rev1), self.git_id(rev2),\n                                 diff_flags = diff_flags )\n             if diff_str:\n                 pager(diff_str)\ndiff --git a/stgit/commands/files.py b/stgit/commands/files.py\nindex dbdbf11..ad3a5d1 100644\n--- a/stgit/commands/files.py\n+++ b/stgit/commands/files.py\n@@ -56,8 +56,8 @@ class concreteCommand(Command):\n         else:\n             self.parser.error('incorrect number of arguments')\n \n-        rev1 = git_id('%s//bottom' % patch)\n-        rev2 = git_id('%s//top' % patch)\n+        rev1 = self.git_id('%s//bottom' % patch)\n+        rev2 = self.git_id('%s//top' % patch)\n \n         if self.flags.stat:\n             out.stdout_raw(git.diffstat(rev1 = rev1, rev2 = rev2) + '\\n')\ndiff --git a/stgit/commands/float.py b/stgit/commands/float.py\nindex 7acd70c..ea82ea5 100644\n--- a/stgit/commands/float.py\n+++ b/stgit/commands/float.py\n@@ -46,7 +46,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         unapplied = crt_series.get_unapplied()\n         applied = crt_series.get_applied()\n@@ -85,7 +85,7 @@ class concreteCommand(Command):\n         # check whether the operation is really needed\n         if topop != topush:\n             if topop:\n-                pop_patches(topop)\n+                self.pop_patches(topop)\n             if topush:\n                 topush.reverse()\n-                push_patches(topush)\n+                self.push_patches(topush)\ndiff --git a/stgit/commands/fold.py b/stgit/commands/fold.py\nindex 73612fc..6d75df5 100644\n--- a/stgit/commands/fold.py\n+++ b/stgit/commands/fold.py\n@@ -49,7 +49,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         if len(self.args) == 1:\n             filename = self.args[0]\n@@ -73,7 +73,7 @@ class concreteCommand(Command):\n             bottom = crt_patch.get_bottom()\n             git.apply_patch(filename = filename, base = bottom)\n         elif self.flags.base:\n-            git.apply_patch(filename = filename, base = git_id(self.flags.base))\n+            git.apply_patch(filename = filename, base = self.git_id(self.flags.base))\n         else:\n             git.apply_patch(filename = filename)\n \ndiff --git a/stgit/commands/goto.py b/stgit/commands/goto.py\nindex 0ca6bc3..ceec9ea 100644\n--- a/stgit/commands/goto.py\n+++ b/stgit/commands/goto.py\n@@ -43,7 +43,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         applied = crt_series.get_applied()\n         unapplied = crt_series.get_unapplied()\n@@ -52,11 +52,11 @@ class concreteCommand(Command):\n         if patch in applied:\n             applied.reverse()\n             patches = applied[:applied.index(patch)]\n-            pop_patches(patches)\n+            self.pop_patches(patches)\n         elif patch in unapplied:\n             patches = unapplied[:unapplied.index(patch)+1]\n-            push_patches(patches)\n+            self.push_patches(patches)\n         else:\n             raise CmdException, 'Patch \"%s\" does not exist' % patch\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/id.py b/stgit/commands/id.py\nindex 50ddc42..64f5132 100644\n--- a/stgit/commands/id.py\n+++ b/stgit/commands/id.py\n@@ -47,4 +47,4 @@ class concreteCommand(Command):\n         else:\n             self.parser.error('incorrect number of arguments')\n \n-        out.stdout(git_id(id_str))\n+        out.stdout(self.git_id(id_str))\ndiff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py\nindex 5c2a95f..2401c4a 100644\n--- a/stgit/commands/imprt.py\n+++ b/stgit/commands/imprt.py\n@@ -292,7 +292,7 @@ class concreteCommand(Command):\n \n         out.start('Importing patch \"%s\"' % patch)\n         if self.flags.base:\n-            git.apply_patch(diff = diff, base = git_id(self.flags.base))\n+            git.apply_patch(diff = diff, base = self.git_id(self.flags.base))\n         else:\n             git.apply_patch(diff = diff)\n         crt_series.refresh_patch(edit = self.flags.edit,\n@@ -396,7 +396,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         if len(self.args) == 1:\n             filename = self.args[0]\n@@ -412,4 +412,4 @@ class concreteCommand(Command):\n         else:\n             self.__import_file(filename)\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/mail.py b/stgit/commands/mail.py\nindex b8bf1d2..cdc0e2a 100644\n--- a/stgit/commands/mail.py\n+++ b/stgit/commands/mail.py\n@@ -405,11 +405,11 @@ class concreteCommand(Command):\n                      'longdescr':    long_descr,\n                      # for backward template compatibility\n                      'endofheaders': '',\n-                     'diff':         git.diff(rev1 = git_id('%s//bottom' % patch),\n-                                              rev2 = git_id('%s//top' % patch),\n+                     'diff':         git.diff(rev1 = self.git_id('%s//bottom' % patch),\n+                                              rev2 = self.git_id('%s//top' % patch),\n                                               diff_flags = diff_flags ),\n-                     'diffstat':     git.diffstat(rev1 = git_id('%s//bottom'%patch),\n-                                                  rev2 = git_id('%s//top' % patch)),\n+                     'diffstat':     git.diffstat(rev1 = self.git_id('%s//bottom'%patch),\n+                                                  rev2 = self.git_id('%s//top' % patch)),\n                      # for backward template compatibility\n                      'date':         '',\n                      'version':      version_str,\ndiff --git a/stgit/commands/new.py b/stgit/commands/new.py\nindex 2b7bd3d..87f3874 100644\n--- a/stgit/commands/new.py\n+++ b/stgit/commands/new.py\n@@ -69,7 +69,7 @@ class concreteCommand(Command):\n             self.parser.error('incorrect number of arguments')\n \n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         if self.flags.author:\n             self.flags.authname, self.flags.authemail = name_email(self.flags.author)\ndiff --git a/stgit/commands/pick.py b/stgit/commands/pick.py\nindex 1ff9d05..6ec8be3 100644\n--- a/stgit/commands/pick.py\n+++ b/stgit/commands/pick.py\n@@ -61,10 +61,10 @@ class concreteCommand(Command):\n         if not self.flags.unapplied:\n             check_local_changes()\n             check_conflicts()\n-            check_head_top_equal()\n+            self.check_head_top_equal()\n \n         commit_str = self.args[0]\n-        commit_id = git_id(commit_str)\n+        commit_id = self.git_id(commit_str)\n         commit = git.Commit(commit_id)\n \n         if self.flags.fold or self.flags.update:\n@@ -80,7 +80,7 @@ class concreteCommand(Command):\n                 patchname = None\n \n         if self.flags.parent:\n-            parent = git_id(self.flags.parent)\n+            parent = self.git_id(self.flags.parent)\n         else:\n             parent = commit.get_parent()\n \n@@ -100,8 +100,8 @@ class concreteCommand(Command):\n \n             out.done()\n         elif self.flags.update:\n-            rev1 = git_id('//bottom')\n-            rev2 = git_id('//top')\n+            rev1 = self.git_id('//bottom')\n+            rev2 = self.git_id('//top')\n             files = git.barefiles(rev1, rev2).split('\\n')\n \n             out.start('Updating with commit %s' % commit_id)\n@@ -157,4 +157,4 @@ class concreteCommand(Command):\n             else:\n                 out.done()\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/pop.py b/stgit/commands/pop.py\nindex cd5c46d..3b8b536 100644\n--- a/stgit/commands/pop.py\n+++ b/stgit/commands/pop.py\n@@ -51,7 +51,7 @@ class concreteCommand(Command):\n         \"\"\"Pop the topmost patch from the stack\n         \"\"\"\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         if not self.flags.keep:\n             check_local_changes()\n@@ -83,8 +83,8 @@ class concreteCommand(Command):\n             raise CmdException, 'Cannot pop arbitrary patches with --keep'\n \n         topop.reverse()\n-        pop_patches(topop, self.flags.keep)\n+        self.pop_patches(topop, self.flags.keep)\n         if topush:\n-            push_patches(topush)\n+            self.push_patches(topush)\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/pull.py b/stgit/commands/pull.py\nindex 3fdbc74..06d9aa9 100644\n--- a/stgit/commands/pull.py\n+++ b/stgit/commands/pull.py\n@@ -76,7 +76,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         if policy == 'pull':\n             must_rebase = 0\n@@ -87,7 +87,7 @@ class concreteCommand(Command):\n         else:\n             raise GitConfigException, 'Unsupported pull-policy \"%s\"' % policy\n \n-        applied = prepare_rebase(force=self.flags.force)\n+        applied = self.prepare_rebase(force=self.flags.force)\n \n         # pull the remote changes\n         if policy == 'pull':\n@@ -96,14 +96,14 @@ class concreteCommand(Command):\n         elif policy == 'fetch-rebase':\n             out.info('Fetching from \"%s\"' % repository)\n             git.fetch(repository)\n-            rebase(git.fetch_head())\n+            self.rebase(git.fetch_head())\n         elif policy == 'rebase':\n-            rebase(crt_series.get_parent_branch())\n+            self.rebase(crt_series.get_parent_branch())\n \n-        post_rebase(applied, self.flags.nopush, self.flags.merged)\n+        self.post_rebase(applied, self.flags.nopush, self.flags.merged)\n \n         # maybe tidy up\n         if config.get('stgit.keepoptimized') == 'yes':\n             git.repack()\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/push.py b/stgit/commands/push.py\nindex 14e8e41..0d41cad 100644\n--- a/stgit/commands/push.py\n+++ b/stgit/commands/push.py\n@@ -71,13 +71,13 @@ class concreteCommand(Command):\n                 out.done()\n             else:\n                 out.done('patch unchanged')\n-            print_crt_patch()\n+            self.print_crt_patch()\n \n             return\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         unapplied = crt_series.get_unapplied()\n         if not unapplied:\n@@ -98,6 +98,6 @@ class concreteCommand(Command):\n         if self.flags.reverse:\n             patches.reverse()\n \n-        push_patches(patches, self.flags.merged)\n+        self.push_patches(patches, self.flags.merged)\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py\nindex 111d78e..f953d6b 100644\n--- a/stgit/commands/rebase.py\n+++ b/stgit/commands/rebase.py\n@@ -51,14 +51,14 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         # ensure an exception is raised before popping on non-existent target\n-        if git_id(self.args[0]) == None:\n-            raise GitException, 'Unknown revision: %s' % git_id(self.args[0])\n+        if self.git_id(self.args[0]) == None:\n+            raise GitException, 'Unknown revision: %s' % self.git_id(self.args[0])\n \n-        applied = prepare_rebase(force=self.flags.force)\n-        rebase(self.args[0])\n-        post_rebase(applied, self.flags.nopush, self.flags.merged)\n+        applied = self.prepare_rebase(force=self.flags.force)\n+        self.rebase(self.args[0])\n+        self.post_rebase(applied, self.flags.nopush, self.flags.merged)\n \n-        print_crt_patch()\n+        self.print_crt_patch()\ndiff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py\nindex e6a6953..90eb26b 100644\n--- a/stgit/commands/refresh.py\n+++ b/stgit/commands/refresh.py\n@@ -96,7 +96,7 @@ class concreteCommand(Command):\n                 raise CmdException, 'No patches applied'\n \n         if not self.flags.force:\n-            check_head_top_equal()\n+            self.check_head_top_equal()\n \n         if self.flags.undo:\n             out.start('Undoing the refresh of \"%s\"' % patch)\n@@ -126,7 +126,7 @@ class concreteCommand(Command):\n             if self.flags.patch:\n                 applied = crt_series.get_applied()\n                 between = applied[:applied.index(patch):-1]\n-                pop_patches(between, keep = True)\n+                self.pop_patches(between, keep = True)\n \n             out.start('Refreshing patch \"%s\"' % patch)\n \n@@ -150,6 +150,6 @@ class concreteCommand(Command):\n \n             if self.flags.patch:\n                 between.reverse()\n-                push_patches(between)\n+                self.push_patches(between)\n         else:\n             out.info('Patch \"%s\" is already up to date' % patch)\ndiff --git a/stgit/commands/series.py b/stgit/commands/series.py\nindex ebb1ce4..2afa013 100644\n--- a/stgit/commands/series.py\n+++ b/stgit/commands/series.py\n@@ -191,12 +191,12 @@ class concreteCommand(Command):\n                 raise CmdException, '--graphical not supported with --missing'\n \n             if applied:\n-                gitk_args = ' %s^..%s' % (git_id(applied[0]), git_id(applied[-1]))\n+                gitk_args = ' %s^..%s' % (self.git_id(applied[0]), self.git_id(applied[-1]))\n             else:\n                 gitk_args = ''\n \n             for p in unapplied:\n-                patch_id = git_id(p)\n+                patch_id = self.git_id(p)\n                 gitk_args += ' %s^..%s' % (patch_id, patch_id)\n \n             if os.system('gitk%s' % gitk_args) != 0:\ndiff --git a/stgit/commands/show.py b/stgit/commands/show.py\nindex c207e45..5ff772f 100644\n--- a/stgit/commands/show.py\n+++ b/stgit/commands/show.py\n@@ -66,7 +66,7 @@ class concreteCommand(Command):\n         else:\n             diff_flags = []\n \n-        commit_ids = [git_id(patch) for patch in patches]\n+        commit_ids = [self.git_id(patch) for patch in patches]\n         commit_str = '\\n'.join([git.pretty_commit(commit_id, diff_flags=diff_flags)\n                                 for commit_id in commit_ids])\n         if commit_str:\ndiff --git a/stgit/commands/sink.py b/stgit/commands/sink.py\nindex 5ec0f1d..c3ef4d5 100644\n--- a/stgit/commands/sink.py\n+++ b/stgit/commands/sink.py\n@@ -45,7 +45,7 @@ class concreteCommand(Command):\n \n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n         oldapplied = crt_series.get_applied()\n         unapplied = crt_series.get_unapplied()\n@@ -57,10 +57,10 @@ class concreteCommand(Command):\n             patches = [ crt_series.get_current() ]\n \n         crt_series.pop_patch(self.flags.to or oldapplied[0])\n-        push_patches(patches)\n+        self.push_patches(patches)\n \n         if not self.flags.nopush:\n             newapplied = crt_series.get_applied()\n             def not_reapplied_yet(p):\n                 return not p in newapplied\n-            push_patches(filter(not_reapplied_yet, oldapplied))\n+            self.push_patches(filter(not_reapplied_yet, oldapplied))\ndiff --git a/stgit/commands/sync.py b/stgit/commands/sync.py\nindex 513e7bb..9c95b99 100644\n--- a/stgit/commands/sync.py\n+++ b/stgit/commands/sync.py\n@@ -62,7 +62,7 @@ class concreteCommand(Command):\n     def __check_all(self):\n         check_local_changes()\n         check_conflicts()\n-        check_head_top_equal()\n+        self.check_head_top_equal()\n \n     def func(self):\n         \"\"\"Synchronise a range of patches\n@@ -135,13 +135,13 @@ class concreteCommand(Command):\n         # pop to the one before the first patch to be synchronised\n         popped = applied[applied.index(sync_patches[0]) + 1:]\n         if popped:\n-            pop_patches(popped[::-1])\n+            self.pop_patches(popped[::-1])\n \n         for p in sync_patches:\n             if p in popped:\n                 # push to this patch\n                 idx = popped.index(p) + 1\n-                push_patches(popped[:idx])\n+                self.push_patches(popped[:idx])\n                 del popped[:idx]\n \n             # the actual sync\n@@ -170,4 +170,4 @@ class concreteCommand(Command):\n \n         # push the remaining patches\n         if popped:\n-            push_patches(popped)\n+            self.push_patches(popped)\n"},{"id":"45187","messageId":"20070616220100.14941.3131.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 6/9] Changed sync not to use -b which has other semantics.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:01:00Z","receivedAt":"2007-06-16T22:01:00Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Using --branch here is confusing from a UI point of view, and\nunnecessarily complicates implementation, making in more delicate to\nget rid of the crt-series global.  We now use --ref-branch (-B)\ninstead.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/sync.py |   15 ++++++---------\n t/t2000-sync.sh        |    8 ++++----\n 2 files changed, 10 insertions(+), 13 deletions(-)\n\ndiff --git a/stgit/commands/sync.py b/stgit/commands/sync.py\nindex 9c95b99..2882391 100644\n--- a/stgit/commands/sync.py\n+++ b/stgit/commands/sync.py\n@@ -51,7 +51,7 @@ class concreteCommand(Command):\n     options = [make_option('-a', '--all',\n                            help = 'synchronise all the patches',\n                            action = 'store_true'),\n-               make_option('-b', '--branch',\n+               make_option('-B', '--ref-branch',\n                            help = 'syncronise patches with BRANCH'),\n                make_option('-s', '--series',\n                            help = 'syncronise patches with SERIES'),\n@@ -70,9 +70,9 @@ class concreteCommand(Command):\n         global crt_series\n \n         if self.flags.undo:\n-            if self.flags.branch or self.flags.series:\n+            if self.flags.ref_branch or self.flags.series:\n                 raise CmdException, \\\n-                      '--undo cannot be specified with --branch or --series'\n+                      '--undo cannot be specified with --ref-branch or --series'\n             self.__check_all()\n \n             out.start('Undoing the sync of \"%s\"' % crt_series.get_current())\n@@ -81,12 +81,9 @@ class concreteCommand(Command):\n             out.done()\n             return\n \n-        if self.flags.branch:\n-            # the main function already made crt_series to be the remote\n-            # branch\n-            remote_series = crt_series\n-            stgit.commands.common.crt_series = crt_series = stack.Series()\n-            if self.flags.branch == crt_series.get_name():\n+        if self.flags.ref_branch:\n+            remote_series = stack.Series(self.flags.ref_branch)\n+            if self.flags.ref_branch == crt_series.get_name():\n                 raise CmdException, 'Cannot synchronise with the current branch'\n             remote_patches = remote_series.get_applied()\n \ndiff --git a/t/t2000-sync.sh b/t/t2000-sync.sh\nindex 69ab1ac..f831df7 100755\n--- a/t/t2000-sync.sh\n+++ b/t/t2000-sync.sh\n@@ -48,7 +48,7 @@ test_expect_success \\\n test_expect_success \\\n     'Synchronise second patch with the master branch' \\\n     '\n-    stg sync -b master p2 &&\n+    stg sync -B master p2 &&\n     [ \"$(echo $(stg applied))\" = \"p1 p2 p3\" ] &&\n     [ \"$(echo $(stg unapplied))\" = \"\" ] &&\n     test $(cat foo2.txt) = \"foo2\"\n@@ -57,7 +57,7 @@ test_expect_success \\\n test_expect_success \\\n     'Synchronise the first two patches with the master branch' \\\n     '\n-    stg sync -b master -a &&\n+    stg sync -B master -a &&\n     [ \"$(echo $(stg applied))\" = \"p1 p2 p3\" ] &&\n     [ \"$(echo $(stg unapplied))\" = \"\" ] &&\n     test $(cat foo1.txt) = \"foo1\" &&\n@@ -100,7 +100,7 @@ test_expect_success \\\n test_expect_success \\\n     'Synchronise second patch with the master branch' \\\n     '\n-    stg sync -b master p2 &&\n+    stg sync -B master p2 &&\n     [ \"$(echo $(stg applied))\" = \"p1 p2 p3\" ] &&\n     [ \"$(echo $(stg unapplied))\" = \"\" ] &&\n     test $(cat bar2.txt) = \"bar2\"\n@@ -109,7 +109,7 @@ test_expect_success \\\n test_expect_failure \\\n     'Synchronise the first two patches with the master branch (to fail)' \\\n     '\n-    stg sync -b master -a\n+    stg sync -B master -a\n     '\n \n test_expect_success \\\n"},{"id":"45191","messageId":"20070616220105.14941.41947.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 7/9] Replace crt_series uses with a method call.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:01:05Z","receivedAt":"2007-06-16T22:01:05Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"This is a first step towards use of a factory method.\n\nIt also allows to get on-demand instantiation of the \"current series\"\nobject, and we can avoid calling a Series constructor when only the\ncurrent head's name is needed.\n\nAt the same time, cleaned up how \"series --missing\" was implemented.\n\nNote: current_head() is actually slightly misnamed: it is expected to\nbe the Series/PatchSet object on which the command operates, but for\nsome commands (notably stg-branch and stg-clone) the semantics are a\nbit different.  Thus there is probably some more refactoring to do\nhere, and I'm keeping this name as a reminder.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/add.py        |    2 +-\n stgit/commands/applied.py    |    2 +-\n stgit/commands/assimilate.py |    8 ++++----\n stgit/commands/branch.py     |   14 +++++++-------\n stgit/commands/clean.py      |   16 ++++++++--------\n stgit/commands/commit.py     |    8 ++++----\n stgit/commands/common.py     |   36 ++++++++++++++++++------------------\n stgit/commands/copy.py       |    2 +-\n stgit/commands/delete.py     |    6 +++---\n stgit/commands/export.py     |    8 ++++----\n stgit/commands/float.py      |    4 ++--\n stgit/commands/fold.py       |    4 ++--\n stgit/commands/goto.py       |    4 ++--\n stgit/commands/hide.py       |    6 +++---\n stgit/commands/imprt.py      |   26 +++++++++++++-------------\n stgit/commands/init.py       |    2 +-\n stgit/commands/log.py        |    6 +++---\n stgit/commands/mail.py       |    6 +++---\n stgit/commands/new.py        |   14 +++++++-------\n stgit/commands/patches.py    |    8 ++++----\n stgit/commands/pick.py       |   18 +++++++++---------\n stgit/commands/pop.py        |    2 +-\n stgit/commands/pull.py       |    8 ++++----\n stgit/commands/push.py       |    6 +++---\n stgit/commands/rebase.py     |    2 +-\n stgit/commands/refresh.py    |   34 +++++++++++++++++-----------------\n stgit/commands/rename.py     |    2 +-\n stgit/commands/rm.py         |    2 +-\n stgit/commands/series.py     |   37 +++++++++++++++++--------------------\n stgit/commands/show.py       |    6 +++---\n stgit/commands/sink.py       |   10 +++++-----\n stgit/commands/sync.py       |   17 ++++++++---------\n stgit/commands/top.py        |    2 +-\n stgit/commands/unapplied.py  |    2 +-\n stgit/commands/uncommit.py   |   18 +++++++++---------\n stgit/commands/unhide.py     |    6 +++---\n stgit/main.py                |    7 -------\n 37 files changed, 175 insertions(+), 186 deletions(-)\n\ndiff --git a/stgit/commands/add.py b/stgit/commands/add.py\nindex cc9dab0..48fb78a 100644\n--- a/stgit/commands/add.py\n+++ b/stgit/commands/add.py\n@@ -39,7 +39,7 @@ class concreteCommand(Command):\n         if len(self.args) < 1:\n             self.parser.error('incorrect number of arguments')\n \n-        if not crt_series.get_current():\n+        if not self.current_head().get_current():\n             raise CmdException, 'No patches applied'\n \n         git.add(self.args)\ndiff --git a/stgit/commands/applied.py b/stgit/commands/applied.py\nindex a30a0e0..27077d9 100644\n--- a/stgit/commands/applied.py\n+++ b/stgit/commands/applied.py\n@@ -45,7 +45,7 @@ class concreteCommand(Command):\n         if len(self.args) != 0:\n             self.parser.error('incorrect number of arguments')\n \n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n \n         if self.flags.count:\n             out.stdout(len(applied))\ndiff --git a/stgit/commands/assimilate.py b/stgit/commands/assimilate.py\nindex c85ae6e..b79358a 100644\n--- a/stgit/commands/assimilate.py\n+++ b/stgit/commands/assimilate.py\n@@ -43,7 +43,7 @@ class concreteCommand(Command):\n         def nothing_to_do():\n             out.info('No commits to assimilate')\n \n-        top_patch = crt_series.get_current_patch()\n+        top_patch = self.current_head().get_current_patch()\n         if not top_patch:\n             return nothing_to_do()\n \n@@ -61,7 +61,7 @@ class concreteCommand(Command):\n         if not victims:\n             return nothing_to_do()\n \n-        if crt_series.get_protected():\n+        if self.current_head().get_protected():\n             raise CmdException(\n                 'This branch is protected. Modification is not permitted')\n \n@@ -69,7 +69,7 @@ class concreteCommand(Command):\n         name2patch = {}\n \n         def name_taken(name):\n-            return name in name2patch or crt_series.patch_exists(name)\n+            return name in name2patch or self.current_head().patch_exists(name)\n \n         for victim in victims:\n             patchname = make_patch_name(victim.get_log(), name_taken)\n@@ -82,7 +82,7 @@ class concreteCommand(Command):\n                      % (patch2name[victim], victim))\n             aname, amail, adate = name_email_date(victim.get_author())\n             cname, cmail, cdate = name_email_date(victim.get_committer())\n-            crt_series.new_patch(\n+            self.current_head().new_patch(\n                 patch2name[victim],\n                 can_edit = False, before_existing = False, refresh = False,\n                 top = victim.get_id_hash(), bottom = victim.get_parent(),\ndiff --git a/stgit/commands/branch.py b/stgit/commands/branch.py\nindex e243830..ca4f98c 100644\n--- a/stgit/commands/branch.py\n+++ b/stgit/commands/branch.py\n@@ -69,7 +69,7 @@ class concreteCommand(Command):\n \n \n     def __is_current_branch(self, branch_name):\n-        return crt_series.get_name() == branch_name\n+        return self.current_head_name() == branch_name\n \n     def __print_branch(self, branch_name, length):\n         initialized = ' '\n@@ -169,7 +169,7 @@ class concreteCommand(Command):\n         elif self.flags.clone:\n \n             if len(self.args) == 0:\n-                clone = crt_series.get_name() + \\\n+                clone = self.current_head_name() + \\\n                         time.strftime('-%C%y%m%d-%H%M%S')\n             elif len(self.args) == 1:\n                 clone = self.args[0]\n@@ -181,7 +181,7 @@ class concreteCommand(Command):\n             self.check_head_top_equal()\n \n             out.start('Cloning current branch to \"%s\"' % clone)\n-            crt_series.clone(clone)\n+            self.current_head().clone(clone)\n             out.done()\n \n             return\n@@ -216,7 +216,7 @@ class concreteCommand(Command):\n         elif self.flags.protect:\n \n             if len(self.args) == 0:\n-                branch_name = crt_series.get_name()\n+                branch_name = self.current_head_name()\n             elif len(self.args) == 1:\n                 branch_name = self.args[0]\n             else:\n@@ -250,7 +250,7 @@ class concreteCommand(Command):\n         elif self.flags.unprotect:\n \n             if len(self.args) == 0:\n-                branch_name = crt_series.get_name()\n+                branch_name = self.current_head_name()\n             elif len(self.args) == 1:\n                 branch_name = self.args[0]\n             else:\n@@ -270,7 +270,7 @@ class concreteCommand(Command):\n         elif self.flags.description is not None:\n \n             if len(self.args) == 0:\n-                branch_name = crt_series.get_name()\n+                branch_name = self.current_head_name()\n             elif len(self.args) == 1:\n                 branch_name = self.args[0]\n             else:\n@@ -304,4 +304,4 @@ class concreteCommand(Command):\n         if len(self.args) != 0:\n             self.parser.error('incorrect number of arguments')\n \n-        print crt_series.get_name()\n+        print self.current_head_name()\ndiff --git a/stgit/commands/clean.py b/stgit/commands/clean.py\nindex 3e9d829..74f5cf7 100644\n--- a/stgit/commands/clean.py\n+++ b/stgit/commands/clean.py\n@@ -43,14 +43,14 @@ class concreteCommand(Command):\n         \"\"\"Delete the empty patches\n         \"\"\"\n         for p in patches:\n-            if crt_series.empty_patch(p):\n+            if self.current_head().empty_patch(p):\n                 out.start('Deleting patch \"%s\"' % p)\n-                if applied and crt_series.patch_applied(p):\n-                    crt_series.pop_patch(p)\n-                crt_series.delete_patch(p)\n+                if applied and self.current_head().patch_applied(p):\n+                    self.current_head().pop_patch(p)\n+                self.current_head().delete_patch(p)\n                 out.done()\n-            elif applied and crt_series.patch_unapplied(p):\n-                crt_series.push_patch(p)\n+            elif applied and self.current_head().patch_unapplied(p):\n+                self.current_head().push_patch(p)\n \n     def func(self):\n         \"\"\"Delete the empty patches in the series\n@@ -66,11 +66,11 @@ class concreteCommand(Command):\n             self.flags.applied = self.flags.unapplied = True\n \n         if self.flags.applied:\n-            applied = crt_series.get_applied()\n+            applied = self.current_head().get_applied()\n             self.__delete_empty(applied, True)\n \n         if self.flags.unapplied:\n-            unapplied = crt_series.get_unapplied()\n+            unapplied = self.current_head().get_unapplied()\n             self.__delete_empty(unapplied, False)\n \n         self.print_crt_patch()\ndiff --git a/stgit/commands/commit.py b/stgit/commands/commit.py\nindex 56f3943..decba21 100644\n--- a/stgit/commands/commit.py\n+++ b/stgit/commands/commit.py\n@@ -44,21 +44,21 @@ class concreteCommand(Command):\n         check_conflicts()\n         self.check_head_top_equal()\n \n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n         if not applied:\n             raise CmdException, 'No patches applied'\n \n-        if crt_series.get_protected():\n+        if self.current_head().get_protected():\n             raise CmdException, 'This branch is protected.  Commit is not permitted'\n \n         crt_head = git.get_head()\n \n         out.start('Committing %d patches' % len(applied))\n \n-        crt_series.pop_patch(applied[0])\n+        self.current_head().pop_patch(applied[0])\n         git.switch(crt_head)\n \n         for patch in applied:\n-            crt_series.delete_patch(patch)\n+            self.current_head().delete_patch(patch)\n \n         out.done()\ndiff --git a/stgit/commands/common.py b/stgit/commands/common.py\nindex 1ed5086..12487a5 100644\n--- a/stgit/commands/common.py\n+++ b/stgit/commands/common.py\n@@ -25,9 +25,6 @@ from stgit.utils import *\n from stgit import stack, git, basedir\n from stgit.config import config, file_extensions\n \n-crt_series = None\n-\n-\n # Command exception class\n class CmdException(Exception):\n     pass\n@@ -48,6 +45,7 @@ class Command:\n     This command is undocumented.\"\"\"\n     options = []\n     __head_name = None\n+    __head = None\n \n     def __init__(self, name):\n         self.__name = name\n@@ -61,7 +59,9 @@ class Command:\n         return self.__head_name\n \n     def current_head(self):\n-        return stack.Series(self.current_head_name())\n+        if not self.__head:\n+            self.__head = stack.Series(self.current_head_name())\n+        return self.__head\n \n     def func(self):\n         raise CmdException, 'Unimplemented command'\n@@ -79,7 +79,7 @@ class Command:\n         try:\n             patch, branch, patch_id = parse_rev(rev)\n             if branch == None:\n-                series = crt_series\n+                series = self.current_head()\n             else:\n                 series = stack.Series(branch)\n             if patch == None:\n@@ -104,7 +104,7 @@ class Command:\n         return git.rev_parse(rev + '^{commit}')\n \n     def check_head_top_equal(self):\n-        if not crt_series.head_top_equal():\n+        if not self.current_head().head_top_equal():\n             raise CmdException(\n                 'HEAD and top are not the same. You probably committed\\n'\n                 '  changes to the tree outside of StGIT. To bring them\\n'\n@@ -112,7 +112,7 @@ class Command:\n \n     def print_crt_patch(self, branch = None):\n         if not branch:\n-            patch = crt_series.get_current()\n+            patch = self.current_head().get_current()\n         else:\n             patch = stack.Series(branch).get_current()\n \n@@ -125,7 +125,7 @@ class Command:\n         \"\"\"Push multiple patches onto the stack. This function is shared\n         between the push and pull commands\n         \"\"\"\n-        forwarded = crt_series.forward_patches(patches)\n+        forwarded = self.current_head().forward_patches(patches)\n         if forwarded > 1:\n             out.info('Fast-forwarded patches \"%s\" - \"%s\"'\n                      % (patches[0], patches[forwarded - 1]))\n@@ -138,7 +138,7 @@ class Command:\n         if names and check_merged:\n             out.start('Checking for patches merged upstream')\n \n-            merged = crt_series.merged_patches(names)\n+            merged = self.current_head().merged_patches(names)\n \n             out.done('%d found' % len(merged))\n         else:\n@@ -148,12 +148,12 @@ class Command:\n             out.start('Pushing patch \"%s\"' % p)\n \n             if p in merged:\n-                crt_series.push_patch(p, empty = True)\n+                self.current_head().push_patch(p, empty = True)\n                 out.done('merged upstream')\n             else:\n-                modified = crt_series.push_patch(p)\n+                modified = self.current_head().push_patch(p)\n \n-                if crt_series.empty_patch(p):\n+                if self.current_head().empty_patch(p):\n                     out.done('empty patch')\n                 elif modified:\n                     out.done('modified')\n@@ -172,22 +172,22 @@ class Command:\n                 out.start('Popping patch \"%s\"' % p)\n             else:\n                 out.start('Popping patches \"%s\" - \"%s\"' % (patches[0], p))\n-            crt_series.pop_patch(p, keep)\n+            self.current_head().pop_patch(p, keep)\n             out.done()\n \n     def prepare_rebase(self, force=None):\n         if not force:\n             # Be sure we won't loose results of stg-(un)commit by error.\n             # Do not require an existing orig-base for compatibility with 0.12 and earlier.\n-            origbase = crt_series._get_field('orig-base')\n-            if origbase and crt_series.get_base() != origbase:\n+            origbase = self.current_head()._get_field('orig-base')\n+            if origbase and self.current_head().get_base() != origbase:\n                 raise CmdException, 'Rebasing would possibly lose data'\n \n         # pop all patches\n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n         if len(applied) > 0:\n             out.start('Popping all applied patches')\n-            crt_series.pop_patch(applied[0])\n+            self.current_head().pop_patch(applied[0])\n             out.done()\n         return applied\n \n@@ -201,7 +201,7 @@ class Command:\n \n     def post_rebase(self, applied, nopush, merged):\n         # memorize that we rebased to here\n-        crt_series._set_field('orig-base', git.get_head())\n+        self.current_head()._set_field('orig-base', git.get_head())\n         # push the patches back\n         if not nopush:\n             self.push_patches(applied, merged)\ndiff --git a/stgit/commands/copy.py b/stgit/commands/copy.py\nindex 393d509..3eb267e 100644\n--- a/stgit/commands/copy.py\n+++ b/stgit/commands/copy.py\n@@ -37,7 +37,7 @@ class concreteCommand(Command):\n         if len(self.args) < 1:\n             self.parser.error('incorrect number of arguments')\n \n-        if not crt_series.get_current():\n+        if not self.current_head().get_current():\n             raise CmdException, 'No patches applied'\n \n         git.copy(self.args[0:-1], self.args[-1])\ndiff --git a/stgit/commands/delete.py b/stgit/commands/delete.py\nindex 6d10895..b87d13d 100644\n--- a/stgit/commands/delete.py\n+++ b/stgit/commands/delete.py\n@@ -42,8 +42,8 @@ class concreteCommand(Command):\n     def func(self):\n         \"\"\"Deletes one or more patches.\n         \"\"\"\n-        applied_patches = crt_series.get_applied()\n-        unapplied_patches = crt_series.get_unapplied()\n+        applied_patches = self.current_head().get_applied()\n+        unapplied_patches = self.current_head().get_unapplied()\n         all_patches = applied_patches + unapplied_patches\n \n         if self.args:\n@@ -74,7 +74,7 @@ class concreteCommand(Command):\n \n         # delete the patches\n         for patch in applied + patches:\n-            crt_series.delete_patch(patch)\n+            self.current_head().delete_patch(patch)\n             out.info('Patch \"%s\" successfully deleted' % patch)\n \n         if not self.flags.branch:\ndiff --git a/stgit/commands/export.py b/stgit/commands/export.py\nindex fb5e87b..f1c1920 100644\n--- a/stgit/commands/export.py\n+++ b/stgit/commands/export.py\n@@ -76,7 +76,7 @@ class concreteCommand(Command):\n         if self.flags.dir:\n             dirname = self.flags.dir\n         else:\n-            dirname = 'patches-%s' % crt_series.get_name()\n+            dirname = 'patches-%s' % self.current_head_name()\n \n         if not self.flags.branch and git.local_changes():\n             out.warn('Local changes in the tree;'\n@@ -92,7 +92,7 @@ class concreteCommand(Command):\n         else:\n             diff_flags = []\n \n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n         if len(self.args) != 0:\n             patches = parse_patches(self.args, applied)\n         else:\n@@ -116,7 +116,7 @@ class concreteCommand(Command):\n \n         # note the base commit for this series\n         if not self.flags.stdout:\n-            base_commit = crt_series.get_patch(patches[0]).get_bottom()\n+            base_commit = self.current_head().get_patch(patches[0]).get_bottom()\n             print >> series, '# This series applies on GIT commit %s' % base_commit\n \n         patch_no = 1;\n@@ -133,7 +133,7 @@ class concreteCommand(Command):\n                 print >> series, pname\n \n             # get the patch description\n-            patch = crt_series.get_patch(p)\n+            patch = self.current_head().get_patch(p)\n \n             descr = patch.get_description().strip()\n             descr_lines = descr.split('\\n')\ndiff --git a/stgit/commands/float.py b/stgit/commands/float.py\nindex ea82ea5..b3b9acb 100644\n--- a/stgit/commands/float.py\n+++ b/stgit/commands/float.py\n@@ -48,8 +48,8 @@ class concreteCommand(Command):\n         check_conflicts()\n         self.check_head_top_equal()\n \n-        unapplied = crt_series.get_unapplied()\n-        applied = crt_series.get_applied()\n+        unapplied = self.current_head().get_unapplied()\n+        applied = self.current_head().get_applied()\n         all = unapplied + applied\n \n         if self.flags.series:\ndiff --git a/stgit/commands/fold.py b/stgit/commands/fold.py\nindex 6d75df5..734db43 100644\n--- a/stgit/commands/fold.py\n+++ b/stgit/commands/fold.py\n@@ -56,7 +56,7 @@ class concreteCommand(Command):\n         else:\n             filename = None\n \n-        current = crt_series.get_current()\n+        current = self.current_head().get_current()\n         if not current:\n             raise CmdException, 'No patches applied'\n \n@@ -69,7 +69,7 @@ class concreteCommand(Command):\n             out.start('Folding patch from stdin')\n \n         if self.flags.threeway:\n-            crt_patch = crt_series.get_patch(current)\n+            crt_patch = self.current_head().get_patch(current)\n             bottom = crt_patch.get_bottom()\n             git.apply_patch(filename = filename, base = bottom)\n         elif self.flags.base:\ndiff --git a/stgit/commands/goto.py b/stgit/commands/goto.py\nindex ceec9ea..dc862ef 100644\n--- a/stgit/commands/goto.py\n+++ b/stgit/commands/goto.py\n@@ -45,8 +45,8 @@ class concreteCommand(Command):\n         check_conflicts()\n         self.check_head_top_equal()\n \n-        applied = crt_series.get_applied()\n-        unapplied = crt_series.get_unapplied()\n+        applied = self.current_head().get_applied()\n+        unapplied = self.current_head().get_unapplied()\n         patch = self.args[0]\n \n         if patch in applied:\ndiff --git a/stgit/commands/hide.py b/stgit/commands/hide.py\nindex 4259fdf..ef17592 100644\n--- a/stgit/commands/hide.py\n+++ b/stgit/commands/hide.py\n@@ -38,12 +38,12 @@ class concreteCommand(Command):\n         \"\"\"\n         if self.args:\n             # parsing all the patches for a more meaningful error reporting\n-            all_patches = crt_series.get_applied() + crt_series.get_unapplied() \\\n-                          + crt_series.get_hidden()\n+            all_patches = self.current_head().get_applied() + self.current_head().get_unapplied() \\\n+                          + self.current_head().get_hidden()\n             patches = parse_patches(self.args, all_patches)\n         else:\n             self.parser.error('No patches specified')\n \n         for patch in patches:\n-            crt_series.hide_patch(patch)\n+            self.current_head().hide_patch(patch)\n             out.info('Patch \"%s\" hidden' % patch)\ndiff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py\nindex 2401c4a..b45ec29 100644\n--- a/stgit/commands/imprt.py\n+++ b/stgit/commands/imprt.py\n@@ -246,7 +246,7 @@ class concreteCommand(Command):\n             if self.flags.ignore or self.flags.replace:\n                 unacceptable_name = lambda name: False\n             else:\n-                unacceptable_name = crt_series.patch_exists\n+                unacceptable_name = self.current_head().patch_exists\n             patch = make_patch_name(message, unacceptable_name)\n         else:\n             # fix possible invalid characters in the patch name\n@@ -255,11 +255,11 @@ class concreteCommand(Command):\n         if not diff:\n             raise CmdException, 'No diff found inside the patch'\n \n-        if self.flags.ignore and patch in crt_series.get_applied():\n+        if self.flags.ignore and patch in self.current_head().get_applied():\n             out.info('Ignoring already applied patch \"%s\"' % patch)\n             return\n-        if self.flags.replace and patch in crt_series.get_unapplied():\n-            crt_series.delete_patch(patch)\n+        if self.flags.replace and patch in self.current_head().get_unapplied():\n+            self.current_head().delete_patch(patch)\n \n         # refresh_patch() will invoke the editor in this case, with correct\n         # patch content\n@@ -283,20 +283,20 @@ class concreteCommand(Command):\n         if self.flags.commemail:\n             committer_email = self.flags.commemail\n \n-        crt_series.new_patch(patch, message = message, can_edit = False,\n-                             author_name = author_name,\n-                             author_email = author_email,\n-                             author_date = author_date,\n-                             committer_name = committer_name,\n-                             committer_email = committer_email)\n+        self.current_head().new_patch(patch, message = message, can_edit = False,\n+                                      author_name = author_name,\n+                                      author_email = author_email,\n+                                      author_date = author_date,\n+                                      committer_name = committer_name,\n+                                      committer_email = committer_email)\n \n         out.start('Importing patch \"%s\"' % patch)\n         if self.flags.base:\n             git.apply_patch(diff = diff, base = self.git_id(self.flags.base))\n         else:\n             git.apply_patch(diff = diff)\n-        crt_series.refresh_patch(edit = self.flags.edit,\n-                                 show_patch = self.flags.showpatch)\n+        self.current_head().refresh_patch(edit = self.flags.edit,\n+                                          show_patch = self.flags.showpatch)\n         out.done()\n \n     def __import_file(self, filename, patch = None):\n@@ -332,7 +332,7 @@ class concreteCommand(Command):\n     def __import_series(self, filename):\n         \"\"\"Import a series of patches\n         \"\"\"\n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n \n         if filename:\n             f = file(filename)\ndiff --git a/stgit/commands/init.py b/stgit/commands/init.py\nindex 9ffcaaa..bdccacd 100644\n--- a/stgit/commands/init.py\n+++ b/stgit/commands/init.py\n@@ -37,4 +37,4 @@ class concreteCommand(Command):\n         if len(self.args) != 0:\n             self.parser.error('incorrect number of arguments')\n \n-        crt_series.init()\n+        self.current_head().init()\ndiff --git a/stgit/commands/log.py b/stgit/commands/log.py\nindex 6b85975..d314c9a 100644\n--- a/stgit/commands/log.py\n+++ b/stgit/commands/log.py\n@@ -86,17 +86,17 @@ class concreteCommand(Command):\n         \"\"\"Show the patch changelog\n         \"\"\"\n         if len(self.args) == 0:\n-            name = crt_series.get_current()\n+            name = self.current_head().get_current()\n             if not name:\n                 raise CmdException, 'No patches applied'\n         elif len(self.args) == 1:\n             name = self.args[0]\n-            if not name in crt_series.get_applied() + crt_series.get_unapplied():\n+            if not name in self.current_head().get_applied() + self.current_head().get_unapplied():\n                 raise CmdException, 'Unknown patch \"%s\"' % name\n         else:\n             self.parser.error('incorrect number of arguments')\n \n-        patch = crt_series.get_patch(name)\n+        patch = self.current_head().get_patch(name)\n \n         log = patch.get_log()\n         if not log:\ndiff --git a/stgit/commands/mail.py b/stgit/commands/mail.py\nindex cdc0e2a..258cc7f 100644\n--- a/stgit/commands/mail.py\n+++ b/stgit/commands/mail.py\n@@ -350,7 +350,7 @@ class concreteCommand(Command):\n     def __build_message(self, tmpl, patch, patch_nr, total_nr, msg_id, ref_id):\n         \"\"\"Build the message to be sent via SMTP\n         \"\"\"\n-        p = crt_series.get_patch(patch)\n+        p = self.current_head().get_patch(patch)\n \n         descr = p.get_description().strip()\n         descr_lines = descr.split('\\n')\n@@ -463,12 +463,12 @@ class concreteCommand(Command):\n         \"\"\"\n         smtpserver = config.get('stgit.smtpserver')\n \n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n \n         if self.flags.all:\n             patches = applied\n         elif len(self.args) >= 1:\n-            unapplied = crt_series.get_unapplied()\n+            unapplied = self.current_head().get_unapplied()\n             patches = parse_patches(self.args, applied + unapplied, len(applied))\n         else:\n             raise CmdException, 'Incorrect options. Unknown patches to send'\ndiff --git a/stgit/commands/new.py b/stgit/commands/new.py\nindex 87f3874..4149c58 100644\n--- a/stgit/commands/new.py\n+++ b/stgit/commands/new.py\n@@ -74,10 +74,10 @@ class concreteCommand(Command):\n         if self.flags.author:\n             self.flags.authname, self.flags.authemail = name_email(self.flags.author)\n \n-        crt_series.new_patch(name, message = self.flags.message,\n-                             show_patch = self.flags.showpatch,\n-                             author_name = self.flags.authname,\n-                             author_email = self.flags.authemail,\n-                             author_date = self.flags.authdate,\n-                             committer_name = self.flags.commname,\n-                             committer_email = self.flags.commemail)\n+        self.current_head().new_patch(name, message = self.flags.message,\n+                                      show_patch = self.flags.showpatch,\n+                                      author_name = self.flags.authname,\n+                                      author_email = self.flags.authemail,\n+                                      author_date = self.flags.authdate,\n+                                      committer_name = self.flags.commname,\n+                                      committer_email = self.flags.commemail)\ndiff --git a/stgit/commands/patches.py b/stgit/commands/patches.py\nindex 7bf8920..f4abea6 100644\n--- a/stgit/commands/patches.py\n+++ b/stgit/commands/patches.py\n@@ -51,18 +51,18 @@ class concreteCommand(Command):\n         if len(self.args) < 1:\n             self.parser.error('incorrect number of arguments')\n \n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n         if not applied:\n             raise CmdException, 'No patches applied'\n \n-        revs = git.modifying_revs(self.args, crt_series.get_base(),\n-                                  crt_series.get_head())\n+        revs = git.modifying_revs(self.args, self.current_head().get_base(),\n+                                  self.current_head().get_head())\n         revs.reverse()\n \n         # build the patch/revision mapping\n         rev_patch = dict()\n         for name in applied:\n-            patch = crt_series.get_patch(name)\n+            patch = self.current_head().get_patch(name)\n             rev_patch[patch.get_top()] = patch\n \n         # print the patch names\ndiff --git a/stgit/commands/pick.py b/stgit/commands/pick.py\nindex 6ec8be3..0fb7282 100644\n--- a/stgit/commands/pick.py\n+++ b/stgit/commands/pick.py\n@@ -68,7 +68,7 @@ class concreteCommand(Command):\n         commit = git.Commit(commit_id)\n \n         if self.flags.fold or self.flags.update:\n-            if not crt_series.get_current():\n+            if not self.current_head().get_current():\n                 raise CmdException, 'No patches applied'\n         else:\n             patch_branch = commit_str.split('@')\n@@ -117,11 +117,11 @@ class concreteCommand(Command):\n \n             out.start('Importing commit %s' % commit_id)\n \n-            newpatch = crt_series.new_patch(patchname, message = message, can_edit = False,\n-                                            unapplied = True, bottom = bottom, top = top,\n-                                            author_name = author_name,\n-                                            author_email = author_email,\n-                                            author_date = author_date)\n+            newpatch = self.current_head().new_patch(patchname, message = message, can_edit = False,\n+                                                     unapplied = True, bottom = bottom, top = top,\n+                                                     author_name = author_name,\n+                                                     author_email = author_email,\n+                                                     author_date = author_date)\n             # in case the patch name was automatically generated\n             patchname = newpatch.get_name()\n \n@@ -135,7 +135,7 @@ class concreteCommand(Command):\n                     # commit_str to a git_id\n                     refseries = Series(refbranchname)\n                 else:\n-                    refseries = crt_series\n+                    refseries = self.current_head()\n                 patch = refseries.get_patch(refpatchname)\n                 if patch.get_log():\n                     out.info(\"Log was %s\" % newpatch.get_log())\n@@ -146,11 +146,11 @@ class concreteCommand(Command):\n                     out.info(\"No log for %s\\n\" % patchname)\n \n             if not self.flags.unapplied:\n-                modified = crt_series.push_patch(patchname)\n+                modified = self.current_head().push_patch(patchname)\n             else:\n                 modified = False\n \n-            if crt_series.empty_patch(patchname):\n+            if self.current_head().empty_patch(patchname):\n                 out.done('empty patch')\n             elif modified:\n                 out.done('modified')\ndiff --git a/stgit/commands/pop.py b/stgit/commands/pop.py\nindex 3b8b536..9a81c8a 100644\n--- a/stgit/commands/pop.py\n+++ b/stgit/commands/pop.py\n@@ -56,7 +56,7 @@ class concreteCommand(Command):\n         if not self.flags.keep:\n             check_local_changes()\n \n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n         if not applied:\n             raise CmdException, 'No patches applied'\n \ndiff --git a/stgit/commands/pull.py b/stgit/commands/pull.py\nindex 06d9aa9..0824443 100644\n--- a/stgit/commands/pull.py\n+++ b/stgit/commands/pull.py\n@@ -51,7 +51,7 @@ class concreteCommand(Command):\n     def func(self):\n         \"\"\"Pull the changes from a remote repository\n         \"\"\"\n-        policy = config.get('branch.%s.stgit.pull-policy' % crt_series.get_name()) or \\\n+        policy = config.get('branch.%s.stgit.pull-policy' % self.current_head_name()) or \\\n                  config.get('stgit.pull-policy')\n \n         if policy == 'rebase':\n@@ -69,9 +69,9 @@ class concreteCommand(Command):\n             if len(self.args) >= 1:\n                 repository = self.args[0]\n             else:\n-                repository = crt_series.get_parent_remote()\n+                repository = self.current_head().get_parent_remote()\n \n-        if crt_series.get_protected():\n+        if self.current_head().get_protected():\n             raise CmdException, 'This branch is protected. Pulls are not permitted'\n \n         check_local_changes()\n@@ -98,7 +98,7 @@ class concreteCommand(Command):\n             git.fetch(repository)\n             self.rebase(git.fetch_head())\n         elif policy == 'rebase':\n-            self.rebase(crt_series.get_parent_branch())\n+            self.rebase(self.current_head().get_parent_branch())\n \n         self.post_rebase(applied, self.flags.nopush, self.flags.merged)\n \ndiff --git a/stgit/commands/push.py b/stgit/commands/push.py\nindex 0d41cad..10acbff 100644\n--- a/stgit/commands/push.py\n+++ b/stgit/commands/push.py\n@@ -61,13 +61,13 @@ class concreteCommand(Command):\n \n         # If --undo is passed, do the work and exit\n         if self.flags.undo:\n-            patch = crt_series.get_current()\n+            patch = self.current_head().get_current()\n             if not patch:\n                 raise CmdException, 'No patch to undo'\n \n             out.start('Undoing push of \"%s\"' % patch)\n             resolved_all()\n-            if crt_series.undo_push():\n+            if self.current_head().undo_push():\n                 out.done()\n             else:\n                 out.done('patch unchanged')\n@@ -79,7 +79,7 @@ class concreteCommand(Command):\n         check_conflicts()\n         self.check_head_top_equal()\n \n-        unapplied = crt_series.get_unapplied()\n+        unapplied = self.current_head().get_unapplied()\n         if not unapplied:\n             raise CmdException, 'No more patches to push'\n \ndiff --git a/stgit/commands/rebase.py b/stgit/commands/rebase.py\nindex f953d6b..f14f244 100644\n--- a/stgit/commands/rebase.py\n+++ b/stgit/commands/rebase.py\n@@ -46,7 +46,7 @@ class concreteCommand(Command):\n         if len(self.args) != 1:\n             self.parser.error('incorrect number of arguments')\n \n-        if crt_series.get_protected():\n+        if self.current_head().get_protected():\n             raise CmdException, 'This branch is protected. Rebase is not permitted'\n \n         check_local_changes()\ndiff --git a/stgit/commands/refresh.py b/stgit/commands/refresh.py\nindex 90eb26b..4d6eac8 100644\n--- a/stgit/commands/refresh.py\n+++ b/stgit/commands/refresh.py\n@@ -88,10 +88,10 @@ class concreteCommand(Command):\n                 raise CmdException, \\\n                       'Only full refresh is available with the --patch option'\n             patch = self.flags.patch\n-            if not crt_series.patch_applied(patch):\n+            if not self.current_head().patch_applied(patch):\n                 raise CmdException, 'Patches \"%s\" not applied' % patch\n         else:\n-            patch = crt_series.get_current()\n+            patch = self.current_head().get_current()\n             if not patch:\n                 raise CmdException, 'No patches applied'\n \n@@ -100,7 +100,7 @@ class concreteCommand(Command):\n \n         if self.flags.undo:\n             out.start('Undoing the refresh of \"%s\"' % patch)\n-            crt_series.undo_refresh()\n+            self.current_head().undo_refresh()\n             out.done()\n             return\n \n@@ -117,14 +117,14 @@ class concreteCommand(Command):\n             sign_str = None\n \n         if git.local_changes() \\\n-               or not crt_series.head_top_equal() \\\n+               or not self.current_head().head_top_equal() \\\n                or self.flags.edit or self.flags.message \\\n                or self.flags.authname or self.flags.authemail or self.flags.authdate \\\n                or self.flags.commname or self.flags.commemail \\\n                or self.flags.sign or self.flags.ack:\n \n             if self.flags.patch:\n-                applied = crt_series.get_applied()\n+                applied = self.current_head().get_applied()\n                 between = applied[:applied.index(patch):-1]\n                 self.pop_patches(between, keep = True)\n \n@@ -132,18 +132,18 @@ class concreteCommand(Command):\n \n             if autoresolved == 'yes':\n                 resolved_all()\n-            crt_series.refresh_patch(files = self.args,\n-                                     message = self.flags.message,\n-                                     edit = self.flags.edit,\n-                                     show_patch = self.flags.showpatch,\n-                                     author_name = self.flags.authname,\n-                                     author_email = self.flags.authemail,\n-                                     author_date = self.flags.authdate,\n-                                     committer_name = self.flags.commname,\n-                                     committer_email = self.flags.commemail,\n-                                     backup = True, sign_str = sign_str)\n-\n-            if crt_series.empty_patch(patch):\n+            self.current_head().refresh_patch(files = self.args,\n+                                              message = self.flags.message,\n+                                              edit = self.flags.edit,\n+                                              show_patch = self.flags.showpatch,\n+                                              author_name = self.flags.authname,\n+                                              author_email = self.flags.authemail,\n+                                              author_date = self.flags.authdate,\n+                                              committer_name = self.flags.commname,\n+                                              committer_email = self.flags.commemail,\n+                                              backup = True, sign_str = sign_str)\n+\n+            if self.current_head().empty_patch(patch):\n                 out.done('empty patch')\n             else:\n                 out.done()\ndiff --git a/stgit/commands/rename.py b/stgit/commands/rename.py\nindex 5199a4a..8cf6cab 100644\n--- a/stgit/commands/rename.py\n+++ b/stgit/commands/rename.py\n@@ -40,5 +40,5 @@ class concreteCommand(Command):\n             self.parser.error('incorrect number of arguments')\n \n         out.start('Renaming patch \"%s\" to \"%s\"' % (self.args[0], self.args[1]))\n-        crt_series.rename_patch(self.args[0], self.args[1])\n+        self.current_head().rename_patch(self.args[0], self.args[1])\n         out.done()\ndiff --git a/stgit/commands/rm.py b/stgit/commands/rm.py\nindex 68714d0..35ca151 100644\n--- a/stgit/commands/rm.py\n+++ b/stgit/commands/rm.py\n@@ -42,7 +42,7 @@ class concreteCommand(Command):\n         if len(self.args) < 1:\n             self.parser.error('incorrect number of arguments')\n \n-        if not crt_series.get_current():\n+        if not self.current_head().get_current():\n             raise CmdException, 'No patches applied'\n \n         git.rm(self.args, self.flags.force)\ndiff --git a/stgit/commands/series.py b/stgit/commands/series.py\nindex 2afa013..c9f0efc 100644\n--- a/stgit/commands/series.py\n+++ b/stgit/commands/series.py\n@@ -74,7 +74,7 @@ class concreteCommand(Command):\n     def __get_description(self, patch):\n         \"\"\"Extract and return a patch's short description\n         \"\"\"\n-        p = crt_series.get_patch(patch)\n+        p = self.current_head().get_patch(patch)\n         descr = (p.get_description() or '').strip()\n         descr_lines = descr.split('\\n')\n         return descr_lines[0].rstrip()\n@@ -82,7 +82,7 @@ class concreteCommand(Command):\n     def __get_author(self, patch):\n         \"\"\"Extract and return a patch's short description\n         \"\"\"\n-        p = crt_series.get_patch(patch)\n+        p = self.current_head().get_patch(patch)\n         return p.get_authname();\n \n     def __print_patch(self, patch, branch_str, prefix, empty_prefix, length):\n@@ -90,7 +90,7 @@ class concreteCommand(Command):\n         \"\"\"\n         if self.flags.noprefix:\n             prefix = ''\n-        elif self.flags.empty and crt_series.empty_patch(patch):\n+        elif self.flags.empty and self.current_head().empty_patch(patch):\n             prefix = empty_prefix\n \n         patch_str = patch + branch_str\n@@ -108,41 +108,38 @@ class concreteCommand(Command):\n     def func(self):\n         \"\"\"Show the patch series\n         \"\"\"\n-        global crt_series\n \n         # current series patches\n         if self.flags.invisible:\n             applied = unapplied = []\n-            hidden = crt_series.get_hidden()\n+            hidden = self.current_head().get_hidden()\n         elif self.flags.all:\n-            applied = crt_series.get_applied()\n-            unapplied = crt_series.get_unapplied()\n-            hidden = crt_series.get_hidden()\n+            applied = self.current_head().get_applied()\n+            unapplied = self.current_head().get_unapplied()\n+            hidden = self.current_head().get_hidden()\n         else:\n-            applied = crt_series.get_applied()\n-            unapplied = crt_series.get_unapplied()\n+            applied = self.current_head().get_applied()\n+            unapplied = self.current_head().get_unapplied()\n             hidden = []\n \n         if self.flags.missing:\n             # switch the series, the one specified with --missing should\n             # become the current\n-            cmp_series = crt_series\n-            crt_series = stack.Series(self.flags.missing)\n-            stgit.commands.common.crt_series = crt_series\n+            miss_series = stack.Series(self.flags.missing)\n \n             cmp_patches = applied + unapplied + hidden\n \n             # new current series patches\n             if self.flags.invisible:\n                 applied = unapplied = []\n-                hidden = crt_series.get_hidden()\n+                hidden = miss_series.get_hidden()\n             elif self.flags.all:\n-                applied = crt_series.get_applied()\n-                unapplied = crt_series.get_unapplied()\n-                hidden = crt_series.get_hidden()\n+                applied = miss_series.get_applied()\n+                unapplied = miss_series.get_unapplied()\n+                hidden = miss_series.get_hidden()\n             else:\n-                applied = crt_series.get_applied()\n-                unapplied = crt_series.get_unapplied()\n+                applied = miss_series.get_applied()\n+                unapplied = miss_series.get_unapplied()\n                 hidden = []\n         else:\n             cmp_patches = []\n@@ -182,7 +179,7 @@ class concreteCommand(Command):\n             return\n \n         if self.flags.showbranch:\n-            branch_str = '@' + crt_series.get_name()\n+            branch_str = '@' + self.current_head_name()\n         else:\n             branch_str = ''\n \ndiff --git a/stgit/commands/show.py b/stgit/commands/show.py\nindex 5ff772f..4540f58 100644\n--- a/stgit/commands/show.py\n+++ b/stgit/commands/show.py\n@@ -44,8 +44,8 @@ class concreteCommand(Command):\n     def func(self):\n         \"\"\"Show commit log and diff\n         \"\"\"\n-        applied = crt_series.get_applied()\n-        unapplied = crt_series.get_unapplied()\n+        applied = self.current_head().get_applied()\n+        unapplied = self.current_head().get_unapplied()\n \n         if self.flags.applied:\n             patches = applied\n@@ -55,7 +55,7 @@ class concreteCommand(Command):\n             patches = ['HEAD']\n         else:\n             if len(self.args) == 1 and self.args[0].find('..') == -1 \\\n-                   and not crt_series.patch_exists(self.args[0]):\n+                   and not self.current_head().patch_exists(self.args[0]):\n                 # it might be just a commit id\n                 patches = self.args\n             else:\ndiff --git a/stgit/commands/sink.py b/stgit/commands/sink.py\nindex c3ef4d5..84d6bac 100644\n--- a/stgit/commands/sink.py\n+++ b/stgit/commands/sink.py\n@@ -47,20 +47,20 @@ class concreteCommand(Command):\n         check_conflicts()\n         self.check_head_top_equal()\n \n-        oldapplied = crt_series.get_applied()\n-        unapplied = crt_series.get_unapplied()\n+        oldapplied = self.current_head().get_applied()\n+        unapplied = self.current_head().get_unapplied()\n         all = unapplied + oldapplied\n \n         if len(self.args) > 0:\n             patches = parse_patches(self.args, all)\n         else:\n-            patches = [ crt_series.get_current() ]\n+            patches = [ self.current_head().get_current() ]\n \n-        crt_series.pop_patch(self.flags.to or oldapplied[0])\n+        self.current_head().pop_patch(self.flags.to or oldapplied[0])\n         self.push_patches(patches)\n \n         if not self.flags.nopush:\n-            newapplied = crt_series.get_applied()\n+            newapplied = self.current_head().get_applied()\n             def not_reapplied_yet(p):\n                 return not p in newapplied\n             self.push_patches(filter(not_reapplied_yet, oldapplied))\ndiff --git a/stgit/commands/sync.py b/stgit/commands/sync.py\nindex 2882391..18d7394 100644\n--- a/stgit/commands/sync.py\n+++ b/stgit/commands/sync.py\n@@ -67,7 +67,6 @@ class concreteCommand(Command):\n     def func(self):\n         \"\"\"Synchronise a range of patches\n         \"\"\"\n-        global crt_series\n \n         if self.flags.undo:\n             if self.flags.ref_branch or self.flags.series:\n@@ -75,15 +74,15 @@ class concreteCommand(Command):\n                       '--undo cannot be specified with --ref-branch or --series'\n             self.__check_all()\n \n-            out.start('Undoing the sync of \"%s\"' % crt_series.get_current())\n-            crt_series.undo_refresh()\n+            out.start('Undoing the sync of \"%s\"' % self.current_head().get_current())\n+            self.current_head().undo_refresh()\n             git.reset()\n             out.done()\n             return\n \n         if self.flags.ref_branch:\n             remote_series = stack.Series(self.flags.ref_branch)\n-            if self.flags.ref_branch == crt_series.get_name():\n+            if self.flags.ref_branch == self.current_head_name():\n                 raise CmdException, 'Cannot synchronise with the current branch'\n             remote_patches = remote_series.get_applied()\n \n@@ -108,14 +107,14 @@ class concreteCommand(Command):\n         else:\n             raise CmdException, 'No remote branch or series specified'\n \n-        applied = crt_series.get_applied()\n+        applied = self.current_head().get_applied()\n \n         if self.flags.all:\n             patches = applied\n         elif len(self.args) != 0:\n             patches = parse_patches(self.args, applied, ordered = True)\n         elif applied:\n-            patches = [crt_series.get_current()]\n+            patches = [self.current_head().get_current()]\n         else:\n             self.parser.error('no patches applied')\n \n@@ -144,7 +143,7 @@ class concreteCommand(Command):\n             # the actual sync\n             out.start('Synchronising \"%s\"' % p)\n \n-            patch = crt_series.get_patch(p)\n+            patch = self.current_head().get_patch(p)\n             bottom = patch.get_bottom()\n             top = patch.get_top()\n \n@@ -159,8 +158,8 @@ class concreteCommand(Command):\n             if git.local_changes(verbose = False):\n                 # index (cache) already updated by the git merge. The\n                 # backup information was already reset above\n-                crt_series.refresh_patch(cache_update = False, backup = False,\n-                                         log = 'sync')\n+                self.current_head().refresh_patch(cache_update = False, backup = False,\n+                                                  log = 'sync')\n                 out.done('updated')\n             else:\n                 out.done()\ndiff --git a/stgit/commands/top.py b/stgit/commands/top.py\nindex 88c03e2..ae57387 100644\n--- a/stgit/commands/top.py\n+++ b/stgit/commands/top.py\n@@ -40,7 +40,7 @@ class concreteCommand(Command):\n         if len(self.args) != 0:\n             self.parser.error('incorrect number of arguments')\n \n-        name = crt_series.get_current()\n+        name = self.current_head().get_current()\n         if name:\n             out.stdout(name)\n         else:\ndiff --git a/stgit/commands/unapplied.py b/stgit/commands/unapplied.py\nindex 083ed07..a5aaddc 100644\n--- a/stgit/commands/unapplied.py\n+++ b/stgit/commands/unapplied.py\n@@ -44,7 +44,7 @@ class concreteCommand(Command):\n         if len(self.args) != 0:\n             self.parser.error('incorrect number of arguments')\n \n-        unapplied = crt_series.get_unapplied()\n+        unapplied = self.current_head().get_unapplied()\n \n         if self.flags.count:\n             out.stdout(len(unapplied))\ndiff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py\nindex ee2342f..48fda15 100644\n--- a/stgit/commands/uncommit.py\n+++ b/stgit/commands/uncommit.py\n@@ -84,7 +84,7 @@ class concreteCommand(Command):\n             patchnames = self.args\n             patch_nr = len(patchnames)\n \n-        if crt_series.get_protected():\n+        if self.current_head().get_protected():\n             raise CmdException, \\\n                   'This branch is protected. Uncommit is not permitted'\n \n@@ -98,7 +98,7 @@ class concreteCommand(Command):\n             return (commit, commit_id, parent)\n \n         commits = []\n-        next_commit = crt_series.get_base()\n+        next_commit = self.current_head().get_base()\n         if patch_nr:\n             out.start('Uncommitting %d patches' % patch_nr)\n             for i in xrange(patch_nr):\n@@ -119,12 +119,12 @@ class concreteCommand(Command):\n             zip(commits, patchnames or [None for i in xrange(len(commits))]):\n             author_name, author_email, author_date = \\\n                          name_email_date(commit.get_author())\n-            crt_series.new_patch(patchname,\n-                                 can_edit = False, before_existing = True,\n-                                 top = commit_id, bottom = parent,\n-                                 message = commit.get_log(),\n-                                 author_name = author_name,\n-                                 author_email = author_email,\n-                                 author_date = author_date)\n+            self.current_head().new_patch(patchname,\n+                                          can_edit = False, before_existing = True,\n+                                          top = commit_id, bottom = parent,\n+                                          message = commit.get_log(),\n+                                          author_name = author_name,\n+                                          author_email = author_email,\n+                                          author_date = author_date)\n \n         out.done()\ndiff --git a/stgit/commands/unhide.py b/stgit/commands/unhide.py\nindex 01d4b18..f9817c3 100644\n--- a/stgit/commands/unhide.py\n+++ b/stgit/commands/unhide.py\n@@ -38,12 +38,12 @@ class concreteCommand(Command):\n         \"\"\"\n         if self.args:\n             # parsing all the patches for a more meaningful error reporting\n-            all_patches = crt_series.get_applied() + crt_series.get_unapplied() \\\n-                          + crt_series.get_hidden()\n+            all_patches = self.current_head().get_applied() + self.current_head().get_unapplied() \\\n+                          + self.current_head().get_hidden()\n             patches = parse_patches(self.args, all_patches)\n         else:\n             self.parser.error('No patches specified')\n \n         for patch in patches:\n-            crt_series.unhide_patch(patch)\n+            self.current_head().unhide_patch(patch)\n             out.info('Patch \"%s\" unhidden' % patch)\ndiff --git a/stgit/main.py b/stgit/main.py\nindex 1fd5df9..1871cd3 100644\n--- a/stgit/main.py\n+++ b/stgit/main.py\n@@ -271,13 +271,6 @@ def main():\n \n     try:\n         config_setup()\n-\n-        # 'clone' doesn't expect an already initialised GIT tree. A Series\n-        # object will be created after the GIT tree is cloned\n-        if cmd != 'clone':\n-            command_module.crt_series = command.current_head()\n-            stgit.commands.common.crt_series = command_module.crt_series\n-\n         command.func()\n     except (IOError, ParsingError, NoSectionError, CmdException,\n             StackException, GitException, GitMergeException,\n"},{"id":"45190","messageId":"20070616220110.14941.24888.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 8/9] Add a constructor to PatchSet.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:01:10Z","receivedAt":"2007-06-16T22:01:10Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Move __base_dir up into PatchSet as well, and add an accessor.\n\nSigned-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/stack.py |   38 ++++++++++++++++++++++----------------\n 1 files changed, 22 insertions(+), 16 deletions(-)\n\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex 634588d..e33fe62 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -277,11 +277,26 @@ class Patch(StgitObject):\n FORMAT_VERSION = 2\n \n class PatchSet(StgitObject):\n+    def __init__(self, name = None):\n+        try:\n+            if name:\n+                self.set_name (name)\n+            else:\n+                self.set_name (git.get_head_file())\n+            self.__base_dir = basedir.get()\n+        except git.GitException, ex:\n+            raise StackException, 'GIT tree not initialised: %s' % ex\n+\n+        self._set_dir(os.path.join(self.__base_dir, 'patches', self.get_name()))\n+\n     def get_name(self):\n         return self.__name\n     def set_name(self, name):\n         self.__name = name\n \n+    def _basedir(self):\n+        return self.__base_dir\n+\n     def get_head(self):\n         \"\"\"Return the head of the branch\n         \"\"\"\n@@ -337,22 +352,13 @@ class Series(PatchSet):\n     def __init__(self, name = None):\n         \"\"\"Takes a series name as the parameter.\n         \"\"\"\n-        try:\n-            if name:\n-                self.set_name (name)\n-            else:\n-                self.set_name (git.get_head_file())\n-            self.__base_dir = basedir.get()\n-        except git.GitException, ex:\n-            raise StackException, 'GIT tree not initialised: %s' % ex\n-\n-        self._set_dir(os.path.join(self.__base_dir, 'patches', self.get_name()))\n+        PatchSet.__init__(self, name)\n \n         # Update the branch to the latest format version if it is\n         # initialized, but don't touch it if it isn't.\n         self.update_to_current_format_version()\n \n-        self.__refs_dir = os.path.join(self.__base_dir, 'refs', 'patches',\n+        self.__refs_dir = os.path.join(self._basedir(), 'refs', 'patches',\n                                        self.get_name())\n \n         self.__applied_file = os.path.join(self._dir(), 'applied')\n@@ -374,7 +380,7 @@ class Series(PatchSet):\n         possible on external functions that may change during a format\n         version bump, since it must remain able to process older formats.\"\"\"\n \n-        branch_dir = os.path.join(self.__base_dir, 'patches', self.get_name())\n+        branch_dir = os.path.join(self._basedir(), 'patches', self.get_name())\n         def get_format_version():\n             \"\"\"Return the integer format version number, or None if the\n             branch doesn't have any StGIT metadata at all, of any version.\"\"\"\n@@ -416,7 +422,7 @@ class Series(PatchSet):\n             mkdir(os.path.join(branch_dir, 'trash'))\n             patch_dir = os.path.join(branch_dir, 'patches')\n             mkdir(patch_dir)\n-            refs_dir = os.path.join(self.__base_dir, 'refs', 'patches', self.get_name())\n+            refs_dir = os.path.join(self._basedir(), 'refs', 'patches', self.get_name())\n             mkdir(refs_dir)\n             for patch in (file(os.path.join(branch_dir, 'unapplied')).readlines()\n                           + file(os.path.join(branch_dir, 'applied')).readlines()):\n@@ -435,7 +441,7 @@ class Series(PatchSet):\n                     config.set('branch.%s.description' % self.get_name(), desc)\n                 rm(desc_file)\n             rm(os.path.join(branch_dir, 'current'))\n-            rm(os.path.join(self.__base_dir, 'refs', 'bases', self.get_name()))\n+            rm(os.path.join(self._basedir(), 'refs', 'bases', self.get_name()))\n             set_format_version(2)\n \n         # Make sure we're at the latest version.\n@@ -603,10 +609,10 @@ class Series(PatchSet):\n         git.rename_branch(self.get_name(), to_name)\n \n         if os.path.isdir(self._dir()):\n-            rename(os.path.join(self.__base_dir, 'patches'),\n+            rename(os.path.join(self._basedir(), 'patches'),\n                    self.get_name(), to_stack.get_name())\n         if os.path.exists(self.__refs_dir):\n-            rename(os.path.join(self.__base_dir, 'refs', 'patches'),\n+            rename(os.path.join(self._basedir(), 'refs', 'patches'),\n                    self.get_name(), to_stack.get_name())\n \n         # Rename the config section\n"},{"id":"45189","messageId":"20070616220115.14941.5072.stgit@gandelf.nowhere.earth","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"[StGIT PATCH 9/9] Cleanup the use of the Series class.","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-16T22:01:15Z","receivedAt":"2007-06-16T22:01:15Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"Signed-off-by: Yann Dirson <ydirson@altern.org>\n---\n\n stgit/commands/pick.py |    3 +--\n stgit/stack.py         |    2 +-\n 2 files changed, 2 insertions(+), 3 deletions(-)\n\ndiff --git a/stgit/commands/pick.py b/stgit/commands/pick.py\nindex 0fb7282..9dd49d2 100644\n--- a/stgit/commands/pick.py\n+++ b/stgit/commands/pick.py\n@@ -21,7 +21,6 @@ from optparse import OptionParser, make_option\n from stgit.commands.common import *\n from stgit.utils import *\n from stgit import stack, git\n-from stgit.stack import Series\n \n \n class concreteCommand(Command):\n@@ -133,7 +132,7 @@ class concreteCommand(Command):\n                 if refbranchname:\n                     # assume the refseries is OK, since we already resolved\n                     # commit_str to a git_id\n-                    refseries = Series(refbranchname)\n+                    refseries = stack.Series(refbranchname)\n                 else:\n                     refseries = self.current_head()\n                 patch = refseries.get_patch(refpatchname)\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex e33fe62..8acb308 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -629,8 +629,8 @@ class Series(PatchSet):\n             base = self.get_base()\n         except:\n             base = git.get_head()\n-        Series(target_series).init(create_at = base)\n         new_series = Series(target_series)\n+        new_series.init(create_at = base)\n \n         # generate an artificial description file\n         new_series.set_description('clone of \"%s\"' % self.get_name())\n"},{"id":"45390","messageId":"20070619224116.GB7730@nan92-1-81-57-214-146.fbx.proxad.net","threadId":"8618","inReplyTo":"20070616213615.14941.31187.stgit@gandelf.nowhere.earth","subject":"Re: [StGIT PATCH 0/9] Refactoring of command handling","fromName":"Yann Dirson","fromEmail":"ydirson@altern.org","sentAt":"2007-06-19T22:41:17Z","receivedAt":"2007-06-19T22:41:17Z","isPatch":true,"sender":{"key":"ydirson@altern.org","avatar":"https://avatars.githubusercontent.com/u/1190950?v=4"},"body":"On Sun, Jun 17, 2007 at 12:00:28AM +0200, Yann Dirson wrote:\n>       Refactor command definition with a Command class.\n\nThat patch (3/9, and the main patch in the series) was most probably\nblocked from the list because of its size.  The whole series is anyway\navailable at http://repo.or.cz/w/stgit/ydirson.git (together with even\nmore unreleased patches - beware ;)\n\nMore generally, I'll try to --sign those patches in my stack that I\nconsider stable and have been (or are in the queue fo being) sent to\nCatalin.\n\nBest regards,\n-- \nYann\n"}]}