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

[PATCH 3/3] gitview: Catch exception from rindex

From
Aneesh Kumar K.V <aneesh.kumar@gmail.com>
Date
Jun 12, 2007, 17:59 UTC
Message-ID
<11816711802519-git-send-email-aneesh.kumar@gmail.com>
In-Reply-To
<392459374618773353ea560d021dd3211d143d86.1181671162.git.aneesh.kumar@gmail.com>

If we have really short read the input buffer will not have a new line and rindex with through the ValueError exception. Handle the same gracefully

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
 contrib/gitview/gitview |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/contrib/gitview/gitview b/contrib/gitview/gitview
index 01128f4..4f39ddd 100755
--- a/contrib/gitview/gitview
+++ b/contrib/gitview/gitview
@@ -421,8 +421,13 @@ class AnnotateWindow(object):
 				self.prev_read = ""
 
 			if (buffer[len(buffer) -1] != '\n'):
-				self.prev_read = buffer[buffer.rindex("\n"):(len(buffer))]
-				buffer = buffer[0:buffer.rindex("\n")]
+				try:
+					newline_index = buffer.rindex("\n")
+				except ValueError:
+					newline_index = 0
+
+				self.prev_read = buffer[newline_index:(len(buffer))]
+				buffer = buffer[0:newline_index]
 
 			for buff in buffer.split("\n"):
 				annotate_line = re.compile('^([0-9a-f]{40}) (.+) (.+) (.+)$')
-- 
1.5.2.1.239.g75d8-dirty
Message 1 of 1 in “gitview: Catch exception from rindex”
  1. 3/3 gitview: Catch exception from rindexAneesh Kumar K.V, Jun 12, 2007

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.