filectx: use cmp(self, fctx) instead of cmp(self, text)

This allows more flexibility in implementation, and in particular,
lets the context decide if revision text has to be loaded or not.
This commit is contained in:
Nicolas Dumazet 2010-07-27 23:40:46 +09:00
parent f59b5d9c39
commit 064d677bd7
4 changed files with 12 additions and 12 deletions

View File

@ -352,12 +352,12 @@ class filectx(object):
def size(self):
return self._filelog.size(self._filerev)
def cmp(self, text):
"""compare text with stored file revision
def cmp(self, fctx):
"""compare with other file context
returns True if text is different than what is stored.
returns True if different than fctx.
"""
return self._filelog.cmp(self._filenode, text)
return self._filelog.cmp(self._filenode, fctx.data())
def renamed(self):
"""check if file was actually renamed in this changeset revision
@ -935,12 +935,12 @@ class workingfilectx(filectx):
raise
return (t, tz)
def cmp(self, text):
"""compare text with disk content
def cmp(self, fctx):
"""compare with other file context
returns True if text is different than what is on disk.
returns True if different than fctx.
"""
return self._repo.wread(self._path) != text
return self._repo.wread(self._path) != fctx.data()
class memctx(object):
"""Use memctx to perform in-memory commits via localrepo.commitctx().

View File

@ -135,7 +135,7 @@ def filemerge(repo, mynode, orig, fcd, fco, fca):
except IOError:
return False
if not fco.cmp(fcd.data()): # files identical?
if not fco.cmp(fcd): # files identical?
return None
if fca == fco: # backwards, use working dir parent as ancestor

View File

@ -1062,7 +1062,7 @@ class localrepository(repo.repository):
# do a full compare of any files that might have changed
for f in sorted(cmp):
if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
or ctx1[f].cmp(ctx2[f].data())):
or ctx1[f].cmp(ctx2[f])):
modified.append(f)
else:
fixup.append(f)
@ -1106,7 +1106,7 @@ class localrepository(repo.repository):
if fn in mf1:
if (mf1.flags(fn) != mf2.flags(fn) or
(mf1[fn] != mf2[fn] and
(mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))):
(mf2[fn] or ctx1[fn].cmp(ctx2[fn])))):
modified.append(fn)
elif listclean:
clean.append(fn)

View File

@ -73,7 +73,7 @@ class mergestate(object):
def _checkunknown(wctx, mctx):
"check for collisions between unknown files and files in mctx"
for f in wctx.unknown():
if f in mctx and mctx[f].cmp(wctx[f].data()):
if f in mctx and mctx[f].cmp(wctx[f]):
raise util.Abort(_("untracked file in working directory differs"
" from file in requested revision: '%s'") % f)