# HG changeset patch # User Martin Geisler # Date 2010-09-13 11:08:09 # Node ID 00658492e2aa57013c2371c1767af79d7fdb90c9 # Parent 1ed2dc9d4368ed9676e970d300dfb8d822ce1cab patch: break import cycle with cmdutil The patch module imported cmdutil but used it only in updatedir. diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -685,7 +685,7 @@ class queue(object): p1, p2 = repo.dirstate.parents() repo.dirstate.setparents(p1, merge) - files = patch.updatedir(self.ui, repo, files) + files = cmdutil.updatedir(self.ui, repo, files) match = cmdutil.matchfiles(repo, files or []) n = repo.commit(message, ph.user, ph.date, match=match, force=True) @@ -2134,7 +2134,7 @@ def fold(ui, repo, *files, **opts): (patchsuccess, files, fuzz) = q.patch(repo, pf) if not patchsuccess: raise util.Abort(_('error folding patch %s') % p) - patch.updatedir(ui, repo, files) + cmdutil.updatedir(ui, repo, files) if not message: ph = patchheader(q.join(parent), q.plainmode) diff --git a/hgext/record.py b/hgext/record.py --- a/hgext/record.py +++ b/hgext/record.py @@ -497,7 +497,7 @@ def dorecord(ui, repo, commitfunc, *pats pfiles = {} patch.internalpatch(fp, ui, 1, repo.root, files=pfiles, eolmode=None) - patch.updatedir(ui, repo, pfiles) + cmdutil.updatedir(ui, repo, pfiles) except patch.PatchError, err: s = str(err) if s: diff --git a/hgext/transplant.py b/hgext/transplant.py --- a/hgext/transplant.py +++ b/hgext/transplant.py @@ -225,7 +225,7 @@ class transplanter(object): % revlog.hex(node)) return None finally: - files = patch.updatedir(self.ui, repo, files) + files = cmdutil.updatedir(self.ui, repo, files) except Exception, inst: seriespath = os.path.join(self.path, 'series') if os.path.exists(seriespath): diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -329,6 +329,49 @@ def addremove(repo, pats=[], opts={}, dr finally: wlock.release() +def updatedir(ui, repo, patches, similarity=0): + '''Update dirstate after patch application according to metadata''' + if not patches: + return + copies = [] + removes = set() + cfiles = patches.keys() + cwd = repo.getcwd() + if cwd: + cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] + for f in patches: + gp = patches[f] + if not gp: + continue + if gp.op == 'RENAME': + copies.append((gp.oldpath, gp.path)) + removes.add(gp.oldpath) + elif gp.op == 'COPY': + copies.append((gp.oldpath, gp.path)) + elif gp.op == 'DELETE': + removes.add(gp.path) + + wctx = repo[None] + for src, dst in copies: + wctx.copy(src, dst) + if (not similarity) and removes: + wctx.remove(sorted(removes), True) + + for f in patches: + gp = patches[f] + if gp and gp.mode: + islink, isexec = gp.mode + dst = repo.wjoin(gp.path) + # patch won't create empty files + if gp.op == 'ADD' and not os.path.exists(dst): + flags = (isexec and 'x' or '') + (islink and 'l' or '') + repo.wwrite(gp.path, '', flags) + util.set_flags(dst, islink, isexec) + addremove(repo, cfiles, similarity=similarity) + files = patches.keys() + files.extend([r for r in removes if r not in files]) + return sorted(files) + def copy(ui, repo, pats, opts, rename=False): # called with the repo lock held # diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2301,8 +2301,8 @@ def import_(ui, repo, patch1, *patches, patch.patch(tmpname, ui, strip=strip, cwd=repo.root, files=files, eolmode=None) finally: - files = patch.updatedir(ui, repo, files, - similarity=sim / 100.0) + files = cmdutil.updatedir(ui, repo, files, + similarity=sim / 100.0) if not opts.get('no_commit'): if opts.get('exact'): m = None diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -11,7 +11,7 @@ import tempfile, zlib from i18n import _ from node import hex, nullid, short -import base85, cmdutil, mdiff, util, diffhelpers, copies, encoding +import base85, mdiff, util, diffhelpers, copies, encoding gitre = re.compile('diff --git a/(.*) b/(.*)') @@ -444,8 +444,8 @@ class patchfile(object): def writelines(self, fname, lines): # Ensure supplied data ends in fname, being a regular file or - # a symlink. updatedir() will -too magically- take care of - # setting it to the proper type afterwards. + # a symlink. cmdutil.updatedir will -too magically- take care + # of setting it to the proper type afterwards. islink = os.path.islink(fname) if islink: fp = cStringIO.StringIO() @@ -1129,8 +1129,8 @@ def applydiff(ui, fp, changed, strip=1, read in binary mode. Otherwise, line endings are ignored when patching then normalized according to 'eolmode'. - Callers probably want to call 'updatedir' after this to apply - certain categories of changes not done by this function. + Callers probably want to call 'cmdutil.updatedir' after this to + apply certain categories of changes not done by this function. """ return _applydiff( ui, fp, patchfile, copyfile, @@ -1196,49 +1196,6 @@ def _applydiff(ui, fp, patcher, copyfn, return -1 return err -def updatedir(ui, repo, patches, similarity=0): - '''Update dirstate after patch application according to metadata''' - if not patches: - return - copies = [] - removes = set() - cfiles = patches.keys() - cwd = repo.getcwd() - if cwd: - cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] - for f in patches: - gp = patches[f] - if not gp: - continue - if gp.op == 'RENAME': - copies.append((gp.oldpath, gp.path)) - removes.add(gp.oldpath) - elif gp.op == 'COPY': - copies.append((gp.oldpath, gp.path)) - elif gp.op == 'DELETE': - removes.add(gp.path) - - wctx = repo[None] - for src, dst in copies: - wctx.copy(src, dst) - if (not similarity) and removes: - wctx.remove(sorted(removes), True) - - for f in patches: - gp = patches[f] - if gp and gp.mode: - islink, isexec = gp.mode - dst = repo.wjoin(gp.path) - # patch won't create empty files - if gp.op == 'ADD' and not os.path.exists(dst): - flags = (isexec and 'x' or '') + (islink and 'l' or '') - repo.wwrite(gp.path, '', flags) - util.set_flags(dst, islink, isexec) - cmdutil.addremove(repo, cfiles, similarity=similarity) - files = patches.keys() - files.extend([r for r in removes if r not in files]) - return sorted(files) - def externalpatch(patcher, args, patchname, ui, strip, cwd, files): """use to apply to the working directory. returns whether patch was applied with fuzz factor."""