def applyupdates(repo, action, wctx, mctx): "apply the merge action list to the working directory" updated, merged, removed, unresolved = 0, 0, 0, 0 ms = mergestate(repo) ms.reset(wctx.parents()[0].node()) moves = [] action.sort(actioncmp) # prescan for merges for a in action: f, m = a[:2] if m == 'm': # merge f2, fd, flags, move = a[2:] repo.ui.debug(_("preserving %s for resolve of %s\n") % (f, fd)) fcl = wctx[f] fco = mctx[f2] fca = fcl.ancestor(fco) or repo.filectx(f, fileid=nullrev) ms.add(fcl, fco, fca, fd, flags) if f != fd and move: moves.append(f) # remove renamed files after safely stored for f in moves: if util.lexists(repo.wjoin(f)): repo.ui.debug(_("removing %s\n") % f) os.unlink(repo.wjoin(f)) audit_path = util.path_auditor(repo.root) for a in action: f, m = a[:2] if f and f[0] == "/": continue if m == "r": # remove repo.ui.note(_("removing %s\n") % f) audit_path(f) try: util.unlink(repo.wjoin(f)) except OSError, inst: if inst.errno != errno.ENOENT: repo.ui.warn(_("update failed to remove %s: %s!\n") % (f, inst.strerror)) removed += 1 elif m == "m": # merge f2, fd, flags, move = a[2:] r = ms.resolve(fd, wctx, mctx) if r > 0: unresolved += 1 else: if r is None: updated += 1 else: merged += 1 util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags) if f != fd and move and util.lexists(repo.wjoin(f)): repo.ui.debug(_("removing %s\n") % f) os.unlink(repo.wjoin(f))
def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): if dry_run is None: dry_run = opts.get('dry_run') if similarity is None: similarity = float(opts.get('similarity') or 0) add, remove = [], [] mapping = {} for src, abs, rel, exact in walk(repo, pats, opts): target = repo.wjoin(abs) if src == 'f' and abs not in repo.dirstate: add.append(abs) mapping[abs] = rel, exact if repo.ui.verbose or not exact: repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) if repo.dirstate[abs] != 'r' and (not util.lexists(target) or (os.path.isdir(target) and not os.path.islink(target))): remove.append(abs) mapping[abs] = rel, exact if repo.ui.verbose or not exact: repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) if not dry_run: repo.remove(remove) repo.add(add) if similarity > 0: for old, new, score in findrenames(repo, add, remove, similarity): oldrel, oldexact = mapping[old] newrel, newexact = mapping[new] if repo.ui.verbose or not oldexact or not newexact: repo.ui.status(_('recording removal of %s as rename to %s ' '(%d%% similar)\n') % (oldrel, newrel, score * 100)) if not dry_run: repo.copy(old, new)
def selectfile(afile_orig, bfile_orig, hunk, strip, reverse): def pathstrip(path, count=1): pathlen = len(path) i = 0 if count == 0: return '', path.rstrip() while count > 0: i = path.find('/', i) if i == -1: raise PatchError( _("unable to strip away %d dirs from %s") % (count, path)) i += 1 # consume '//' in the path while i < pathlen - 1 and path[i] == '/': i += 1 count -= 1 return path[:i].lstrip(), path[i:].rstrip() nulla = afile_orig == "/dev/null" nullb = bfile_orig == "/dev/null" abase, afile = pathstrip(afile_orig, strip) gooda = not nulla and util.lexists(afile) bbase, bfile = pathstrip(bfile_orig, strip) if afile == bfile: goodb = gooda else: goodb = not nullb and os.path.exists(bfile) createfunc = hunk.createfile if reverse: createfunc = hunk.rmfile missing = not goodb and not gooda and not createfunc() # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the # diff is between a file and its backup. In this case, the original # file should be patched (see original mpatch code). isbackup = (abase == bbase and bfile.startswith(afile)) fname = None if not missing: if gooda and goodb: fname = isbackup and afile or bfile elif gooda: fname = afile if not fname: if not nullb: fname = isbackup and afile or bfile elif not nulla: fname = afile else: raise PatchError(_("undefined source and destination files")) return fname, missing
def selectfile(afile_orig, bfile_orig, hunk, strip, reverse): def pathstrip(path, count=1): pathlen = len(path) i = 0 if count == 0: return '', path.rstrip() while count > 0: i = path.find('/', i) if i == -1: raise PatchError(_("unable to strip away %d dirs from %s") % (count, path)) i += 1 # consume '//' in the path while i < pathlen - 1 and path[i] == '/': i += 1 count -= 1 return path[:i].lstrip(), path[i:].rstrip() nulla = afile_orig == "/dev/null" nullb = bfile_orig == "/dev/null" abase, afile = pathstrip(afile_orig, strip) gooda = not nulla and util.lexists(afile) bbase, bfile = pathstrip(bfile_orig, strip) if afile == bfile: goodb = gooda else: goodb = not nullb and os.path.exists(bfile) createfunc = hunk.createfile if reverse: createfunc = hunk.rmfile missing = not goodb and not gooda and not createfunc() # If afile is "a/b/foo" and bfile is "a/b/foo.orig" we assume the # diff is between a file and its backup. In this case, the original # file should be patched (see original mpatch code). isbackup = (abase == bbase and bfile.startswith(afile)) fname = None if not missing: if gooda and goodb: fname = isbackup and afile or bfile elif gooda: fname = afile if not fname: if not nullb: fname = isbackup and afile or bfile elif not nulla: fname = afile else: raise PatchError(_("undefined source and destination files")) return fname, missing
def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): if dry_run is None: dry_run = opts.get('dry_run') if similarity is None: similarity = float(opts.get('similarity') or 0) # we'd use status here, except handling of symlinks and ignore is tricky added, unknown, deleted, removed = [], [], [], [] audit_path = util.path_auditor(repo.root) m = match(repo, pats, opts) for abs in repo.walk(m): target = repo.wjoin(abs) good = True try: audit_path(abs) except: good = False rel = m.rel(abs) exact = m.exact(abs) if good and abs not in repo.dirstate: unknown.append(abs) if repo.ui.verbose or not exact: repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) elif repo.dirstate[abs] != 'r' and ( not good or not util.lexists(target) or (os.path.isdir(target) and not os.path.islink(target))): deleted.append(abs) if repo.ui.verbose or not exact: repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) # for finding renames elif repo.dirstate[abs] == 'r': removed.append(abs) elif repo.dirstate[abs] == 'a': added.append(abs) if not dry_run: repo.remove(deleted) repo.add(unknown) if similarity > 0: for old, new, score in findrenames(repo, added + unknown, removed + deleted, similarity): if repo.ui.verbose or not m.exact(old) or not m.exact(new): repo.ui.status( _('recording removal of %s as rename to %s ' '(%d%% similar)\n') % (m.rel(old), m.rel(new), score * 100)) if not dry_run: repo.copy(old, new)
def applyupdates(repo, action, wctx, mctx): "apply the merge action list to the working directory" updated, merged, removed, unresolved = 0, 0, 0, 0 action.sort() # prescan for copy/renames for a in action: f, m = a[:2] if m == 'm': # merge f2, fd, flags, move = a[2:] if f != fd: repo.ui.debug(_("copying %s to %s\n") % (f, fd)) repo.wwrite(fd, repo.wread(f), flags) audit_path = util.path_auditor(repo.root) for a in action: f, m = a[:2] if f and f[0] == "/": continue if m == "r": # remove repo.ui.note(_("removing %s\n") % f) audit_path(f) try: util.unlink(repo.wjoin(f)) except OSError, inst: if inst.errno != errno.ENOENT: repo.ui.warn( _("update failed to remove %s: %s!\n") % (f, inst.strerror)) removed += 1 elif m == "m": # merge f2, fd, flags, move = a[2:] r = filemerge(repo, f, fd, f2, wctx, mctx) if r > 0: unresolved += 1 else: if r is None: updated += 1 else: merged += 1 util.set_exec(repo.wjoin(fd), "x" in flags) if f != fd and move and util.lexists(repo.wjoin(f)): repo.ui.debug(_("removing %s\n") % f) os.unlink(repo.wjoin(f))
def applyupdates(repo, action, wctx, mctx): "apply the merge action list to the working directory" updated, merged, removed, unresolved = 0, 0, 0, 0 action.sort() # prescan for copy/renames for a in action: f, m = a[:2] if m == 'm': # merge f2, fd, flags, move = a[2:] if f != fd: repo.ui.debug(_("copying %s to %s\n") % (f, fd)) repo.wwrite(fd, repo.wread(f), flags) audit_path = util.path_auditor(repo.root) for a in action: f, m = a[:2] if f and f[0] == "/": continue if m == "r": # remove repo.ui.note(_("removing %s\n") % f) audit_path(f) try: util.unlink(repo.wjoin(f)) except OSError, inst: if inst.errno != errno.ENOENT: repo.ui.warn(_("update failed to remove %s: %s!\n") % (f, inst.strerror)) removed += 1 elif m == "m": # merge f2, fd, flags, move = a[2:] r = filemerge.filemerge(repo, f, fd, f2, wctx, mctx) if r > 0: unresolved += 1 else: if r is None: updated += 1 else: merged += 1 util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags) if f != fd and move and util.lexists(repo.wjoin(f)): repo.ui.debug(_("removing %s\n") % f) os.unlink(repo.wjoin(f))
def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): if dry_run is None: dry_run = opts.get('dry_run') if similarity is None: similarity = float(opts.get('similarity') or 0) # we'd use status here, except handling of symlinks and ignore is tricky added, unknown, deleted, removed = [], [], [], [] audit_path = util.path_auditor(repo.root) m = match(repo, pats, opts) for abs in repo.walk(m): target = repo.wjoin(abs) good = True try: audit_path(abs) except: good = False rel = m.rel(abs) exact = m.exact(abs) if good and abs not in repo.dirstate: unknown.append(abs) if repo.ui.verbose or not exact: repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) elif repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) or (os.path.isdir(target) and not os.path.islink(target))): deleted.append(abs) if repo.ui.verbose or not exact: repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) # for finding renames elif repo.dirstate[abs] == 'r': removed.append(abs) elif repo.dirstate[abs] == 'a': added.append(abs) if not dry_run: repo.remove(deleted) repo.add(unknown) if similarity > 0: for old, new, score in findrenames(repo, added + unknown, removed + deleted, similarity): if repo.ui.verbose or not m.exact(old) or not m.exact(new): repo.ui.status(_('recording removal of %s as rename to %s ' '(%d%% similar)\n') % (m.rel(old), m.rel(new), score * 100)) if not dry_run: repo.copy(old, new)
def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): if dry_run is None: dry_run = opts.get('dry_run') if similarity is None: similarity = float(opts.get('similarity') or 0) add, remove = [], [] mapping = {} audit_path = util.path_auditor(repo.root) m = match(repo, pats, opts) for abs in repo.walk(m): target = repo.wjoin(abs) good = True try: audit_path(abs) except: good = False rel = m.rel(abs) exact = m.exact(abs) if good and abs not in repo.dirstate: add.append(abs) mapping[abs] = rel, m.exact(abs) if repo.ui.verbose or not exact: repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) if repo.dirstate[abs] != 'r' and (not good or not util.lexists(target) or (os.path.isdir(target) and not os.path.islink(target))): remove.append(abs) mapping[abs] = rel, exact if repo.ui.verbose or not exact: repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) if not dry_run: repo.remove(remove) repo.add(add) if similarity > 0: for old, new, score in findrenames(repo, add, remove, similarity): oldrel, oldexact = mapping[old] newrel, newexact = mapping[new] if repo.ui.verbose or not oldexact or not newexact: repo.ui.status(_('recording removal of %s as rename to %s ' '(%d%% similar)\n') % (oldrel, newrel, score * 100)) if not dry_run: repo.copy(old, new)
def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None): if dry_run is None: dry_run = opts.get('dry_run') if similarity is None: similarity = float(opts.get('similarity') or 0) add, remove = [], [] mapping = {} audit_path = util.path_auditor(repo.root) for src, abs, rel, exact in walk(repo, pats, opts): target = repo.wjoin(abs) good = True try: audit_path(abs) except: good = False if src == 'f' and good and abs not in repo.dirstate: add.append(abs) mapping[abs] = rel, exact if repo.ui.verbose or not exact: repo.ui.status(_('adding %s\n') % ((pats and rel) or abs)) if repo.dirstate[abs] != 'r' and ( not good or not util.lexists(target) or (os.path.isdir(target) and not os.path.islink(target))): remove.append(abs) mapping[abs] = rel, exact if repo.ui.verbose or not exact: repo.ui.status(_('removing %s\n') % ((pats and rel) or abs)) if not dry_run: repo.remove(remove) repo.add(add) if similarity > 0: for old, new, score in findrenames(repo, add, remove, similarity): oldrel, oldexact = mapping[old] newrel, newexact = mapping[new] if repo.ui.verbose or not oldexact or not newexact: repo.ui.status( _('recording removal of %s as rename to %s ' '(%d%% similar)\n') % (oldrel, newrel, score * 100)) if not dry_run: repo.copy(old, new)
def applyupdates(repo, action, wctx, mctx): "apply the merge action list to the working directory" updated, merged, removed, unresolved = 0, 0, 0, 0 ms = mergestate(repo) ms.reset(wctx.parents()[0].node()) moves = [] action.sort(key=actionkey) substate = wctx.substate # prime # prescan for merges for a in action: f, m = a[:2] if m == 'm': # merge f2, fd, flags, move = a[2:] if f == '.hgsubstate': # merged internally continue repo.ui.debug(_("preserving %s for resolve of %s\n") % (f, fd)) fcl = wctx[f] fco = mctx[f2] fca = fcl.ancestor(fco) or repo.filectx(f, fileid=nullrev) ms.add(fcl, fco, fca, fd, flags) if f != fd and move: moves.append(f) # remove renamed files after safely stored for f in moves: if util.lexists(repo.wjoin(f)): repo.ui.debug(_("removing %s\n") % f) os.unlink(repo.wjoin(f)) audit_path = util.path_auditor(repo.root) for a in action: f, m = a[:2] if f and f[0] == "/": continue if m == "r": # remove repo.ui.note(_("removing %s\n") % f) audit_path(f) if f == '.hgsubstate': # subrepo states need updating subrepo.submerge(repo, wctx, mctx, wctx) try: util.unlink(repo.wjoin(f)) except OSError, inst: if inst.errno != errno.ENOENT: repo.ui.warn( _("update failed to remove %s: %s!\n") % (f, inst.strerror)) removed += 1 elif m == "m": # merge if f == '.hgsubstate': # subrepo states need updating subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx)) continue f2, fd, flags, move = a[2:] r = ms.resolve(fd, wctx, mctx) if r is not None and r > 0: unresolved += 1 else: if r is None: updated += 1 else: merged += 1 util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags) if f != fd and move and util.lexists(repo.wjoin(f)): repo.ui.debug(_("removing %s\n") % f) os.unlink(repo.wjoin(f))
def applyupdates(repo, action, wctx, mctx): "apply the merge action list to the working directory" updated, merged, removed, unresolved = 0, 0, 0, 0 ms = mergestate(repo) ms.reset(wctx.parents()[0].node()) moves = [] action.sort(key=actionkey) substate = wctx.substate # prime # prescan for merges u = repo.ui for a in action: f, m = a[:2] if m == 'm': # merge f2, fd, flags, move = a[2:] if f == '.hgsubstate': # merged internally continue repo.ui.debug("preserving %s for resolve of %s\n" % (f, fd)) fcl = wctx[f] fco = mctx[f2] fca = fcl.ancestor(fco) or repo.filectx(f, fileid=nullrev) ms.add(fcl, fco, fca, fd, flags) if f != fd and move: moves.append(f) # remove renamed files after safely stored for f in moves: if util.lexists(repo.wjoin(f)): repo.ui.debug("removing %s\n" % f) os.unlink(repo.wjoin(f)) audit_path = util.path_auditor(repo.root) numupdates = len(action) for i, a in enumerate(action): f, m = a[:2] u.progress('update', i + 1, item=f, total=numupdates, unit='files') if f and f[0] == "/": continue if m == "r": # remove repo.ui.note(_("removing %s\n") % f) audit_path(f) if f == '.hgsubstate': # subrepo states need updating subrepo.submerge(repo, wctx, mctx, wctx) try: util.unlink(repo.wjoin(f)) except OSError, inst: if inst.errno != errno.ENOENT: repo.ui.warn(_("update failed to remove %s: %s!\n") % (f, inst.strerror)) removed += 1 elif m == "m": # merge if f == '.hgsubstate': # subrepo states need updating subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx)) continue f2, fd, flags, move = a[2:] r = ms.resolve(fd, wctx, mctx) if r is not None and r > 0: unresolved += 1 else: if r is None: updated += 1 else: merged += 1 util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags) if f != fd and move and util.lexists(repo.wjoin(f)): repo.ui.debug("removing %s\n" % f) os.unlink(repo.wjoin(f))