-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgitcommit.py
executable file
·63 lines (51 loc) · 2.38 KB
/
gitcommit.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
58
59
60
61
62
63
#!/usr/bin/python
import git as pygit
import gdiff
from config import *
from commit import *
class GitCommit(Commit):
def getDiffsArray(self):
if self.diffIsReallyBig: return []
alldiffs = []
differ = gdiff.diff_match_patch()
commit = self.getChangedTextMetadata()
for d in commit.diff(commit.__str__()+'^').iter_change_type('M'): #Changed
left = d.a_blob.data_stream.read()
right = d.b_blob.data_stream.read()
alldiffs.append(differ.diff_main(left, right))
for d in commit.diff(commit.__str__()+'^').iter_change_type('A'): #Added
addition = d.b_blob.data_stream.read()
alldiffs.append(differ.diff_main('', addition))
return alldiffs
def getChangedTextMetadata(self):
localfolder = urlToFolder(self.repo.url)
repoloc = Config.fsdir + 'git-repos/' + localfolder + '/'
repo = pygit.Repo(repoloc)
commit = repo.commit(self.uniqueid)
return commit
def getChangedTexts(self, commitobj):
if self.changedTexts != None:
return self.changedTexts
elif self.changedTexts_data != None:
return self._loadChangedTextFromBackingVar()
elif commitobj == None:
raise Exception("NULL passed to getChangedTexts when local changedTexts was not set")
alldiffs = []
differ = gdiff.diff_match_patch()
for d in commitobj.diff(commitobj.__str__()+'^').iter_change_type('M'): #Changed
left = d.a_blob.data_stream.read()
right = d.b_blob.data_stream.read()
diffs = differ.diff_main(left, right)
if diffs: differ.diff_cleanupSemantic(diffs)
for d in diffs:
if d[0] != 0 and d[1].strip():
alldiffs.append(d[1].lower())
for d in commitobj.diff(commitobj.__str__()+'^').iter_change_type('A'): #Added
addition = d.b_blob.data_stream.read()
alldiffs.append(addition.lower())
#for d in commitobj.diff(commitobj.__str__()+'^').iter_change_type('D'): #Deleted
# pass
#for d in commitobj.diff(commitobj.__str__()+'^').iter_change_type('R'): #Renamed
# pass
self.changedTexts = alldiffs
return self.changedTexts