gitview: Read tag and branch information using git ls-remote
This fix the below bug Junio C Hamano <junkio@cox.net> writes: > > It does not work in my repository, since you do not seem to > handle branch and tag names with slashes in them. All of my > topic branches live in directories with two-letter names > (e.g. ak/gitview). Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
aneesh.kumar@gmail.com committed
Feb 21, 2006 at 16:00 UTC
5301eee92ceb1c349ea8090a4d8aa3aa70c4abed
1 file changed
+14
-36
contrib/gitview/gitview
+14
-36
@@ -56,20 +56,6 @@ def show_date(epoch, tz):
56
57
return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(secs))
58
59
-def get_sha1_from_tags(line):
60
- fp = os.popen("git cat-file -t " + line)
61
- entry = string.strip(fp.readline())
62
- fp.close()
63
- if (entry == "commit"):
64
- return line
65
- elif (entry == "tag"):
66
- fp = os.popen("git cat-file tag "+ line)
67
- entry = string.strip(fp.readline())
68
- fp.close()
69
- obj = re.split(" ", entry)
70
- if (obj[0] == "object"):
71
- return obj[1]
72
- return None
59
60
class CellRendererGraph(gtk.GenericCellRenderer):
61
"""Cell renderer for directed graph.
@@ -465,32 +451,24 @@ class GitView:
451
respective sha1 details """
452
453
self.bt_sha1 = { }
454
+ ls_remote = re.compile('^(.{40})\trefs/([^^]+)(?:\\^(..))?$');
455
git_dir = os.getenv("GIT_DIR")
456
if (git_dir == None):
457
git_dir = ".git"
458
472
- #FIXME the path seperator
473
- ref_files = os.listdir(git_dir + "/refs/tags")
474
- for file in ref_files:
475
- fp = open(git_dir + "/refs/tags/"+file)
476
- sha1 = get_sha1_from_tags(string.strip(fp.readline()))
477
- try:
478
- self.bt_sha1[sha1].append(file)
479
- except KeyError:
480
- self.bt_sha1[sha1] = [file]
481
- fp.close()
482
-
483
-
484
- #FIXME the path seperator
485
- ref_files = os.listdir(git_dir + "/refs/heads")
486
- for file in ref_files:
487
- fp = open(git_dir + "/refs/heads/" + file)
488
- sha1 = get_sha1_from_tags(string.strip(fp.readline()))
489
- try:
490
- self.bt_sha1[sha1].append(file)
491
- except KeyError:
492
- self.bt_sha1[sha1] = [file]
493
- fp.close()
459
+ fp = os.popen('git ls-remote ' + git_dir)
460
+ while 1:
461
+ line = string.strip(fp.readline())
462
+ if line == '':
463
+ break
464
+ m = ls_remote.match(line)
465
+ if not m:
466
+ continue
467
+ (sha1, name) = (m.group(1), m.group(2))
468
+ if not self.bt_sha1.has_key(sha1):
469
+ self.bt_sha1[sha1] = []
470
+ self.bt_sha1[sha1].append(name)
471
+ fp.close()
472
473
474
def construct(self):