forked from cryptodotis/code-peer-review
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svncommit.py
executable file
·57 lines (48 loc) · 2.12 KB
/
svncommit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
import pysvn
import gdiff
from commit import *
class SVNCommit(Commit):
def getDiffsArray(self):
if self.diffIsReallyBig: return []
alldiffs = []
differ = gdiff.diff_match_patch()
client = pysvn.Client()
for f in self.files:
loc = self.repo.url + f
loc = loc.replace("trunk//trunk", "trunk/")
#Try/Catches are easier than seeing if the diff is an addition/deletion
try:
left = client.cat(url_or_path=loc, revision=pysvn.Revision(pysvn.opt_revision_kind.number, int(self.uniqueid)-1))
except:
left = ''
try:
right = client.cat(url_or_path=loc, revision=pysvn.Revision(pysvn.opt_revision_kind.number, int(self.uniqueid)))
except:
right = ''
alldiffs.append(differ.diff_main(left, right))
return alldiffs
def getChangedTextMetadata(self):
return (self.uniqueid, self.repo)
def getChangedTexts(self, metadata):
if self.changedTexts != None:
return self.changedTexts
elif self.changedTexts_data != None:
return self._loadChangedTextFromBackingVar()
elif metadata == None:
raise Exception("NULL passed to getChangedTexts when local changedTexts was not set")
uniqueid, repo = metadata
if int(uniqueid) == 1:
diff = ''
else:
client = pysvn.Client()
diff = client.diff(tmp_path='./', url_or_path=repo.url,
revision1=pysvn.Revision(pysvn.opt_revision_kind.number, int(uniqueid)-1),
revision2=pysvn.Revision(pysvn.opt_revision_kind.number, int(uniqueid)))
diff = svn_diff_header.sub('', diff)
diff = svn_diff_newline.sub('', diff)
diff = svn_diff_property.sub('', diff)
diff = svn_diff_deletions.sub('', diff)
diff = diff.lower()
self.changedTexts = [diff]
return self.changedTexts