comparison upmana/mercurial/filemerge.py @ 121:496dbf12a6cb alpha

Traipse Alpha 'OpenRPG' {091030-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta): Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree {091029} Changes made to server to start working with Element Tree. Changes made to Meta Server Lib. Prepping test work for a multi meta network page. Minor bug fixed with mini to gametree Zoom Mouse plugin added. {091030} Getting ready for Beta. Server needs debugging so Alpha remains bugged. Plugin UI code cleaned. Auto start works with a graphic, pop-up asks to enable or disable plugin. Update Manager now has a partially working Status Bar. Status Bar captures terminal text, so Merc out put is visible. Manifest.xml file, will be renamed, is now much cleaner. Debug Console has a clear button and a Report Bug button. Prep work for a Term2Win class in Debug Console. Known: Current Alpha fails in Windows.
author sirebral
date Fri, 30 Oct 2009 22:21:40 -0500
parents
children
comparison
equal deleted inserted replaced
120:d86e762a994f 121:496dbf12a6cb
1 # filemerge.py - file-level merge handling for Mercurial
2 #
3 # Copyright 2006, 2007, 2008 Matt Mackall <mpm@selenic.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2, incorporated herein by reference.
7
8 from node import short
9 from i18n import _
10 import util, simplemerge, match
11 import os, tempfile, re, filecmp
12
13 def _toolstr(ui, tool, part, default=""):
14 return ui.config("merge-tools", tool + "." + part, default)
15
16 def _toolbool(ui, tool, part, default=False):
17 return ui.configbool("merge-tools", tool + "." + part, default)
18
19 _internal = ['internal:' + s
20 for s in 'fail local other merge prompt dump'.split()]
21
22 def _findtool(ui, tool):
23 if tool in _internal:
24 return tool
25 k = _toolstr(ui, tool, "regkey")
26 if k:
27 p = util.lookup_reg(k, _toolstr(ui, tool, "regname"))
28 if p:
29 p = util.find_exe(p + _toolstr(ui, tool, "regappend"))
30 if p:
31 return p
32 return util.find_exe(_toolstr(ui, tool, "executable", tool))
33
34 def _picktool(repo, ui, path, binary, symlink):
35 def check(tool, pat, symlink, binary):
36 tmsg = tool
37 if pat:
38 tmsg += " specified for " + pat
39 if not _findtool(ui, tool):
40 if pat: # explicitly requested tool deserves a warning
41 ui.warn(_("couldn't find merge tool %s\n") % tmsg)
42 else: # configured but non-existing tools are more silent
43 ui.note(_("couldn't find merge tool %s\n") % tmsg)
44 elif symlink and not _toolbool(ui, tool, "symlink"):
45 ui.warn(_("tool %s can't handle symlinks\n") % tmsg)
46 elif binary and not _toolbool(ui, tool, "binary"):
47 ui.warn(_("tool %s can't handle binary\n") % tmsg)
48 elif not util.gui() and _toolbool(ui, tool, "gui"):
49 ui.warn(_("tool %s requires a GUI\n") % tmsg)
50 else:
51 return True
52 return False
53
54 # HGMERGE takes precedence
55 hgmerge = os.environ.get("HGMERGE")
56 if hgmerge:
57 return (hgmerge, hgmerge)
58
59 # then patterns
60 for pat, tool in ui.configitems("merge-patterns"):
61 mf = match.match(repo.root, '', [pat])
62 if mf(path) and check(tool, pat, symlink, False):
63 toolpath = _findtool(ui, tool)
64 return (tool, '"' + toolpath + '"')
65
66 # then merge tools
67 tools = {}
68 for k,v in ui.configitems("merge-tools"):
69 t = k.split('.')[0]
70 if t not in tools:
71 tools[t] = int(_toolstr(ui, t, "priority", "0"))
72 names = tools.keys()
73 tools = sorted([(-p,t) for t,p in tools.items()])
74 uimerge = ui.config("ui", "merge")
75 if uimerge:
76 if uimerge not in names:
77 return (uimerge, uimerge)
78 tools.insert(0, (None, uimerge)) # highest priority
79 tools.append((None, "hgmerge")) # the old default, if found
80 for p,t in tools:
81 if check(t, None, symlink, binary):
82 toolpath = _findtool(ui, t)
83 return (t, '"' + toolpath + '"')
84 # internal merge as last resort
85 return (not (symlink or binary) and "internal:merge" or None, None)
86
87 def _eoltype(data):
88 "Guess the EOL type of a file"
89 if '\0' in data: # binary
90 return None
91 if '\r\n' in data: # Windows
92 return '\r\n'
93 if '\r' in data: # Old Mac
94 return '\r'
95 if '\n' in data: # UNIX
96 return '\n'
97 return None # unknown
98
99 def _matcheol(file, origfile):
100 "Convert EOL markers in a file to match origfile"
101 tostyle = _eoltype(open(origfile, "rb").read())
102 if tostyle:
103 data = open(file, "rb").read()
104 style = _eoltype(data)
105 if style:
106 newdata = data.replace(style, tostyle)
107 if newdata != data:
108 open(file, "wb").write(newdata)
109
110 def filemerge(repo, mynode, orig, fcd, fco, fca):
111 """perform a 3-way merge in the working directory
112
113 mynode = parent node before merge
114 orig = original local filename before merge
115 fco = other file context
116 fca = ancestor file context
117 fcd = local file context for current/destination file
118 """
119
120 def temp(prefix, ctx):
121 pre = "%s~%s." % (os.path.basename(ctx.path()), prefix)
122 (fd, name) = tempfile.mkstemp(prefix=pre)
123 data = repo.wwritedata(ctx.path(), ctx.data())
124 f = os.fdopen(fd, "wb")
125 f.write(data)
126 f.close()
127 return name
128
129 def isbin(ctx):
130 try:
131 return util.binary(ctx.data())
132 except IOError:
133 return False
134
135 if not fco.cmp(fcd.data()): # files identical?
136 return None
137
138 ui = repo.ui
139 fd = fcd.path()
140 binary = isbin(fcd) or isbin(fco) or isbin(fca)
141 symlink = 'l' in fcd.flags() + fco.flags()
142 tool, toolpath = _picktool(repo, ui, fd, binary, symlink)
143 ui.debug(_("picked tool '%s' for %s (binary %s symlink %s)\n") %
144 (tool, fd, binary, symlink))
145
146 if not tool or tool == 'internal:prompt':
147 tool = "internal:local"
148 if ui.prompt(_(" no tool found to merge %s\n"
149 "keep (l)ocal or take (o)ther?") % fd,
150 (_("&Local"), _("&Other")), _("l")) != _("l"):
151 tool = "internal:other"
152 if tool == "internal:local":
153 return 0
154 if tool == "internal:other":
155 repo.wwrite(fd, fco.data(), fco.flags())
156 return 0
157 if tool == "internal:fail":
158 return 1
159
160 # do the actual merge
161 a = repo.wjoin(fd)
162 b = temp("base", fca)
163 c = temp("other", fco)
164 out = ""
165 back = a + ".orig"
166 util.copyfile(a, back)
167
168 if orig != fco.path():
169 ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd))
170 else:
171 ui.status(_("merging %s\n") % fd)
172
173 ui.debug(_("my %s other %s ancestor %s\n") % (fcd, fco, fca))
174
175 # do we attempt to simplemerge first?
176 if _toolbool(ui, tool, "premerge", not (binary or symlink)):
177 r = simplemerge.simplemerge(ui, a, b, c, quiet=True)
178 if not r:
179 ui.debug(_(" premerge successful\n"))
180 os.unlink(back)
181 os.unlink(b)
182 os.unlink(c)
183 return 0
184 util.copyfile(back, a) # restore from backup and try again
185
186 env = dict(HG_FILE=fd,
187 HG_MY_NODE=short(mynode),
188 HG_OTHER_NODE=str(fco.changectx()),
189 HG_MY_ISLINK='l' in fcd.flags(),
190 HG_OTHER_ISLINK='l' in fco.flags(),
191 HG_BASE_ISLINK='l' in fca.flags())
192
193 if tool == "internal:merge":
194 r = simplemerge.simplemerge(ui, a, b, c, label=['local', 'other'])
195 elif tool == 'internal:dump':
196 a = repo.wjoin(fd)
197 util.copyfile(a, a + ".local")
198 repo.wwrite(fd + ".other", fco.data(), fco.flags())
199 repo.wwrite(fd + ".base", fca.data(), fca.flags())
200 return 1 # unresolved
201 else:
202 args = _toolstr(ui, tool, "args", '$local $base $other')
203 if "$output" in args:
204 out, a = a, back # read input from backup, write to original
205 replace = dict(local=a, base=b, other=c, output=out)
206 args = re.sub("\$(local|base|other|output)",
207 lambda x: '"%s"' % replace[x.group()[1:]], args)
208 r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env)
209
210 if not r and _toolbool(ui, tool, "checkconflicts"):
211 if re.match("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data()):
212 r = 1
213
214 if not r and _toolbool(ui, tool, "checkchanged"):
215 if filecmp.cmp(repo.wjoin(fd), back):
216 if ui.prompt(_(" output file %s appears unchanged\n"
217 "was merge successful (yn)?") % fd,
218 (_("&Yes"), _("&No")), _("n")) != _("y"):
219 r = 1
220
221 if _toolbool(ui, tool, "fixeol"):
222 _matcheol(repo.wjoin(fd), back)
223
224 if r:
225 ui.warn(_("merging %s failed!\n") % fd)
226 else:
227 os.unlink(back)
228
229 os.unlink(b)
230 os.unlink(c)
231 return r