Show More
@@ -50,16 +50,25 from mercurial.node import short | |||
|
50 | 50 | from mercurial import cmdutil, util, commands |
|
51 | 51 | import os, shlex, shutil, tempfile |
|
52 | 52 | |
|
53 |
def snapshot |
|
|
54 |
'''snapshot files as of some revision |
|
|
53 | def snapshot(ui, repo, files, node, tmproot): | |
|
54 | '''snapshot files as of some revision | |
|
55 | if not using snapshot, -I/-X does not work and recursive diff | |
|
56 | in tools like kdiff3 and meld displays too many files.''' | |
|
55 | 57 | dirname = os.path.basename(repo.root) |
|
56 | 58 | if dirname == "": |
|
57 | 59 | dirname = "root" |
|
60 | if node is not None: | |
|
58 | 61 | dirname = '%s.%s' % (dirname, short(node)) |
|
59 | 62 | base = os.path.join(tmproot, dirname) |
|
60 | 63 | os.mkdir(base) |
|
64 | if node is not None: | |
|
61 | 65 | ui.note(_('making snapshot of %d files from rev %s\n') % |
|
62 | 66 | (len(files), short(node))) |
|
67 | else: | |
|
68 | ui.note(_('making snapshot of %d files from working dir\n') % | |
|
69 | (len(files))) | |
|
70 | ||
|
71 | fns_and_mtime = [] | |
|
63 | 72 | ctx = repo[node] |
|
64 | 73 | for fn in files: |
|
65 | 74 | wfn = util.pconvert(fn) |
@@ -73,42 +82,10 def snapshot_node(ui, repo, files, node, | |||
|
73 | 82 | os.makedirs(destdir) |
|
74 | 83 | data = repo.wwritedata(wfn, ctx[wfn].data()) |
|
75 | 84 | open(dest, 'wb').write(data) |
|
76 | return dirname | |
|
77 | ||
|
78 | ||
|
79 | def snapshot_wdir(ui, repo, files, tmproot): | |
|
80 | '''snapshot files from working directory. | |
|
81 | if not using snapshot, -I/-X does not work and recursive diff | |
|
82 | in tools like kdiff3 and meld displays too many files.''' | |
|
83 | dirname = os.path.basename(repo.root) | |
|
84 | if dirname == "": | |
|
85 | dirname = "root" | |
|
86 | base = os.path.join(tmproot, dirname) | |
|
87 | os.mkdir(base) | |
|
88 | ui.note(_('making snapshot of %d files from working dir\n') % | |
|
89 | (len(files))) | |
|
90 | ||
|
91 | fns_and_mtime = [] | |
|
92 | ||
|
93 | for fn in files: | |
|
94 | wfn = util.pconvert(fn) | |
|
95 | ui.note(' %s\n' % wfn) | |
|
96 | dest = os.path.join(base, wfn) | |
|
97 | destdir = os.path.dirname(dest) | |
|
98 | if not os.path.isdir(destdir): | |
|
99 | os.makedirs(destdir) | |
|
100 | ||
|
101 | fp = open(dest, 'wb') | |
|
102 | for chunk in util.filechunkiter(repo.wopener(wfn)): | |
|
103 | fp.write(chunk) | |
|
104 | fp.close() | |
|
105 | ||
|
85 | if node is None: | |
|
106 | 86 | fns_and_mtime.append((dest, repo.wjoin(fn), os.path.getmtime(dest))) |
|
107 | ||
|
108 | ||
|
109 | 87 | return dirname, fns_and_mtime |
|
110 | 88 | |
|
111 | ||
|
112 | 89 | def dodiff(ui, repo, diffcmd, diffopts, pats, opts): |
|
113 | 90 | '''Do the actuall diff: |
|
114 | 91 | |
@@ -139,24 +116,17 def dodiff(ui, repo, diffcmd, diffopts, | |||
|
139 | 116 | dir2root = '' |
|
140 | 117 | try: |
|
141 | 118 | # Always make a copy of node1 |
|
142 |
dir1 = snapshot |
|
|
119 | dir1 = snapshot(ui, repo, modified + removed, node1, tmproot)[0] | |
|
143 | 120 | changes = len(modified) + len(removed) + len(added) |
|
144 | 121 | |
|
145 | fns_and_mtime = [] | |
|
146 | ||
|
147 | 122 | # If node2 in not the wc or there is >1 change, copy it |
|
148 | if node2: | |
|
149 |
dir2 = snapshot |
|
|
150 | elif changes > 1: | |
|
151 | #we only actually need to get the files to copy back to the working | |
|
152 | #dir in this case (because the other cases are: diffing 2 revisions | |
|
153 | #or single file -- in which case the file is already directly passed | |
|
154 | #to the diff tool). | |
|
155 | dir2, fns_and_mtime = snapshot_wdir(ui, repo, modified + added, tmproot) | |
|
123 | if node2 or changes > 1: | |
|
124 | dir2, fns_and_mtime = snapshot(ui, repo, modified + added, node2, tmproot) | |
|
156 | 125 | else: |
|
157 | 126 | # This lets the diff tool open the changed file directly |
|
158 | 127 | dir2 = '' |
|
159 | 128 | dir2root = repo.root |
|
129 | fns_and_mtime = [] | |
|
160 | 130 | |
|
161 | 131 | # If only one change, diff the files instead of the directories |
|
162 | 132 | if changes == 1 : |
General Comments 0
You need to be logged in to leave comments.
Login now