{"thread":{"id":"12527","subject":"AssertionError in \"stg uncommit\" when going too far back","startedAt":"2008-03-05T21:47:02Z","lastAt":"2008-03-08T12:19:58Z","messageCount":2,"participants":["Pavel Roskin","Catalin Marinas"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"71129","messageId":"1204753622.17845.16.camel@dv","threadId":"12527","inReplyTo":null,"subject":"AssertionError in \"stg uncommit\" when going too far back","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2008-03-05T21:47:02Z","receivedAt":"2008-03-05T21:47:02Z","isPatch":false,"sender":{"key":"proski@gnu.org","avatar":null},"body":"Hello!\n\n\"stg uncommit\" causes AssertionError if the number commits to uncommit it too large:\n\n$ stg uncommit -n 10000 \nUncommitting 10000 patches ... Traceback (most recent call last):\n  File \"/home/proski/bin/stg\", line 43, in <module>\n    main()\n  File \"home/proski/lib/python2.5/site-packages/stgit/main.py\", line 278, in main\n  File \"home/proski/lib/python2.5/site-packages/stgit/commands/uncommit.py\", line 94, in func\n  File \"home/proski/lib/python2.5/site-packages/stgit/lib/git.py\", line 171, in parent\nAssertionError\n\nPerhaps parent() should raise an exception that uncommit would\nintercept?  Sorry, my Python is not so good to make a correct fix.\nHere's a prototype patch that still doesn't terminate gracefully:\n\nAttributeError: 'module' object has no attribute 'NoParentException'\n\n\ndiff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py\nindex 933ec60..87dab77 100644\n--- a/stgit/commands/uncommit.py\n+++ b/stgit/commands/uncommit.py\n@@ -21,7 +21,7 @@ from optparse import make_option\n from stgit.commands import common\n from stgit.lib import transaction\n from stgit.out import *\n-from stgit import utils\n+from stgit import utils, git\n \n help = 'turn regular GIT commits into StGIT patches'\n usage = \"\"\"%prog [<patchnames>] | -n NUM [<prefix>]] | -t <committish> [-x]\n@@ -89,9 +89,12 @@ def func(parser, options, args):\n     next_commit = stack.base\n     if patch_nr:\n         out.start('Uncommitting %d patches' % patch_nr)\n-        for i in xrange(patch_nr):\n-            commits.append(next_commit)\n-            next_commit = next_commit.data.parent\n+        try:\n+            for i in xrange(patch_nr):\n+                commits.append(next_commit)\n+                next_commit = next_commit.data.parent\n+        except git.NoParentException:\n+            raise common.CmdException('Cannot go beyond initial commit')\n     else:\n         if options.exclusive:\n             out.start('Uncommitting to %s (exclusive)' % to_commit)\ndiff --git a/stgit/lib/git.py b/stgit/lib/git.py\nindex 50dc4f1..d8d339c 100644\n--- a/stgit/lib/git.py\n+++ b/stgit/lib/git.py\n@@ -16,6 +16,9 @@ class DetachedHeadException(RepositoryException):\n     def __init__(self):\n         RepositoryException.__init__(self, 'Not on any branch')\n \n+class NoParentException(exception.StgException):\n+    pass\n+\n class Repr(object):\n     def __repr__(self):\n         return str(self)\n@@ -168,7 +171,8 @@ class Commitdata(Repr):\n     parents = property(lambda self: self.__parents)\n     @property\n     def parent(self):\n-        assert len(self.__parents) == 1\n+        if len(self.__parents) != 1:\n+            raise NoParentException\n         return self.__parents[0]\n     author = property(lambda self: self.__author)\n     committer = property(lambda self: self.__committer)\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"71415","messageId":"b0943d9e0803080419y6373ce62xfb108a15203858c7@mail.gmail.com","threadId":"12527","inReplyTo":"1204753622.17845.16.camel@dv","subject":"Re: AssertionError in \"stg uncommit\" when going too far back","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2008-03-08T12:19:58Z","receivedAt":"2008-03-08T12:19:58Z","isPatch":false,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 05/03/2008, Pavel Roskin <proski@gnu.org> wrote:\n> \"stg uncommit\" causes AssertionError if the number commits to uncommit it too large:\n>\n> $ stg uncommit -n 10000\n> Uncommitting 10000 patches ... Traceback (most recent call last):\n>  File \"/home/proski/bin/stg\", line 43, in <module>\n>    main()\n>  File \"home/proski/lib/python2.5/site-packages/stgit/main.py\", line 278, in main\n>  File \"home/proski/lib/python2.5/site-packages/stgit/commands/uncommit.py\", line 94, in func\n>  File \"home/proski/lib/python2.5/site-packages/stgit/lib/git.py\", line 171, in parent\n> AssertionError\n\nThat's on the master branch. I think on the stable one, it used to\nreport a message like \"Commit doesn't have exactly one parent\".\n\nIn the latest version, we should indeed raise an exception rather than\njust assert. I wouldn't declare a new exception class but rather use\nan existing one with a meaningful error message. We can't recover from\nthis anyway and we would simply cancel the operation. I'll let Karl\ncomment on this as well.\n\nThanks for reporting it.\n\n-- \nCatalin\n"}]}