Fix indexing error during "diff -r/"
authorKarl Hasselström <kha@treskal.com>
Wed, 24 May 2006 06:06:58 +0000 (08:06 +0200)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 24 May 2006 20:59:52 +0000 (21:59 +0100)
The string indexing when decoding the -r argument for diff made an
implicit assumption that the revision string was at least two
characters long, which broke on the simple invocation "diff -r/".

stgit/commands/diff.py
stgit/utils.py

index d765784..caa3c5b 100644 (file)
@@ -56,11 +56,11 @@ def func(parser, options, args):
         rev_list_len = len(rev_list)
         if rev_list_len == 1:
             rev = rev_list[0]
-            if rev[-1] == '/':
+            if rev.endswith('/'):
                 # the whole patch
-                rev = rev[:-1]
-                if rev[-1] == '/':
-                    rev = rev[:-1]
+                rev = strip_suffix('/', rev)
+                if rev.endswith('/'):
+                    rev = strip_suffix('/', rev)
                 rev1 = rev + '//bottom'
                 rev2 = rev + '//top'
             else:
index ed6e43c..67431ec 100644 (file)
@@ -109,6 +109,12 @@ def strip_prefix(prefix, string):
     assert string.startswith(prefix)
     return string[len(prefix):]
 
+def strip_suffix(suffix, string):
+    """Return string, without the suffix. Blow up if string doesn't
+    end with suffix."""
+    assert string.endswith(suffix)
+    return string[:-len(suffix)]
+
 def remove_dirs(basedir, dirs):
     """Starting at join(basedir, dirs), remove the directory if empty,
     and try the same with its parent, until we find a nonempty