Mercurial > hg > trac > jungle > src > mercurial-plugin
changeset 26:546d3f11ac7a 1.0
Merge trailing whitespace removal from 0.12
author | Christian Boos <cboos@edgewall.org> |
---|---|
date | Thu, 06 Feb 2014 19:56:06 +0100 |
parents | 8df754d9b36a (current diff) 5b6010df7f43 (diff) |
children | 7aaccb9f649a |
files | setup.py tracext/hg/backend.py |
diffstat | 2 files changed, 60 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Wed Oct 17 20:31:01 2012 +0200 +++ b/setup.py Thu Feb 06 19:56:06 2014 +0100 @@ -32,7 +32,7 @@ except ImportError: pass - + TracMercurial = 'http://trac.edgewall.org/wiki/TracMercurial' setup(name='TracMercurial',
--- a/tracext/hg/backend.py Wed Oct 17 20:31:01 2012 +0200 +++ b/tracext/hg/backend.py Thu Feb 06 19:56:06 2014 +0100 @@ -42,7 +42,7 @@ # -- plugin i18n gettext, _, tag_, N_, add_domain = \ - domain_functions('tracmercurial', + domain_functions('tracmercurial', ('gettext', '_', 'tag_', 'N_', 'add_domain')) # -- Using internal Mercurial API, see: @@ -58,7 +58,7 @@ # before loading mercurial modules, and desactivate it afterwards. # # See http://www.selenic.com/mercurial/bts/issue605 - + try: from mercurial import demandimport demandimport.enable(); @@ -76,7 +76,7 @@ from mercurial.extensions import loadall from mercurial.error import RepoLookupError - # Note: due to the nature of demandimport, there will be no actual + # Note: due to the nature of demandimport, there will be no actual # import error until those symbols get accessed, so here we go: for sym in ("filectx ui hex short nullid pathto " "cachefunc loadall".split()): @@ -97,7 +97,7 @@ # Force local encoding to be non-lossy (#7217) os.environ['HGENCODING'] = 'utf-8' encoding.tolocal = str - + if demandimport: demandimport.disable() @@ -132,7 +132,7 @@ given to `check`, which can accept it as valid or not. """ s = u - if isinstance(u, unicode): + if isinstance(u, unicode): for enc in encodings: try: s = u.encode(enc) @@ -154,14 +154,14 @@ if has_bookmarks: return get_bookmarks(ctx) return () - + class trac_ui(ui): # Note: will be dropped in 0.13, see MercurialConnector._setup_ui def __init__(self, *args, **kwargs): ui.__init__(self, *args) self.setconfig('ui', 'interactive', 'off') self.log = kwargs.get('log', args and args[0].log or None) - + def write(self, *args, **opts): for a in args: self.log.info('(mercurial status) %s', a) @@ -173,7 +173,7 @@ def plain(self, *args, **kw): return False # so that '[hg] hgrc' file can specify [ui] options - def interactive(self): + def interactive(self): return False def readline(self): @@ -205,36 +205,36 @@ name[3:] in ('Parents', 'Children', 'Tags', 'Branch', 'Bookmarks', 'source') and mode == 'revprop') and 4 or 0 - + def render_property(self, name, mode, context, props): if name == 'hg-source': repos, value = props[name] return render_source_prop(repos, context, _("Graft:"), value) - return RenderedProperty(name=gettext(name[3:] + ':'), + return RenderedProperty(name=gettext(name[3:] + ':'), name_attributes=[("class", "property")], content=self._render_property(name, mode, context, props)) def _render_property(self, name, mode, context, props): repos, revs = props[name] - + if name in ('hg-Parents', 'hg-Children'): label = repos.display_rev else: label = lambda rev: rev - + def link(rev): chgset = repos.get_changeset(rev) return tag.a(label(rev), class_="changeset", title=shorten_line(chgset.message), href=context.href.changeset(rev, repos.reponame)) - + if name == 'hg-Parents' and len(revs) == 2: # merge new = context.resource.id parent_links = [ (link(rev), ' (', tag.a('diff', title=_("Diff against this parent " "(show the changes merged from the other parents)"), - href=context.href.changeset(new, repos.reponame, + href=context.href.changeset(new, repos.reponame, old=rev)), ')') for rev in revs] return tag([(parent, ', ') for parent in parent_links[:-1]], @@ -243,11 +243,11 @@ "the changes displayed below correspond " "to the merge itself.", merge=tag.strong('merge')), - class_='hint'), tag.br(), - # TODO: only keep chunks present in both parents + class_='hint'), tag.br(), + # TODO: only keep chunks present in both parents # (conflicts) or in none (extra changes) # tag.span('No changes means the merge was clean.', - # class_='hint'), tag.br(), + # class_='hint'), tag.br(), tag.span(tag_("Use the %(diff)s links above to see all " "the changes relative to each parent.", diff=tag.tt('(diff)')), @@ -263,7 +263,7 @@ def match_property(self, name, mode): return name in ('hg-transplant_source', 'hg-convert_revision') and \ mode == 'revprop' and 4 or 0 - + def render_property(self, name, mode, context, props): repos, value = props[name] if name == 'hg-transplant_source': @@ -292,11 +292,11 @@ def match_property(self, name, mode): return name.startswith('hg-') and mode == 'revprop' and 1 or 0 - + def render_property(self, name, mode, context, props): - return RenderedProperty(name=name[3:] + ':', + return RenderedProperty(name=name[3:] + ':', name_attributes=[("class", "property")], - content=self._render_property(name, mode, + content=self._render_property(name, mode, context, props)) def _render_property(self, name, mode, context, props): @@ -356,7 +356,7 @@ self._version = version() # development version assumed to be always the ''newest'' one, # i.e. old development version won't be supported - self._version_info = (999, 0, 0) + self._version_info = (999, 0, 0) m = re.match(r'(\d+)\.(\d+)(?:\.(\d+))?', self._version or '') if m: self._version_info = tuple([int(n or 0) for n in m.groups()]) @@ -366,7 +366,7 @@ # # ui = baseui.copy() # there's no longer a parent/child concept # ui.setconfig('ui', 'interactive', 'off') - # + # self.ui = trac_ui(log=self.log) # (code below adapted from mercurial.dispatch._dispatch) @@ -380,7 +380,7 @@ self.ui.check_trusted = False self.ui.readconfig(hgrc_path) except IOError, e: - self.log.warn("'[hg] hgrc' file (%s) can't be read: %s", + self.log.warn("'[hg] hgrc' file (%s) can't be read: %s", hgrc_path, e) extensions.loadall(self.ui) @@ -401,7 +401,7 @@ yield 'Mercurial', self._version # IRepositoryConnector methods - + def get_supported_types(self): """Support for `repository_type = hg`""" if hg_import_error: @@ -419,7 +419,7 @@ return repos # IWikiSyntaxProvider methods - + def get_wiki_syntax(self): yield (r'!?(?P<hgrev>[0-9a-f]{12,40})(?P<hgpath>/\S+\b)?', lambda formatter, label, match: @@ -475,7 +475,7 @@ ### Version Control API - + class MercurialRepository(Repository): """Repository implementation based on the mercurial API. @@ -534,7 +534,7 @@ fsencoding = [sys.getfilesystemencoding() or 'utf-8'] + encoding str_path = checked_encode(path, fsencoding, os.path.exists) if str_path is None: - raise TracError(_("Repository path '%(path)s' does not exist.", + raise TracError(_("Repository path '%(path)s' does not exist.", path=path)) try: self.repo = hg.repository(ui=self.ui, path=str_path) @@ -635,7 +635,7 @@ else: return '' # branches - for ctx, b in sorted(branches.items(), reverse=True, + for ctx, b in sorted(branches.items(), reverse=True, key=lambda (ctx, b): ctx.rev()): yield ('branches', b + taginfo(ctx), '/', self._display(ctx)) # heads @@ -652,7 +652,7 @@ except (KeyError, RepoLookupError): pass # closed branches - for ctx, b in sorted(closed_branches.items(), reverse=True, + for ctx, b in sorted(closed_branches.items(), reverse=True, key=lambda (ctx, b): ctx.rev()): yield ('closed branches', b + taginfo(ctx), '/', self._display(ctx)) @@ -666,10 +666,10 @@ return url return url + '#' + self.to_u(branch) # URL for cloning that branch - # Note: link to matching location in Mercurial's file browser + # Note: link to matching location in Mercurial's file browser #rev = rev is not None and short(n) or 'tip' #return '/'.join([url, 'file', rev, path]) - + def get_changeset(self, rev): return MercurialChangeset(self, self.changectx(rev)) @@ -681,7 +681,7 @@ FIXME: this can only be handled correctly and efficiently by using the db repository cache. - + The code below is only an heuristic, and doesn't work in the general case. E.g. look at the mercurial repository timeline for 2006-10-18, you need to give ''38'' daysback in order to @@ -714,7 +714,7 @@ seeds.append(p) def get_node(self, path, rev=None): - return MercurialNode(self, self.normalize_path(path), + return MercurialNode(self, self.normalize_path(path), self.changectx(rev)) def get_oldest_rev(self): @@ -722,12 +722,12 @@ def get_youngest_rev(self): return self.changectx().hex() - + def previous_rev(self, rev, path=''): # FIXME: path ignored for now for p in self.changectx(rev).parents(): if p: return p.hex() # always follow first parent - + def next_rev(self, rev, path=''): ctx = self.changectx(rev) if path: # might be a file @@ -742,7 +742,7 @@ # it might be a directory (not supported for now) FIXME for c in ctx.children(): return c.hex() # always follow first child - + def parent_revs(self, rev): return [p.hex() for p in self.changectx(rev).parents()] @@ -756,7 +756,7 @@ def get_changes(self, old_path, old_rev, new_path, new_rev, ignore_ancestry=1): """Generates changes corresponding to generalized diffs. - + Generator that yields change tuples (old_node, new_node, kind, change) for each node change between the two arbitrary (path,rev) pairs. @@ -779,7 +779,7 @@ # Correct change info from changelog(revlog) # Finding changes between two revs requires tracking back # several routes. - + if new_node.isdir: # TODO: Should we follow rename and copy? # As temporary workaround, simply compare entry names. @@ -817,7 +817,7 @@ if old_node.manifest[old_node.str_path] != \ new_node.manifest[new_node.str_path]: yield(old_node, new_node, Node.FILE, Changeset.EDIT) - + class MercurialNode(Node): """A path in the repository, at a given revision. @@ -829,10 +829,10 @@ than for files, except when created as a `subnode()` of an existing MercurialNode. """ - + filectx = dirnode = None - def __init__(self, repos, path, changectx, + def __init__(self, repos, path, changectx, manifest=None, dirctx=None, str_entry=None): """ :param repos: the `MercurialRepository` @@ -860,7 +860,7 @@ str_path = str_entry else: # Fast path: check for existing file - str_path = checked_encode(path, repos.encoding, + str_path = checked_encode(path, repos.encoding, lambda s: s in self.manifest) if str_path is None: # Slow path: this might be a directory node @@ -929,9 +929,9 @@ def _find_dirctx(self, max_rev, str_dirnames, str_entries): """Find most recent modification for each given directory path. - + :param max_rev: find no revision more recent than this one - :param str_dirnames: directory paths to consider + :param str_dirnames: directory paths to consider (list of `str` ending with '/') :param str_entries: maps each directory to the files it contains @@ -949,7 +949,7 @@ changelog and detect the first occurrence of a change in each directory; this is much faster but can still be slow if some folders are only modified in the distant past - + It is possible to combine both approaches, and this can produce excellent results in some cases, for example browsing the root of the Hg mirror of the Linux repository (at revision @@ -1014,8 +1014,8 @@ str_dirnames.remove(str_dir) if not str_dirnames: return str_dirctxs - - + + def subnode(self, str_path, subctx=None): """Return a node with the same revision information but for another path @@ -1033,7 +1033,7 @@ def read(self, size=None): if self.isdir: - return TracError(_("Can't read from directory %(path)s", + return TracError(_("Can't read from directory %(path)s", path=self.path)) if self.data is None: self.data = self.filectx.data() @@ -1047,7 +1047,7 @@ def get_entries(self): if self.isfile: return - + # dirnames are entries which are sub-directories str_entries = {} str_dirnames = [] @@ -1073,7 +1073,7 @@ # pre-computing the changectx for the last change in each sub-directory if str_dirnames: - dirctxs = self._find_dirctx(self.created_rev, str_dirnames, + dirctxs = self._find_dirctx(self.created_rev, str_dirnames, str_entries) else: dirctxs = {} @@ -1133,7 +1133,7 @@ get = cachefunc(changefn) if self.isfile: fncache = {} - chgiter, matchfn = cmdutil.walkchangerevs(self.repos.ui, repo, pats, + chgiter, matchfn = cmdutil.walkchangerevs(self.repos.ui, repo, pats, get, opts) # keep one lookahead entry so that we can detect renames path = self.path @@ -1165,7 +1165,7 @@ for fc, line in self.filectx.annotate(follow=True): annotations.append(fc.rev() or '0') return annotations - + def get_properties(self): if self.isfile and 'x' in self.manifest.flags(self.str_path): return {'exe': '*'} @@ -1196,7 +1196,7 @@ files changes are obtained by comparing the current manifest to the parent manifest(s). """ - + def __init__(self, repos, ctx): self.repos = repos self.ctx = ctx @@ -1219,7 +1219,7 @@ properties = {} parents = self.ctx.parents() if len(parents) > 1: - properties['hg-Parents'] = (self.repos, + properties['hg-Parents'] = (self.repos, [p.hex() for p in parents if p]) children = self.ctx.children() if len(children) > 1: @@ -1229,10 +1229,10 @@ properties['hg-Branch'] = (self.repos, [self.branch]) tags = self.get_tags() if len(tags): - properties['hg-Tags'] = (self.repos, tags) + properties['hg-Tags'] = (self.repos, tags) bookmarks = get_bookmarks(self.ctx) if len(bookmarks): - properties['hg-Bookmarks'] = (self.repos, bookmarks) + properties['hg-Bookmarks'] = (self.repos, bookmarks) for k, v in self.ctx.extra().iteritems(): if k != 'branch': properties['hg-' + k] = (self.repos, v) @@ -1249,7 +1249,7 @@ changes = [] for str_file in self.ctx.files(): # added, edited and deleted files f = u(str_file) - # TODO: find a way to detect conflicts and show how they were + # TODO: find a way to detect conflicts and show how they were # solved (kind of 3-way diff - theirs/mine/merged) edits = [p for p in parents if str_file in p.manifest()] @@ -1272,7 +1272,7 @@ action = Changeset.MOVE else: action = Changeset.COPY - changes.append((f, Node.FILE, action, u(str_base_path), + changes.append((f, Node.FILE, action, u(str_base_path), base_ctx.rev())) # remaining str_deletions are real deletions for str_file, p in str_deletions.items():