git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] Fix indexing error during "diff -r/"

From
Karl Hasselström <kha@treskal.com>
Date
May 24, 2006, 06:06 UTC
Message-ID
<20060524060658.GB1490@diana.vm.bytemark.co.uk>
In-Reply-To
<20060524060537.GA1173@diana.vm.bytemark.co.uk>

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 |    8 ++++----
 stgit/utils.py         |    6 ++++++
 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/stgit/commands/diff.py b/stgit/commands/diff.py
index d765784..caa3c5b 100644
--- a/stgit/commands/diff.py
+++ b/stgit/commands/diff.py
@@ -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:
diff --git a/stgit/utils.py b/stgit/utils.py
index ed6e43c..67431ec 100644
--- a/stgit/utils.py
+++ b/stgit/utils.py
@@ -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
Previous: Karl HasselströmNext: Karl Hasselström
Message 3 of 5 in “A few stgit bugfixes”
  1. Karl HasselströmMay 24, 2006
  2. 1/3 Fix infinite recursion on absolute pathsKarl Hasselström, May 24, 2006
  3. 2/3 Fix indexing error during "diff -r/"Karl Hasselström, May 24, 2006
  4. 3/3 Explicitly specify utf-8 coding in fileKarl Hasselström, May 24, 2006
  5. Catalin MarinasMay 24, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.