Skip to contentSkip to conversation

gitview: Fix the blame interface.

PATCH In review Aneesh Kumar K.V 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gitview: Fix the blame interface.

The async reading from the pipe was skipping some of the input lines. Fix the same by making sure that we add the partial content of the previous read to the newly read data.

---
 contrib/gitview/gitview |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
contrib/gitview/gitview +16 -2
index 098cb01..286e974 100755
@@ -352,6 +352,7 @@ class AnnotateWindow(object):
 		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 		self.window.set_border_width(0)
 		self.window.set_title("Git repository browser annotation window")
+		self.prev_read = ""
 
 		# Use two thirds of the screen by default
 		screen = self.window.get_screen()
@@ -401,7 +402,11 @@ class AnnotateWindow(object):
 	def data_ready(self, source, condition):
 		while (1):
 			try :
-				buffer = source.read(8192)
+				# A simple readline doesn't work
+				# a readline bug ??
+				buffer=""
+				buffer = source.read(100)
+
 			except:
 				# resource temporary not available
 				return True
@@ -411,6 +416,14 @@ class AnnotateWindow(object):
 				source.close()
 				return False
 
+			if (self.prev_read != ""):
+				buffer = self.prev_read + buffer
+				self.prev_read = ""
+
+			if (buffer[len(buffer) -1] != '\n'):
+				self.prev_read = buffer[buffer.rindex("\n"):(len(buffer))]
+				buffer = buffer[0:buffer.rindex("\n")]
+
 			for buff in buffer.split("\n"):
 				annotate_line = re.compile('^([0-9a-f]{40}) (.+) (.+) (.+)$')
 				m = annotate_line.match(buff)
@@ -419,7 +432,8 @@ class AnnotateWindow(object):
 					m = annotate_line.match(buff)
 					if not m:
 						continue
-					filename = m.group(2)
+					else:
+						filename = m.group(2)
 				else:
 					self.commit_sha1 = m.group(1)
 					self.source_line = int(m.group(2))
Signature · 1 line
1.5.2.1.239.g75d8-dirty
#1 lore raw

PATCH 2/2 gitview: run blame with -M and -C

From: Aneesh Kumar K.V <[email protected]>

pass -M and -C option to git-blame so that blame browsing works when the data is copied over from other files.

---
 contrib/gitview/gitview |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
contrib/gitview/gitview +1 -1
index 286e974..01128f4 100755
@@ -530,7 +530,7 @@ class AnnotateWindow(object):
 
 		self.add_file_data(filename, commit_sha1, line_num)
 
-		fp = os.popen("git blame --incremental -- " + filename + " " + commit_sha1)
+		fp = os.popen("git blame --incremental -M -C -C -- " + filename + " " + commit_sha1)
 		flags = fcntl.fcntl(fp.fileno(), fcntl.F_GETFL)
 		fcntl.fcntl(fp.fileno(), fcntl.F_SETFL, flags | os.O_NONBLOCK)
 		self.io_watch_tag = gobject.io_add_watch(fp, gobject.IO_IN, self.data_ready)
Signature · 1 line
1.5.2.1.239.g75d8-dirty
#2 lore raw

Re: [PATCH 2/2] gitview: run blame with -M and -C

Quoted 15 lines · Aneesh Kumar K.V

From: Aneesh Kumar K.V <[email protected]>

pass -M and -C option to git-blame so that blame browsing works when the data is copied over from other files.

---
 contrib/gitview/gitview |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
contrib/gitview/gitview +0 -0
index 286e974..01128f4 100755

contrib/gitview/gitview class AnnotateWindow(object): · line 533

Quoted 5 lines
contrib/gitview/gitview +1 -1
@@ -530,7 +530,7 @@ class AnnotateWindow(object):
 
 		self.add_file_data(filename, commit_sha1, line_num)
 
-		fp = os.popen("git blame --incremental -- " + filename + " " + commit_sha1)
+		fp = os.popen("git blame --incremental -M -C -C -- " + filename + " " + commit_sha1)

You do not have to say "-M -C -C"; "-C" would imply "-M" anyway.

#3 lore raw
In reply to Aneesh Kumar K.V

contrib/gitview/gitview class AnnotateWindow(object): · line 409

Quoted 10 lines · Aneesh Kumar K.V
contrib/gitview/gitview +5 -1
@@ -401,7 +402,11 @@ class AnnotateWindow(object):
 	def data_ready(self, source, condition):
 		while (1):
 			try :
-				buffer = source.read(8192)
+				# A simple readline doesn't work
+				# a readline bug ??
+				buffer=""
+				buffer = source.read(100)
+

Are you sure about the first assignment?

contrib/gitview/gitview class AnnotateWindow(object): · line 439

Quoted 10 lines
contrib/gitview/gitview +2 -1
@@ -419,7 +432,8 @@ class AnnotateWindow(object):
 					m = annotate_line.match(buff)
 					if not m:
 						continue
-					filename = m.group(2)
+					else:
+						filename = m.group(2)
 				else:
 					self.commit_sha1 = m.group(1)
 					self.source_line = int(m.group(2))

The script is in contrib/ so I probably shouldn't be nitpicking, but for this particular hunk, I think (1) this is a no-op change, and (2) the original is easier to read.

#4 lore raw
Quoted 15 lines · Junio C Hamano

contrib/gitview/gitview class AnnotateWindow(object): · line 409

Quoted 10 lines · Aneesh Kumar K.V
contrib/gitview/gitview +5 -1
@@ -401,7 +402,11 @@ class AnnotateWindow(object):
      def data_ready(self, source, condition):
              while (1):
                      try :
-                             buffer = source.read(8192)
+                             # A simple readline doesn't work
+                             # a readline bug ??
+                             buffer=""
+                             buffer = source.read(100)
+

Are you sure about the first assignment?

That was a debug left over i guess. I will send an update patch which removed the same.
The problem was an interrupted source.read/readline was returning old values.

Quoted 6 lines
Quoted 6 lines
contrib/gitview/gitview +1 -1
@@ -419,7 +432,8 @@ class AnnotateWindow(object):
                                      m = annotate_line.match(buff)
                                      if not m:
                                              continue
-                                     filename = m.group(2)
+                                     else:
Quoted 10 lines

contrib/gitview/gitview class AnnotateWindow(object): · line 439

Quoted 4 lines
contrib/gitview/gitview +1 -0
+                                             filename = m.group(2)
                              else:
                                      self.commit_sha1 = m.group(1)
                                      self.source_line = int(m.group(2))

The script is in contrib/ so I probably shouldn't be nitpicking, but for this particular hunk, I think (1) this is a no-op change, and (2) the original is easier to read.

I will update if you feel that way

-aneesh