Skip to contentSkip to conversation

gitview: Catch exception from rindex

PATCH New Aneesh Kumar K.V 1 participant 1 message Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 392459374618773353ea560d021dd3211d143d86.1181671162.git.aneesh.kumar@gmail.com

#1 lore raw

PATCH 3/3 gitview: Catch exception from rindex

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

---
 contrib/gitview/gitview |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
contrib/gitview/gitview +7 -2
index 01128f4..4f39ddd 100755
@@ -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}) (.+) (.+) (.+)$')
Signature · 1 line
1.5.2.1.239.g75d8-dirty