Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 34051:d2fc88426d21
context: add arbitraryfilectx, which can represent files outside the workdir
Move it from contrib/simplemerge so it can be re-used in the future.
Differential Revision: https://phab.mercurial-scm.org/D604
author | Phil Cohen <phillco@fb.com> |
---|---|
date | Fri, 01 Sep 2017 11:52:20 -0700 |
parents | 65ae54582713 |
children | f698bb31bdfb |
comparison
equal
deleted
inserted
replaced
34050:b4226ad98366 | 34051:d2fc88426d21 |
---|---|
2383 modified.append(f) | 2383 modified.append(f) |
2384 else: | 2384 else: |
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) |