##// 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 10 from mercurial.i18n import _
11 11 from mercurial import (
12 context,
12 13 error,
13 14 fancyopts,
14 15 simplemerge,
@@ -49,26 +50,6 b' def showhelp():'
49 50 for first, second in out_opts:
50 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 53 try:
73 54 for fp in (sys.stdin, sys.stdout, sys.stderr):
74 55 util.setbinary(fp)
@@ -85,9 +66,9 b' try:'
85 66 raise ParseError(_('wrong number of arguments'))
86 67 local, base, other = args
87 68 sys.exit(simplemerge.simplemerge(uimod.ui.load(),
88 filebackedctx(local),
89 filebackedctx(base),
90 filebackedctx(other),
69 context.arbitraryfilectx(local),
70 context.arbitraryfilectx(base),
71 context.arbitraryfilectx(other),
91 72 **opts))
92 73 except ParseError as e:
93 74 sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
@@ -2385,3 +2385,34 b' class metadataonlyctx(committablectx):'
2385 2385 removed.append(f)
2386 2386
2387 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