##// END OF EJS Templates
context: add arbitraryfilectx, which can represent files outside the workdir...
Phil Cohen -
r34053:d2fc8842 default
parent child Browse files
Show More
@@ -9,6 +9,7 b' hgdemandimport.enable()'
9
9
10 from mercurial.i18n import _
10 from mercurial.i18n import _
11 from mercurial import (
11 from mercurial import (
12 context,
12 error,
13 error,
13 fancyopts,
14 fancyopts,
14 simplemerge,
15 simplemerge,
@@ -49,26 +50,6 b' def showhelp():'
49 for first, second in out_opts:
50 for first, second in out_opts:
50 sys.stdout.write(' %-*s %s\n' % (opts_len, first, second))
51 sys.stdout.write(' %-*s %s\n' % (opts_len, first, second))
51
52
52 class filebackedctx(object):
53 """simplemerge requires context-like objects"""
54 def __init__(self, path):
55 self._path = path
56
57 def decodeddata(self):
58 with open(self._path, "rb") as f:
59 return f.read()
60
61 def flags(self):
62 return ''
63
64 def path(self):
65 return self._path
66
67 def write(self, data, flags):
68 assert not flags
69 with open(self._path, "w") as f:
70 f.write(data)
71
72 try:
53 try:
73 for fp in (sys.stdin, sys.stdout, sys.stderr):
54 for fp in (sys.stdin, sys.stdout, sys.stderr):
74 util.setbinary(fp)
55 util.setbinary(fp)
@@ -85,9 +66,9 b' try:'
85 raise ParseError(_('wrong number of arguments'))
66 raise ParseError(_('wrong number of arguments'))
86 local, base, other = args
67 local, base, other = args
87 sys.exit(simplemerge.simplemerge(uimod.ui.load(),
68 sys.exit(simplemerge.simplemerge(uimod.ui.load(),
88 filebackedctx(local),
69 context.arbitraryfilectx(local),
89 filebackedctx(base),
70 context.arbitraryfilectx(base),
90 filebackedctx(other),
71 context.arbitraryfilectx(other),
91 **opts))
72 **opts))
92 except ParseError as e:
73 except ParseError as e:
93 sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
74 sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
@@ -2385,3 +2385,34 b' class metadataonlyctx(committablectx):'
2385 removed.append(f)
2385 removed.append(f)
2386
2386
2387 return scmutil.status(modified, added, removed, [], [], [], [])
2387 return scmutil.status(modified, added, removed, [], [], [], [])
2388
2389 class arbitraryfilectx(object):
2390 """Allows you to use filectx-like functions on a file in an arbitrary
2391 location on disk, possibly not in the working directory.
2392 """
2393 def __init__(self, path):
2394 self._path = path
2395
2396 def cmp(self, otherfilectx):
2397 return self.data() != otherfilectx.data()
2398
2399 def path(self):
2400 return self._path
2401
2402 def flags(self):
2403 return ''
2404
2405 def data(self):
2406 return util.readfile(self._path)
2407
2408 def decodeddata(self):
2409 with open(self._path, "rb") as f:
2410 return f.read()
2411
2412 def remove(self):
2413 util.unlink(self._path)
2414
2415 def write(self, data, flags):
2416 assert not flags
2417 with open(self._path, "w") as f:
2418 f.write(data)
General Comments 0
You need to be logged in to leave comments. Login now