def findoutgoing(self, parent): '''Return the base set of outgoing nodes. A caching wrapper around mercurial.localrepo.findoutgoing(). Complains (to the user), if the parent workspace is non-existent or inaccessible''' self.ui.pushbuffer() try: try: ui = self.ui if hasattr(cmdutil, 'remoteui'): ui = cmdutil.remoteui(ui, {}) pws = hg.repository(ui, parent) if Version.at_least("1.6"): return discovery.findoutgoing(self.repo, pws) else: return self.repo.findoutgoing(pws) except error.RepoError: self.ui.warn("Warning: Parent workspace '%s' is not " "accessible\n" "active list will be incomplete\n\n" % parent) return [] finally: self.ui.popbuffer()
def _changed_file(self, path): '''Compare the parent and local versions of a given file. Return True if file changed, False otherwise. Note that this compares the given path in both versions, not the given entry; renamed and copied files are compared by name, not history. The fast path compares file metadata, slow path is a real comparison of file content.''' if ((path in self.parenttip) != (path in self.localtip)): return True parentfile = self.parenttip.filectx(path) localfile = self.localtip.filectx(path) # # NB: Keep these ordered such as to make every attempt # to short-circuit the more time consuming checks. # if parentfile.size() != localfile.size(): return True if parentfile.flags() != localfile.flags(): return True if Version.at_least("1.7"): if parentfile.cmp(localfile): return True else: if parentfile.cmp(localfile.data()): return True
def diff(self, node1=None, node2=None, match=None, opts=None): ret = cStringIO.StringIO() try: for chunk in patch.diff(self.repo, node1, node2, match=match, opts=opts): ret.write(chunk) finally: # Workaround Hg bug 1651 if not Version.at_least("1.3"): self.repo.dirstate.invalidate() return ret.getvalue()
def reposetup(ui, repo): if repo.local() and repo not in wslist: wslist[repo] = WorkSpace(repo) if Version.at_least("1.3"): interactive = ui.interactive() else: interactive = ui.interactive if interactive and sys.stdin.isatty(): ui.setconfig('hooks', 'preoutgoing.cdm_pbconfirm', 'python:hgext_cdm.pbconfirm')
def yes_no(ui, msg, default): if default: prompt = ' [Y/n]:' defanswer = 'y' else: prompt = ' [y/N]:' defanswer = 'n' if Version.at_least("1.4"): index = ui.promptchoice(msg + prompt, ['&yes', '&no'], default=['y', 'n'].index(defanswer)) resp = ('y', 'n')[index] else: resp = ui.prompt(msg + prompt, ['&yes', '&no'], default=defanswer) return resp[0] in ('Y', 'y')
def yes_no(ui, msg, default): if default: prompt = ' [Y/n]:' defanswer = 'y' else: prompt = ' [y/N]:' defanswer = 'n' if Version.at_least("1.3.0"): resp = ui.prompt(msg + prompt, ['&yes', '&no'], default=defanswer) else: resp = ui.prompt(msg + prompt, r'([Yy(es)?|[Nn]o?)?', default=defanswer) return resp[0] in ('Y', 'y')
''' Create a wx-style active list on stdout based on a Mercurial workspace in support of webrev's Mercurial support. ''' # # NB: This assumes the normal onbld directory structure # import sys, os sys.path.insert(1, "%s/../lib/python" % os.path.dirname(__file__)) sys.path.insert(1, "%s/.." % os.path.dirname(__file__)) from onbld.Scm import Version try: Version.check_version() except Version.VersionMismatch, versionerror: sys.stderr.write("Error: %s\n" % versionerror) sys.exit(1) import getopt, binascii from mercurial import hg, ui, util from onbld.Scm.WorkSpace import WorkSpace, HgRepoError def usage(): sys.stderr.write("usage: %s [-p parent] -w workspace\n" % os.path.basename(__file__)) sys.exit(2)
# time.sleep(1) files = {} try: diff = self.bu.backupfile('diff') try: fuzz = patch.patch(diff, self.ws.ui, strip=1, cwd=self.ws.repo.root, files=files) if fuzz: raise util.Abort('working copy diff applied with fuzz') except Exception, e: raise util.Abort("couldn't apply working copy diff: %s\n" " %s" % (diff, e)) finally: if Version.at_least("1.7"): cmdutil.updatedir(self.ws.ui, self.ws.repo, files) else: patch.updatedir(self.ws.ui, self.ws.repo, files) if not self.bu.exists('renames'): return # # We need to re-apply name changes where the new name # (rename/copy destination) is an already versioned file, as # Hg would otherwise ignore them. # try: fp = self.bu.open('renames') for line in fp:
# sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "..", "..", "python%d.%d" % sys.version_info[:2])) # # Add the relative path from cdm.py to usr/src/tools to the load path, # such that a cdm.py loaded from the source tree uses the modules also # within the source tree. # sys.path.insert(2, os.path.join(os.path.dirname(__file__), "..", "..")) from onbld.Scm import Version from mercurial import util try: Version.check_version() except Version.VersionMismatch, badversion: raise util.Abort("Version Mismatch:\n %s\n" % badversion) from mercurial import cmdutil, ignore, node, patch from onbld.Scm.WorkSpace import WorkSpace, WorkList from onbld.Scm.Backup import CdmBackup from onbld.Checks import Cddl, Comments, Copyright, CStyle, HdrChk from onbld.Checks import JStyle, Keywords, Mapfile def yes_no(ui, msg, default): if default: prompt = ' [Y/n]:' defanswer = 'y'
# important bit here (in that if it is incorrect, everything else will # be as incorrect, or more) # import cStringIO import os from mercurial import cmdutil, context, hg, node, patch, repair, util from hgext import mq from onbld.Scm import Version # # Mercurial >= 1.2 has its exception types in a mercurial.error # module, prior versions had them in their associated modules. # if Version.at_least("1.2"): from mercurial import error HgRepoError = error.RepoError HgLookupError = error.LookupError else: from mercurial import repo, revlog HgRepoError = repo.RepoError HgLookupError = revlog.LookupError class ActiveEntry(object): '''Representation of the changes made to a single file. MODIFIED - Contents changed, but no other changes were made ADDED - File is newly created REMOVED - File is being removed
except EnvironmentError, e: raise util.Abort('Could not create backup directory %s: %s' % (self.backupdir, e)) self.generation += 1 self.create_gen(self.generation) try: for x in self.modules: x.backup() except Exception, e: if isinstance(e, KeyboardInterrupt): self.ws.ui.warn("Interrupted\n") else: self.ws.ui.warn("Error: %s\n" % e) if Version.at_least("1.3.0"): show_traceback = self.ws.ui.configbool( 'ui', 'traceback', False) else: show_traceback = self.ws.ui.traceback # # If it's not a 'normal' error, we want to print a stack # trace now in case the attempt to remove the partial # backup also fails, and raises a second exception. # if (not isinstance(e, (EnvironmentError, util.Abort)) or show_traceback): traceback.print_exc() for x in self.modules:
# # NB: This assumes the normal directory structure, with this # extension 2 levels below .../lib/python. # # If you change that, change this # import atexit, os, stat, sys, termios sys.path.insert(1, "%s/../../" % os.path.dirname(__file__)) from onbld.Scm import Version from mercurial import util try: Version.check_version() except Version.VersionMismatch, badversion: raise util.Abort("Version Mismatch:\n %s\n" % badversion) import ConfigParser from mercurial import cmdutil, ignore, node from onbld.Scm.WorkSpace import ActiveEntry, WorkSpace from onbld.Scm.Backup import CdmBackup from onbld.Checks import Cddl, Comments, Copyright, CStyle, HdrChk from onbld.Checks import JStyle, Keywords, Mapfile, Rti, onSWAN def yes_no(ui, msg, default): if default: prompt = ' [Y/n]:'
# present the entire change in workspace state between a parent and # its child and is the important bit here (in that if it is incorrect, # everything else will be as incorrect, or more) # import cStringIO import os from mercurial import cmdutil, context, error, hg, node, patch, repair, util from hgext import mq from onbld.Scm import Version # # Mercurial 1.6 moves findoutgoing into a discover module # if Version.at_least("1.6"): from mercurial import discovery class ActiveEntry(object): '''Representation of the changes made to a single file. MODIFIED - Contents changed, but no other changes were made ADDED - File is newly created REMOVED - File is being removed Copies are represented by an Entry whose .parentname is non-nil Truly copied files have non-nil .parentname and .renamed = False Renames have non-nil .parentname and .renamed = True
# its child and is the important bit here (in that if it is incorrect, # everything else will be as incorrect, or more) # import cStringIO import os from mercurial import cmdutil, context, error, hg, node, patch, repair, util from hgext import mq from onbld.Scm import Version # # Mercurial 1.6 moves findoutgoing into a discover module # if Version.at_least("1.6"): from mercurial import discovery class ActiveEntry(object): '''Representation of the changes made to a single file. MODIFIED - Contents changed, but no other changes were made ADDED - File is newly created REMOVED - File is being removed Copies are represented by an Entry whose .parentname is non-nil Truly copied files have non-nil .parentname and .renamed = False Renames have non-nil .parentname and .renamed = True