3 # USAGE: blame.py [-r REV] repos-path file
10 my_getopt
= getopt
.gnu_getopt
11 except AttributeError:
12 my_getopt
= getopt
.getopt
14 from svn
import fs
, core
, repos
18 def blame(path
, filename
, rev
=None):
21 path
= core
.svn_path_canonicalize(path
)
23 repos_ptr
= repos
.open(path
)
24 fsob
= repos
.fs(repos_ptr
)
27 rev
= fs
.youngest_rev(fsob
)
29 for i
in xrange(0, rev
+1):
30 root
= fs
.revision_root(fsob
, i
)
31 if fs
.check_path(root
, filename
) != core
.svn_node_none
:
34 print "First revision is %d" % first
35 print "Last revision is %d" % rev
36 for i
in xrange(first
, rev
+1):
38 root
= fs
.revision_root(fsob
, i
)
40 if not fs
.contents_changed(root
, filename
, previousroot
, filename
):
43 file = fs
.file_contents(root
, filename
)
44 previousdata
= filedata
47 data
= core
.svn_stream_read(file, CHUNK_SIZE
)
50 filedata
= filedata
+ data
52 print "Current revision is %d" % i
53 diffresult
= difflib
.ndiff(previousdata
.splitlines(1),
54 filedata
.splitlines(1))
55 # print ''.join(diffresult)
59 if annotresult
.has_key (k
):
63 annotresult
[k
] = (i
, j
[2:])
68 annotresult
[k
] = (i
, j
[2:])
71 # print ''.join(diffresult)
73 for x
in xrange(len(annotresult
.keys())):
74 sys
.stdout
.write("Line %d (rev %d):%s" % (x
,
79 print "USAGE: blame.py [-r REV] repos-path file"
83 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'r:')
87 for name
, value
in opts
:
90 blame(args
[0], args
[1], rev
)
92 if __name__
== '__main__':