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 updatedir(ui, repo, patches): '''Update dirstate after patch application according to metadata''' if not patches: return copies = [] removes = {} cfiles = patches.keys() cwd = repo.getcwd() if cwd: cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()] for f in patches: ctype, gp = patches[f] if ctype == 'RENAME': copies.append((gp.oldpath, gp.path)) removes[gp.oldpath] = 1 elif ctype == 'COPY': copies.append((gp.oldpath, gp.path)) elif ctype == 'DELETE': removes[gp.path] = 1 for src, dst in copies: repo.copy(src, dst) removes = removes.keys() if removes: removes.sort() repo.remove(removes, True) for f in patches: ctype, gp = patches[f] if gp and gp.mode: flags = '' if gp.mode & 0100: flags = 'x' elif gp.mode & 020000: flags = 'l' dst = os.path.join(repo.root, gp.path) # patch won't create empty files if ctype == 'ADD' and not os.path.exists(dst): repo.wwrite(gp.path, '', flags) else: util.set_flags(dst, 'l' in flags, 'x' in flags) cmdutil.addremove(repo, cfiles) files = patches.keys() files.extend([r for r in removes if r not in files]) files.sort() return files
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 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 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: dirstatecopy(ui, repo, wctx, src, dst, cwd=cwd) 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.lexists(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 updatedir(ui, repo, patches, similarity=0): """Update dirstate after patch application according to metadata""" if not patches: return copies = [] removes = {} 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[gp.oldpath] = 1 elif gp.op == "COPY": copies.append((gp.oldpath, gp.path)) elif gp.op == "DELETE": removes[gp.path] = 1 for src, dst in copies: repo.copy(src, dst) removes = removes.keys() if (not similarity) and removes: repo.remove(util.sort(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) elif gp.op != "DELETE": 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 util.sort(files)
t = wctx.filectx(f).data() repo.wwrite(fd, t, flags) util.unlink(repo.wjoin(f)) if f2: repo.ui.note(_("getting %s to %s\n") % (f2, fd)) t = mctx.filectx(f2).data() repo.wwrite(fd, t, flags) updated += 1 elif m == "dr": # divergent renames fl = a[2] repo.ui.warn("warning: detected divergent renames of %s to:\n" % f) for nf in fl: repo.ui.warn(" %s\n" % nf) elif m == "e": # exec flags = a[2] util.set_flags(repo.wjoin(f), 'l' in flags, 'x' in flags) return updated, merged, removed, unresolved def recordupdates(repo, action, branchmerge): "record merge actions to the dirstate" for a in action: f, m = a[:2] if m == "r": # remove if branchmerge: repo.dirstate.remove(f) else: repo.dirstate.forget(f) elif m == "f": # forget repo.dirstate.forget(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 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))
repo.wwrite(fd, t, flags) util.unlink(repo.wjoin(f)) if f2: repo.ui.note(_("getting %s to %s\n") % (f2, fd)) t = mctx.filectx(f2).data() repo.wwrite(fd, t, flags) updated += 1 elif m == "dr": # divergent renames fl = a[2] repo.ui.warn( _("warning: detected divergent renames of %s to:\n") % f) for nf in fl: repo.ui.warn(" %s\n" % nf) elif m == "e": # exec flags = a[2] util.set_flags(repo.wjoin(f), 'l' in flags, 'x' in flags) return updated, merged, removed, unresolved def recordupdates(repo, action, branchmerge): "record merge actions to the dirstate" for a in action: f, m = a[:2] if m == "r": # remove if branchmerge: repo.dirstate.remove(f) else: repo.dirstate.forget(f) elif m == "a": # re-add
def applyupdates(repo, action, wctx, mctx, actx, overwrite): """apply the merge action list to the working directory wctx is the working copy context mctx is the context to be merged into the working copy actx is the context of the common ancestor """ 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] if mctx == actx: # backwards, use working dir parent as ancestor if fcl.parents(): fca = fcl.parents()[0] else: fca = repo.filectx(f, fileid=nullrev) else: fca = fcl.ancestor(fco, actx) if not fca: fca = 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 os.path.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(_('updating'), 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, overwrite) 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), overwrite) 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 os.path.lexists(repo.wjoin(f)): repo.ui.debug("removing %s\n" % f) os.unlink(repo.wjoin(f))
def applyupdates(repo, action, wctx, mctx, actx, overwrite): """apply the merge action list to the working directory wctx is the working copy context mctx is the context to be merged into the working copy actx is the context of the common ancestor """ 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] if mctx == actx: # backwards, use working dir parent as ancestor if fcl.parents(): fca = fcl.parents()[0] else: fca = repo.filectx(f, fileid=nullrev) else: fca = fcl.ancestor(fco, actx) if not fca: fca = 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 os.path.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(_('updating'), 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, overwrite) 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), overwrite) 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 os.path.lexists(repo.wjoin(f)): repo.ui.debug("removing %s\n" % f) os.unlink(repo.wjoin(f))
) parser.add_argument("--version", help="Show the version and exit.", action="store_true") ### Parse and validate args = parser.parse_args() if args.version: print(__VERSION__) sys.exit(0) if args.pattern and not args.lang: parser.error("-e/--pattern and -l/--lang must both be specified") # set the flags util.set_flags(args.verbose, args.quiet) # change cwd if using docker config_resolver.adjust_for_docker(args.precommit) try: if args.test: test.test_main(args) else: sgrep_main.main(args) except NotImplementedError as ex: print_error_exit( f"sgrep encountered an error: {ex}; this is not your fault. {PLEASE_FILE_ISSUE_TEXT}" )
t = wctx.filectx(f).data() repo.wwrite(fd, t, flags) util.unlink(repo.wjoin(f)) if f2: repo.ui.note(_("getting %s to %s\n") % (f2, fd)) t = mctx.filectx(f2).data() repo.wwrite(fd, t, flags) updated += 1 elif m == "dr": # divergent renames fl = a[2] repo.ui.warn("warning: detected divergent renames of %s to:\n" % f) for nf in fl: repo.ui.warn(" %s\n" % nf) elif m == "e": # exec flags = a[2] util.set_flags(repo.wjoin(f), flags) return updated, merged, removed, unresolved def recordupdates(repo, action, branchmerge): "record merge actions to the dirstate" for a in action: f, m = a[:2] if m == "r": # remove if branchmerge: repo.dirstate.remove(f) else: repo.dirstate.forget(f) elif m == "f": # forget repo.dirstate.forget(f)
fl.DEFINE_integer('save_max', 10000, '') fl.DEFINE_integer('epochs', 10000, '') fl.DEFINE_integer('steps', 10000, '') fl.DEFINE_string('gpu_no', "0", '') fl.DEFINE_boolean('random_shuffling', True, '') fl.DEFINE_boolean('use_train_phase', True, '') fl.DEFINE_boolean('use_val_phase', False, '') fl.DEFINE_boolean('use_test_phase', True, '') F = fl.FLAGS def runner(): p = Process(target=trainer.main, args=(F,)) p.start() if not F.parallel_exec: p.join() if __name__ == '__main__': assert F.config is not None assert os.path.isfile(F.config) configs = json.load(open(F.config)) if len(configs) < 1: runner() else: for config in configs: bak_conf = util.set_flags(config) runner() util.restore_flags(bak_conf)