Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 8a8e11ca55
Fetching contributors…

Cannot retrieve contributors at this time

executable file 62 lines (44 sloc) 1.523 kB
#!/usr/bin/env python
import sys
import subprocess
class Blob(object):
def __init__(self, blob_id, size):
self.blob_id = blob_id
self.size = size
self.lines = 0
def count_lines(self):
self.lines = 0
if self.size < 2*1024*1024:
args = ['git', 'cat-file', 'blob', self.blob_id]
sub=subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
for l in sub.stdout:
self.lines += 1
def load_blobs(ref):
args = ['git', 'ls-tree', '-z', '-l', '-r', ref]
sub=subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
blobs = sub.stdout.read().split("\0")
rv = []
for b in (b for b in blobs if b):
info, filename = b.split("\t")
mode, t, blob_id, size = info.split()
assert t == 'blob'
rv.append(Blob(blob_id, int(size)))
return rv
def rev_parse(ref):
args = ['git', 'rev-parse', ref]
sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
return sub.stdout.read().strip()
def name(ref):
args = ['git', 'describe', ref]
sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)
return sub.stdout.read().strip()
if __name__ == '__main__':
refs = sys.argv[1:]
if not refs:
refs = ['HEAD']
for ref in refs:
ref = rev_parse(ref)
blobs = load_blobs(ref)
for b in blobs:
b.count_lines()
print "%s %d" % (name(ref), sum(b.lines for b in blobs))
Jump to Line
Something went wrong with that request. Please try again.