comparison mercurial/filemerge.py @ 26979:7b038ec6c5fd

filemerge: introduce class whose objects represent files not in a context Most code is going to barf at the return values here (particularly from data and size), so we restrict it to the filemerge code. This is already somewhat supported via: ctx.filectx(f, fileid=nullid) Indeed, for add/add conflicts (ancestor doesn't have the file) we use precisely that. However, that is broken in subtle ways: - The cmp() function in filectx returns False (identical) for such a filectx when compared to a zero-length file. - size() returns 0 rather than some sort of value indicating that the file isn't present. - data() returns '' rather than some sort of value indicating that the file isn't present. Given the relatively niche use of such filectxes, this seems to be the simplest way to fix all these issues.
author Siddharth Agarwal <sid0@fb.com>
date Mon, 16 Nov 2015 11:45:35 -0800
parents 7a8e9a985c3b
children 28ee7af4b685
comparison
equal deleted inserted replaced
26978:9b9d4bcc915e 26979:7b038ec6c5fd
11 import os 11 import os
12 import re 12 import re
13 import tempfile 13 import tempfile
14 14
15 from .i18n import _ 15 from .i18n import _
16 from .node import short 16 from .node import nullid, short
17 17
18 from . import ( 18 from . import (
19 cmdutil, 19 cmdutil,
20 error, 20 error,
21 match, 21 match,
41 41
42 # internal tool merge types 42 # internal tool merge types
43 nomerge = None 43 nomerge = None
44 mergeonly = 'mergeonly' # just the full merge, no premerge 44 mergeonly = 'mergeonly' # just the full merge, no premerge
45 fullmerge = 'fullmerge' # both premerge and merge 45 fullmerge = 'fullmerge' # both premerge and merge
46
47 class absentfilectx(object):
48 """Represents a file that's ostensibly in a context but is actually not
49 present in it.
50
51 This is here because it's very specific to the filemerge code for now --
52 other code is likely going to break with the values this returns."""
53 def __init__(self, ctx, f):
54 self._ctx = ctx
55 self._f = f
56
57 def path(self):
58 return self._f
59
60 def size(self):
61 return None
62
63 def data(self):
64 return None
65
66 def filenode(self):
67 return nullid
68
69 _customcmp = True
70 def cmp(self, fctx):
71 """compare with other file context
72
73 returns True if different from fctx.
74 """
75 return not (fctx.isabsent() and
76 fctx.ctx() == self.ctx() and
77 fctx.path() == self.path())
78
79 def flags(self):
80 return ''
81
82 def changectx(self):
83 return self._ctx
84
85 def isbinary(self):
86 return False
87
88 def isabsent(self):
89 return True
46 90
47 def internaltool(name, mergetype, onfailure=None, precheck=None): 91 def internaltool(name, mergetype, onfailure=None, precheck=None):
48 '''return a decorator for populating internal merge tool table''' 92 '''return a decorator for populating internal merge tool table'''
49 def decorator(func): 93 def decorator(func):
50 fullname = ':' + name 94 fullname = ':' + name