def download_patch(source, lastrev, patchbranch): from mercurial import hg, ui, localrepo, commands, bundlerepo UI = ui.ui() bundle = tempfile.mktemp(dir="/var/tmp") cwd = os.getcwd() os.chdir(base) try: repo0 = hg.repository(UI,base) repo0.ui.quiet=True repo0.ui.pushbuffer() commands.pull(repo0.ui, repo0, quiet=True) repo0.ui.popbuffer() # discard all pull output # find out what the head revision of the given branch is repo0.ui.pushbuffer() head = repo0.ui.popbuffer().strip() repo0.ui.pushbuffer() if commands.incoming(repo0.ui, repo0, source=source, branch=[patchbranch], bundle=bundle, force=False) != 0: raise ValueError, "Repository contains no changes" rhead = repo0.ui.popbuffer() if rhead: # output is a list of revisions, one per line. last line should be newest revision rhead = rhead.splitlines()[-1].split(':')[1] if rhead == lastrev: raise NotChanged repo=bundlerepo.bundlerepository(UI, ".", bundle) repo.ui.pushbuffer() old = 'max(ancestors(branch("%s"))-outgoing("%s"))' % (patchbranch, base) commands.diff(repo.ui, repo, rev=[old, patchbranch]) result = repo.ui.popbuffer() finally: os.chdir(cwd) if os.path.exists(bundle): os.unlink(bundle) return result, rhead
def get_diff(self): context = self.repo[None] if not context.files() and not context.deleted(): return None diffui = ui.ui() diffui.pushbuffer() commands.diff(diffui, self.repo, git=True) return diffui.popbuffer()
def main(argv=None): if argv is None: argv = sys.argv parser = OptionParser() (options, args) = parser.parse_args() myui = ui.ui() repo = hg.repository(myui, '.') if len(args) == 0: # we should use the current diff, or if that is empty, the top applied # patch in the patch queue myui.pushbuffer() commands.diff(myui, repo, git=True) diff = myui.popbuffer() changedFiles = fileRe.findall(diff) if len(changedFiles) == 0: print("Patch source: top patch in mq queue") myui.pushbuffer() commands.diff(myui, repo, change="qtip", git=True) diff = myui.popbuffer() else: print("Patch source: current diff") else: diff = url.open(myui, args[0]).read() print("Patch source: %s" % args[0]) changedFiles = fileRe.findall(diff) changes = {} for changedFile in changedFiles: changes[changedFile] = [] for revNum in xrange(len(repo) - SEARCH_DEPTH, len(repo)): rev = repo[revNum] for file in changedFiles: if file in rev.files(): changes[file].append(rev) suckers = Counter() supersuckers = Counter() for file in changes: for change in changes[file]: suckers.update(canon(x) for x in suckerRe.findall(change.description())) supersuckers.update(canon(x) for x in supersuckerRe.findall(change.description())) print "Potential reviewers:" for (reviewer, count) in suckers.most_common(10): print " %s: %d" % (reviewer, count) print print "Potential super-reviewers:" for (reviewer, count) in supersuckers.most_common(10): print " %s: %d" % (reviewer, count) print return 0
def success(self): output = '' for repo, root in self.repositories: #commands.pull(thisui, user_repo) self.ui.pushbuffer() commands.diff(self.ui, repo) output += self.ui.popbuffer() css = '<style type="text/css">%s</style>' % HtmlFormatter().get_style_defs('.highlight') return self.workspace return "%s User: %s" % (css, highlight(output, DiffLexer(), HtmlFormatter()))
def copyPatch(parent, ui, repo, files): ui.pushbuffer() try: commands.diff(ui, repo, *files) except Exception, e: ui.popbuffer() if 'THGDEBUG' in os.environ: import traceback traceback.print_exc() return
def changes(self): if not mercurial_module or not self.repo: return None context = self.repo[None] if not context.files() and not context.deleted(): return None diffui = ui.ui() diffui.pushbuffer() commands.diff(diffui, self.repo, git=True) return diffui.popbuffer()
def qshow(ui, repo, patchspec=None, **opts): '''display a patch If no patch is given, the top of the applied stack is shown.''' q = repo.mq patchf = None if patchspec is None: p = q.lookup("qtip") patchf = q.opener(p, "r") else: try: p = q.lookup(patchspec) patchf = q.opener(p, "r") except util.Abort, e: try: patchf = file(patchspec, "r") except Exception, e: # commands.diff has a bad error message if patchspec not in repo: raise util.Abort(_("Unknown patch '%s'") % patchspec) # the built-in export command does not label the diff for color # output, and the patch header generation is not reusable # independently def empty_diff(*args, **kwargs): return [] temp = patch.diff try: patch.diff = empty_diff cmdutil.export(repo, [ patchspec ], fp=ui) finally: patch.diff = temp return commands.diff(ui, repo, change=patchspec, date=None)
def patch_changes(ui, repo, patchfile=None, **opts): '''Given a patch, look at what files it changes, and map a function over the changesets that touch overlapping files. Scan through the last LIMIT commits to find the relevant changesets The patch may be given as a file or a URL. If no patch is specified, the changes in the working directory will be used. If there are no changes, the topmost applied patch in your mq repository will be used. Alternatively, the -f option may be used to pass in one or more files that will be used directly. ''' if opts['file']: changedFiles = fullpaths(ui, repo, opts['file']) elif opts['rev']: revs = scmutil.revrange(repo, opts['rev']) if not revs: raise util.Abort("no changes found") filesInRevs = set() for rev in revs: for f in repo[rev].files(): filesInRevs.add(f) changedFiles = sorted(filesInRevs) else: if patchfile is None: # we should use the current diff, or if that is empty, the top # applied patch in the patch queue ui.pushbuffer() commands.diff(ui, repo, git=True) diff = ui.popbuffer() changedFiles = fileRe.findall(diff) if len(changedFiles) > 0: source = "current diff" elif repo.mq: source = "top patch in mq queue" ui.pushbuffer() try: commands.diff(ui, repo, change="qtip", git=True) except error.RepoLookupError, e: raise util.Abort("no current diff, no mq patch to use") diff = ui.popbuffer() else: raise util.Abort("no changes found") else:
def rhdiff(ui, repo, *pats, **opts): """diff repository (or selected files)""" change = opts.pop('change', None) if change: # add -c option for Mercurial<1.1 base = repo.changectx(change).parents()[0].rev() opts['rev'] = [str(base), change] opts['nodates'] = True return commands.diff(ui, repo, *map(urllib.unquote_plus, pats), **opts)
def get_hg_info(): try: from mercurial import hg, ui, commands from mercurial.error import RepoError except ImportError: print "WARNING: could not get version information. Please install mercurial." return ('unknown', 'unknown', None) try: u = ui.ui() u.pushbuffer() repo = hg.repository(u, os.path.expanduser('../..')) commands.identify(u, repo) my_info = u.popbuffer().strip().split() u.pushbuffer() commands.diff(u, repo) my_diff = u.popbuffer() return (my_info[0], my_info[1], my_diff) except RepoError: print "WARNING: could not get version information." return ('unknown', 'unknown', None)
def download_patch(source, lastrev, patchbranch): from mercurial import hg, ui, localrepo, commands, bundlerepo UI = ui.ui() bundle = tempfile.mktemp(dir="/var/tmp") cwd = os.getcwd() os.chdir(base) try: repo0 = hg.repository(UI, base) repo0.ui.quiet = True repo0.ui.pushbuffer() commands.pull(repo0.ui, repo0, quiet=True) repo0.ui.popbuffer() # discard all pull output # find out what the head revision of the given branch is repo0.ui.pushbuffer() head = repo0.ui.popbuffer().strip() repo0.ui.pushbuffer() if commands.incoming(repo0.ui, repo0, source=source, branch=[patchbranch], bundle=bundle, force=False) != 0: raise ValueError, "Repository contains no changes" rhead = repo0.ui.popbuffer() if rhead: # output is a list of revisions, one per line. last line should be newest revision rhead = rhead.splitlines()[-1].split(':')[1] if rhead == lastrev: raise NotChanged repo = bundlerepo.bundlerepository(UI, ".", bundle) repo.ui.pushbuffer() old = 'max(ancestors(branch("%s"))-outgoing("%s"))' % (patchbranch, base) commands.diff(repo.ui, repo, rev=[old, patchbranch]) result = repo.ui.popbuffer() finally: os.chdir(cwd) if os.path.exists(bundle): os.unlink(bundle) return result, rhead
def qshow(ui, repo, patchspec=None, **opts): '''display a patch If no patch is given, the top of the applied stack is shown.''' patchf = resolve_patchfile(ui, repo, patchspec) if patchf is None: # commands.diff has a bad error message if patchspec is None: patchspec = '.' if patchspec not in repo and not repo.revs(patchspec).first(): raise util.Abort(_("Unknown patch '%s'") % patchspec) # the built-in export command does not label the diff for color # output, and the patch header generation is not reusable # independently def empty_diff(*args, **kwargs): return [] temp = patch.diff try: patch.diff = empty_diff cmdutil.export(repo, repo.revs(patchspec), fp=ui) finally: patch.diff = temp return commands.diff(ui, repo, change=patchspec, date=None, **opts) if opts['stat']: del opts['stat'] lines = patch.diffstatui(patchf, **opts) else: def singlefile(*a, **b): return patchf lines = patch.difflabel(singlefile, **opts) for chunk, label in lines: ui.write(chunk, label=label) patchf.close()
def qshow(ui, repo, patchspec=None, **opts): '''display a patch If no patch is given, the top of the applied stack is shown.''' q = repo.mq patchf = None if patchspec is None: p = q.lookup("qtip") patchf = q.opener(p, "r") else: try: p = q.lookup(patchspec) patchf = q.opener(p, "r") except util.Abort, e: try: patchf = file(patchspec, "r") except Exception, e: # commands.diff has a bad error message if patchspec not in repo: raise util.Abort(_("Unknown patch '%s'") % patchspec) # the built-in export command does not label the diff for color # output, and the patch header generation is not reusable # independently def empty_diff(*args, **kwargs): return [] temp = patch.diff try: patch.diff = empty_diff cmdutil.export(repo, [patchspec], fp=ui) finally: patch.diff = temp return commands.diff(ui, repo, change=patchspec, date=None)
def paste(ui, repo, *fnames, **opts): '''send diffs from Mercurial to various pastebin websites Send a diff of the specified files to a pastebin website to easily share with other people. If no files are specified all files will be included. To paste a diff of all uncommitted changes in the working directory: hg paste To paste the changes that revision REV made: hg paste -r REV To paste the changes between revisions REV1 and REV2: hg paste -r REV1:REV2 Several options can be used to specify more metadata about the paste: hg paste --user Steve --title 'Progress on feature X' --keep The pastebin website to use can be specified with --dest. See 'hg help pastebins' for more information. ''' dest = opts.pop('dest') dry = opts.pop('dry_run') if not dest: dest = 'dpaste' if dest not in pastebins: raise util.Abort('unknown pastebin (see "hg help pastebins")!') if not opts['user']: opts['user'] = ui.username().replace('<', '').replace('>', '') if opts['rev'] and opts['stdin']: raise util.Abort('--rev and --stdin options are mutually exclusive') if opts['stdin']: content = sys.stdin.read() else: ui.pushbuffer() if opts['rev']: rev = opts.pop('rev') revs = cmdutil.revrange(repo, rev) if len(revs) == 1: opts['change'] = revs[0] else: opts['rev'] = rev commands.diff(ui, repo, *fnames, **opts) else: commands.diff(ui, repo, *fnames, **opts) content = ui.popbuffer() if not content.strip(): raise util.Abort('nothing to paste!') if ui.verbose: ui.status('Pasting:\n%s\n' % content) if not dry: url = pastebins[dest]['handler'](content=content, **opts) ui.write('%s\n' % url)
def choose_changes(ui, repo, patchfile, opts): if opts.get('file'): changedFiles = fullpaths(ui, repo, opts['file']) return (changedFiles, 'file', opts['file']) if opts.get('dir'): changedFiles = opts['dir'] # For --debug printout only return (changedFiles, 'dir', opts['dir']) if opts.get('rev'): revs = scmutil.revrange(repo, opts['rev']) if not revs: raise error.Abort("no changes found") filesInRevs = set() for rev in revs: for f in repo[rev].files(): filesInRevs.add(f) changedFiles = sorted(filesInRevs) return (changedFiles, 'rev', opts['rev']) diff = None changedFiles = None if patchfile is not None: source = None if hasattr(patchfile, 'getvalue'): diff = patchfile.getvalue() source = ('patchdata', None) else: try: diff = url.open(ui, patchfile).read() source = ('patch', patchfile) except IOError: if hasattr(repo, 'mq'): q = repo.mq if q: diff = url.open(ui, q.lookup(patchfile)).read() source = ('mqpatch', patchfile) else: # try using: # 1. current diff (if nonempty) # 2. top applied patch in mq patch queue (if mq enabled) # 3. parent of working directory ui.pushbuffer() commands.diff(ui, repo, git=True) diff = ui.popbuffer() changedFiles = fileRe.findall(diff) if len(changedFiles) > 0: source = ('current diff', None) else: changedFiles = None diff = None if hasattr(repo, 'mq') and repo.mq: ui.pushbuffer() try: commands.diff(ui, repo, change="qtip", git=True) except error.RepoLookupError: pass diff = ui.popbuffer() if diff == '': diff = None else: source = ('qtip', None) if diff is None: changedFiles = sorted(repo[b'.'].files()) source = ('rev', '.') if changedFiles is None: changedFiles = fileRe.findall(diff) return (changedFiles, source[0], source[1])
def _nested_diff(ui, repo, *pats, **opts): diffordiffstat = cmdutil.diffordiffstat cmdutil.diffordiffstat = partial(diffordiffstat, prefix=opts.get('prefix') or '') commands.diff(ui, repo, *pats, **opts) cmdutil.diffordiffstat = diffordiffstat
def d(): ui.pushbuffer() commands.diff(ui, repo, **opts) ui.popbuffer()
def diff(self, paths=(), rev=None): commands.diff(self.ui, self.repo, rev=rev, git=True, *self.joined(paths))
def paste(ui, repo, *fnames, **opts): '''send diffs from Mercurial to various pastebin websites Send a diff of the specified files to a pastebin website to easily share with other people. If no files are specified all files will be included. To paste a diff of all uncommitted changes in the working directory: hg paste To paste the changes that revision REV made: hg paste -r REV To paste the changes between revisions REV1 and REV2: hg paste -r REV1:REV2 Several options can be used to specify more metadata about the paste: hg paste --user Steve --title 'Progress on feature X' --keep The pastebin website to use can be specified with --dest. See 'hg help pastebins' for more information. ''' dest = opts.pop('dest') dry = opts.pop('dry_run') if not dest: dest = 'dpaste' handler = globals().get('_paste_' + dest.replace('.', '_')) if not handler: raise util.Abort('unknown pastebin (see "hg help pastebins")!') if not opts['user']: opts['user'] = ui.username().replace('<', '').replace('>', '') if opts['rev'] and opts['stdin']: raise util.Abort('--rev and --stdin options are mutually exclusive') if opts['stdin']: content = sys.stdin.read() else: ui.pushbuffer() if opts['rev']: rev = opts.pop('rev') revs = cmdutil.revrange(repo, rev) if len(revs) == 1: opts['change'] = revs[0] else: opts['rev'] = rev commands.diff(ui, repo, *fnames, **opts) else: commands.diff(ui, repo, *fnames, **opts) content = ui.popbuffer() if not content.strip(): raise util.Abort('nothing to paste!') if ui.verbose: ui.status('Pasting:\n%s\n' % content) if not dry: url = _paste(handler, content, opts) ui.write('%s\n' % url)
def doRun(): """! Run FireSTARR projections for all matching fires based on Settings @return None """ settings = Settings() sys.path.append(Settings.HOME_DIR) os.chdir(Settings.HOME_DIR) ensure_dir(settings.outbase) out_dir = os.path.join(settings.outbase, "output") ensure_dir(out_dir) if settings.clean: do_clean(settings, out_dir) if not settings.dont_make: runMake() try_copy(Settings.BINARY, os.path.join(out_dir, os.path.basename(Settings.BINARY))) shutil.copyfile("settings.ini", os.path.join(out_dir, "settings.ini")) shutil.copyfile("fuel.lut", os.path.join(out_dir, "fuel.lut")) from mercurial import ui, hg, commands u = ui.ui() repo = hg.repository(u, ".") u.pushbuffer() commands.log(u, repo) output = u.popbuffer() write_file(out_dir, "ver.txt", output) u.pushbuffer() commands.diff(u, repo) output = u.popbuffer() write_file(out_dir, "cur.diff", output) # os.chdir(out_dir) # cols = get_fires(settings) # fires = list(cols['FIRENAME']) if not (settings.fire_mask or settings.resume_mask): logging.info("Found {:d} fires in DFOSS".format(len(fires))) elif settings.fire_mask: fires = [fire for fire in fires if str(settings.fire_mask) in fire] if len(fires) > 0: settings.loadPerims() # if no settings.resume_mask then we're good to start found_start = not settings.resume_mask i = 0 to_run = [] scenario_args = [] for a in list(sys.argv): if a in Scenario.POSSIBLE_ARGS: scenario_args.append(a) for index, row in cols.sort_values( ["FIRENAME"], ascending=not settings.reversed).iterrows(): fire = row["FIRENAME"] found_start = found_start or settings.resume_mask in fire if not found_start: if not settings.fire_mask or fire in fires: i += 1 elif fire in fires: logging.info("Checking fire {} {:d} of {:d}".format( fire, i + 1, len(fires))) print(row) # only run if we're not async or the fire mask is the current fire start_day = row["day"] start_time = row["start_time"] # make sure we're not calling this for the day it started if settings.use_perim and settings.for_date != start_day: day = settings.for_time.strftime("%Y-%m-%d") start_time = settings.for_time.strftime("%H:%M") if day == start_day: if row["start_time"] > start_time: start_time = row["start_time"] else: day = start_day lat = row["LATITUDE"] lon = row["LONGITUDE"] if not settings.fire_mask or str(settings.fire_mask) in fire: if not settings.for_date or settings.for_date >= start_day: try: #~ break #~ print(fire, day, lat, lon, start_time, out_dir, int(row["CURRENTSIZE"])) size = None if pd.isnull(row["CURRENTSIZE"]) else int( row["CURRENTSIZE"]) if settings.override_size: size = int(settings.override_size) scenario = write_config(fire, day, lat, lon, start_time, out_dir, size, settings) if settings.fire_mask == fire or settings.sequential: t0 = timeit.default_timer() run(scenario, settings.args) t1 = timeit.default_timer() logging.debug("Took {}s to run fire".format(t1 - t0)) else: run_what = r'python.exe firestarr\firestarr.py "{}" {}'.format( scenario, ' '.join(scenario_args)) to_run.append(run_what) except Exception as e: logging.fatal(e) traceback.print_exc() sys.exit(-1) i += 1 if len(to_run) > 0: from multiprocessing.pool import ThreadPool tp = ThreadPool(Settings.POOL_SIZE) def run_process(run_what): # newlines were in weird places without this print(run_what + "\n", end='') finish_process( start_process(run_what, Settings.PROCESS_FLAGS, Settings.HOME_DIR)) for run_what in to_run: tp.apply_async(run_process, (run_what, )) tp.close() tp.join()