Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

graph: simplify diff() and getparents() and ismerge()

Changeset 1cf89f23fd4d

Parent dc5c85591c28

by Steve Borho

Changes to one file · Browse files at 1cf89f23fd4d Showing diff from parent dc5c85591c28 Diff from another changeset...

 
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
64
65
66
67
68
69
70
71
72
73
74
75
 
 
76
77
78
79
80
81
82
83
84
85
 
86
87
88
 
128
129
130
131
 
132
133
134
135
136
137
 
138
139
140
141
142
143
 
144
145
146
 
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
 
99
100
101
 
102
103
104
105
106
107
 
108
109
110
111
112
113
 
114
115
116
117
@@ -16,73 +16,44 @@
   """helper functions and classes to ease hg revision graph building   -Based on graphlog's algorithm, with insipration stolen to TortoiseHg -revision grapher. +Based on graphlog's algorithm, with insipration stolen from TortoiseHg +revision grapher (now stolen back).  """   -from cStringIO import StringIO  import difflib   -from mercurial.node import nullrev  from mercurial import patch, util, match   -from tortoisehg.util.util import tounicode, isbfile +from tortoisehg.util.util import isbfile +from tortoisehg.util.hglib import tounicode   -import tortoisehg.hgqt # force apply monkeypatches - -def diff(repo, ctx1, ctx2=None, files=None): +def diff(repo, ctx1, ctx2, files):   """   Compute the diff of files between 2 changectx   """   if ctx2 is None: - ctx2 = ctx1.parents()[0] + ctx2 = ctx1.p1()   if files is None:   m = match.always(repo.root, repo.getcwd())   else:   m = match.exact(repo.root, repo.getcwd(), files) - # try/except for the sake of hg compatibility (API changes between - # 1.0 and 1.1) - try: - out = StringIO() - patch.diff(repo, ctx2.node(), ctx1.node(), match=m, fp=out) - diffdata = out.getvalue() - except: - diffdata = '\n'.join(patch.diff(repo, ctx2.node(), ctx1.node(), - match=m)) - # XXX how to deal diff encodings? - try: - diffdata = unicode(diffdata, "utf-8") - except UnicodeError: - # XXX use a default encoding from config? - diffdata = unicode(diffdata, "iso-8859-15", 'ignore') - return diffdata + diffdata = '\n'.join(patch.diff(repo, ctx2.node(), ctx1.node(), match=m)) + return tounicode(diffdata)     -def __get_parents(repo, rev, branch=None): +def getparents(repo, rev, branch):   """   Return non-null parents of `rev`. If branch is given, only return   parents that belongs to names branch `branch` (beware that this is   much slower).   """   if not branch: - if rev is None: - return [x.rev() for x in repo.changectx(None).parents() if x] - return [x for x in repo.changelog.parentrevs(rev) if x != nullrev] - if rev is None: - return [x.rev() for x in repo.changectx(None).parents() \ - if x and repo.changectx(rev).branch() == branch] - return [x for x in repo.changelog.parentrevs(rev) \ - if (x != nullrev and repo.changectx(rev).branch() == branch)] + return [x.rev() for x in repo[rev].parents() if x] + return [x.rev() for x in repo[rev].parents() if x and x.branch() == branch]      def ismerge(ctx): - """ - Return True if the changecontext ctx is a merge mode (should work - with hg 1.0 and 1.2) - """ - if ctx: - return len(ctx.parents()) == 2 and ctx.parents()[1] - return False + return len(ctx.parents()) > 1    def revision_grapher(repo, start_rev=None, stop_rev=0, branch=None, follow=False):   """incremental revision grapher @@ -128,19 +99,19 @@
  revs.append(curr_rev)   rev_color[curr_rev] = curcolor = nextcolor   nextcolor += 1 - p_revs = __get_parents(repo, curr_rev, branch) + p_revs = getparents(repo, curr_rev, branch)   while p_revs:   rev0 = p_revs[0]   if rev0 < stop_rev or rev0 in rev_color:   break   rev_color[rev0] = curcolor - p_revs = __get_parents(repo, rev0, branch) + p_revs = getparents(repo, rev0, branch)   curcolor = rev_color[curr_rev]   rev_index = revs.index(curr_rev)   next_revs = revs[:]     # Add parents to next_revs. - parents = __get_parents(repo, curr_rev, branch) + parents = getparents(repo, curr_rev, branch)   parents_to_add = []   if len(parents) > 1:   preferred_color = None