# HG changeset patch # User Martin Geisler # Date 2009-04-21 22:55:32 # Node ID bbc24c0753a043a5ee748a535b3b186acea8f6a9 # Parent ddbee2d0d634b67d7f6ebea405398c171bbf3a8a util: use built-in set and frozenset This drops Python 2.3 compatibility. diff --git a/hgext/convert/filemap.py b/hgext/convert/filemap.py --- a/hgext/convert/filemap.py +++ b/hgext/convert/filemap.py @@ -148,7 +148,7 @@ class filemap_source(converter_source): # wanted by previous runs. self._rebuilt = not revmap seen = {SKIPREV: SKIPREV} - dummyset = util.set() + dummyset = set() converted = [] for rev in revmap.order: mapped = revmap[rev] @@ -237,7 +237,7 @@ class filemap_source(converter_source): # map to any revision in the restricted graph. Put SKIPREV # in the set of wanted ancestors to simplify code elsewhere self.parentmap[rev] = SKIPREV - self.wantedancestors[rev] = util.set((SKIPREV,)) + self.wantedancestors[rev] = set((SKIPREV,)) return # Reuse the data from our parent. @@ -254,7 +254,7 @@ class filemap_source(converter_source): # The set of wanted ancestors of rev is the union of the sets # of wanted ancestors of its parents. Plus rev itself. - wrev = util.set() + wrev = set() for p in parents: wrev.update(self.wantedancestors[p]) wrev.add(rev) diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py --- a/hgext/convert/subversion.py +++ b/hgext/convert/subversion.py @@ -564,7 +564,7 @@ class svn_source(converter_source): out, e.g. 'I copied trunk into a subdirectory of itself instead of making a branch'. The converted repository is significantly smaller if we ignore such revisions.""" - self.blacklist = util.set() + self.blacklist = set() blacklist = self.blacklist for line in file("blacklist.txt", "r"): if not line.startswith("#"): @@ -1099,7 +1099,7 @@ class svn_sink(converter_sink, commandli os.rename(tempname, wdest) def dirs_of(self, files): - dirs = util.set() + dirs = set() for f in files: if os.path.isdir(self.wjoin(f)): dirs.add(f) @@ -1155,8 +1155,8 @@ class svn_sink(converter_sink, commandli return self.revid(self.childmap[parent]) except KeyError: pass - entries = util.set(self.delete) - files = util.frozenset(files) + entries = set(self.delete) + files = frozenset(files) entries.update(self.add_dirs(files.difference(entries))) if self.copies: for s, d in self.copies: diff --git a/hgext/graphlog.py b/hgext/graphlog.py --- a/hgext/graphlog.py +++ b/hgext/graphlog.py @@ -286,7 +286,7 @@ def graphlog(ui, repo, path=None, **opts def graphrevs(repo, nodes, opts): nodes.reverse() - include = util.set(nodes) + include = set(nodes) limit = cmdutil.loglimit(opts) count = 0 for node in nodes: diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -128,8 +128,8 @@ def rebase(ui, repo, **opts): if not keepf: # Remove no more useful revisions - if (util.set(repo.changelog.descendants(min(state))) - - util.set(state.keys())): + if (set(repo.changelog.descendants(min(state))) + - set(state.keys())): ui.warn(_("warning: new changesets detected on source branch, " "not stripping\n")) else: @@ -353,7 +353,7 @@ def restorestatus(repo): def abort(repo, originalwd, target, state): 'Restore the repository to its original state' - if util.set(repo.changelog.descendants(target)) - util.set(state.values()): + if set(repo.changelog.descendants(target)) - set(state.values()): repo.ui.warn(_("warning: new changesets detected on target branch, " "not stripping\n")) else: @@ -368,7 +368,7 @@ def abort(repo, originalwd, target, stat def buildstate(repo, dest, src, base, collapse): 'Define which revisions are going to be rebased and where' - targetancestors = util.set() + targetancestors = set() if not dest: # Destination defaults to the latest revision in the current branch @@ -397,12 +397,12 @@ def buildstate(repo, dest, src, base, co repo.ui.debug(_('already working on current\n')) return None - targetancestors = util.set(repo.changelog.ancestors(dest)) + targetancestors = set(repo.changelog.ancestors(dest)) if cwd in targetancestors: repo.ui.debug(_('already working on the current branch\n')) return None - cwdancestors = util.set(repo.changelog.ancestors(cwd)) + cwdancestors = set(repo.changelog.ancestors(cwd)) cwdancestors.add(cwd) rebasingbranch = cwdancestors - targetancestors source = min(rebasingbranch) @@ -412,7 +412,7 @@ def buildstate(repo, dest, src, base, co external = nullrev if collapse: if not targetancestors: - targetancestors = util.set(repo.changelog.ancestors(dest)) + targetancestors = set(repo.changelog.ancestors(dest)) for rev in state: # Check externals and fail if there are more than one for p in repo[rev].parents(): diff --git a/hgext/win32text.py b/hgext/win32text.py --- a/hgext/win32text.py +++ b/hgext/win32text.py @@ -99,7 +99,7 @@ def macencode(s, cmd): def forbidnewline(ui, repo, hooktype, node, newline, **kwargs): halt = False - seen = util.set() + seen = set() # we try to walk changesets in reverse order from newest to # oldest, so that if we see a file multiple times, we take the # newest version as canonical. this prevents us from blocking a diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1306,7 +1306,7 @@ def heads(ui, repo, *branchrevs, **opts) heads = repo.heads(start, closed=closed) else: heads = [] - visitedset = util.set() + visitedset = set() for branchrev in branchrevs: branch = repo[branchrev].branch() if branch in visitedset: diff --git a/mercurial/httprepo.py b/mercurial/httprepo.py --- a/mercurial/httprepo.py +++ b/mercurial/httprepo.py @@ -52,9 +52,9 @@ class httprepository(repo.repository): def get_caps(self): if self.caps is None: try: - self.caps = util.set(self.do_read('capabilities').split()) + self.caps = set(self.do_read('capabilities').split()) except error.RepoError: - self.caps = util.set() + self.caps = set() self.ui.debug(_('capabilities: %s\n') % (' '.join(self.caps or ['none']))) return self.caps diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -17,7 +17,7 @@ import merge as merge_ from lock import release class localrepository(repo.repository): - capabilities = util.set(('lookup', 'changegroupsubset')) + capabilities = set(('lookup', 'changegroupsubset')) supported = ('revlogv1', 'store', 'fncache') def __init__(self, parentui, path=None, create=0): diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -576,7 +576,7 @@ class revlog(object): def ancestors(self, *revs): 'Generate the ancestors of revs using a breadth-first visit' visit = list(revs) - seen = util.set([nullrev]) + seen = set([nullrev]) while visit: for parent in self.parentrevs(visit.pop(0)): if parent not in seen: @@ -586,7 +586,7 @@ class revlog(object): def descendants(self, *revs): 'Generate the descendants of revs in topological order' - seen = util.set(revs) + seen = set(revs) for i in xrange(min(revs) + 1, len(self)): for x in self.parentrevs(i): if x != nullrev and x in seen: diff --git a/mercurial/sshrepo.py b/mercurial/sshrepo.py --- a/mercurial/sshrepo.py +++ b/mercurial/sshrepo.py @@ -80,7 +80,7 @@ class sshrepository(repo.repository): else: self.abort(error.RepoError(_("no suitable response from remote hg"))) - self.capabilities = util.set() + self.capabilities = set() lines.reverse() for l in lines: if l.startswith("capabilities:"): diff --git a/mercurial/url.py b/mercurial/url.py --- a/mercurial/url.py +++ b/mercurial/url.py @@ -84,8 +84,8 @@ def quotepath(path): ''' global _safeset, _hex if _safeset is None: - _safeset = util.set(_safe) - _hex = util.set('abcdefABCDEF0123456789') + _safeset = set(_safe) + _hex = set('abcdefABCDEF0123456789') l = list(path) for i in xrange(len(l)): c = l[i] diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -19,12 +19,6 @@ import imp # Python compatibility -try: - set = set - frozenset = frozenset -except NameError: - from sets import Set as set, ImmutableSet as frozenset - _md5 = None def md5(s): global _md5 diff --git a/tests/test-walkrepo.py b/tests/test-walkrepo.py --- a/tests/test-walkrepo.py +++ b/tests/test-walkrepo.py @@ -1,7 +1,7 @@ import os import os.path from mercurial import hg, ui -from mercurial.util import walkrepos, set, frozenset +from mercurial.util import walkrepos from os import mkdir, chdir from os.path import join as pjoin