merge with crew-stable
authorMartin Geisler <mg@lazybytes.net>
Tue, 07 Jul 2009 14:20:58 +0200
changeset 9045 500013d3b6a9
parent 9042 95046688f80f (diff)
parent 9044 d4d4da54ab05 (current diff)
child 9046 1547126630e9
merge with crew-stable
--- a/hgext/churn.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/churn.py	Tue Jul 07 14:20:58 2009 +0200
@@ -143,8 +143,8 @@
     if not rate:
         return
 
-    sortfn = ((not opts.get('sort')) and (lambda a, b: cmp(b[1], a[1])) or None)
-    rate.sort(sortfn)
+    sortkey = ((not opts.get('sort')) and (lambda x: -x[1]) or None)
+    rate.sort(key=sortkey)
 
     maxcount = float(max([v for k, v in rate]))
     maxname = max([len(k) for k, v in rate])
--- a/hgext/color.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/color.py	Tue Jul 07 14:20:58 2009 +0200
@@ -146,9 +146,9 @@
     for patch in patches:
         patchname = patch
         if opts['summary']:
-            patchname = patchname.split(': ')[0]
+            patchname = patchname.split(': ', 1)[0]
         if ui.verbose:
-            patchname = patchname.split(' ', 2)[-1]
+            patchname = patchname.lstrip().split(' ', 2)[-1]
 
         if opts['missing']:
             effects = _patch_effects['missing']
@@ -158,7 +158,9 @@
             effects = _patch_effects['applied']
         else:
             effects = _patch_effects['unapplied']
-        ui.write(render_effects(patch, effects) + '\n')
+
+        patch = patch.replace(patchname, render_effects(patchname, effects), 1)
+        ui.write(patch + '\n')
     return retval
 
 _patch_effects = { 'applied': ['blue', 'bold', 'underline'],
--- a/hgext/convert/cvs.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/convert/cvs.py	Tue Jul 07 14:20:58 2009 +0200
@@ -38,8 +38,8 @@
         self.lastbranch = {}
         self.parent = {}
         self.socket = None
-        self.cvsroot = file(os.path.join(cvs, "Root")).read()[:-1]
-        self.cvsrepo = file(os.path.join(cvs, "Repository")).read()[:-1]
+        self.cvsroot = open(os.path.join(cvs, "Root")).read()[:-1]
+        self.cvsrepo = open(os.path.join(cvs, "Repository")).read()[:-1]
         self.encoding = locale.getpreferredencoding()
 
         self._connect()
--- a/hgext/convert/cvsps.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/convert/cvsps.py	Tue Jul 07 14:20:58 2009 +0200
@@ -12,13 +12,6 @@
 from mercurial import util
 from mercurial.i18n import _
 
-def listsort(list, key):
-    "helper to sort by key in Python 2.3"
-    try:
-        list.sort(key=key)
-    except TypeError:
-        list.sort(lambda l, r: cmp(key(l), key(r)))
-
 class logentry(object):
     '''Class logentry has the following attributes:
         .author    - author name as CVS knows it
@@ -130,7 +123,7 @@
 
         # Get the real directory in the repository
         try:
-            prefix = file(os.path.join('CVS','Repository')).read().strip()
+            prefix = open(os.path.join('CVS','Repository')).read().strip()
             if prefix == ".":
                 prefix = ""
             directory = prefix
@@ -142,7 +135,7 @@
 
         # Use the Root file in the sandbox, if it exists
         try:
-            root = file(os.path.join('CVS','Root')).read().strip()
+            root = open(os.path.join('CVS','Root')).read().strip()
         except IOError:
             pass
 
@@ -175,7 +168,7 @@
     if cache == 'update':
         try:
             ui.note(_('reading cvs log cache %s\n') % cachefile)
-            oldlog = pickle.load(file(cachefile))
+            oldlog = pickle.load(open(cachefile))
             ui.note(_('cache has %d log entries\n') % len(oldlog))
         except Exception, e:
             ui.note(_('error reading cache: %r\n') % e)
@@ -419,7 +412,7 @@
             if len(log) % 100 == 0:
                 ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n')
 
-    listsort(log, key=lambda x:(x.rcs, x.revision))
+    log.sort(key=lambda x: (x.rcs, x.revision))
 
     # find parent revisions of individual files
     versions = {}
@@ -435,7 +428,7 @@
     if cache:
         if log:
             # join up the old and new logs
-            listsort(log, key=lambda x:x.date)
+            log.sort(key=lambda x: x.date)
 
             if oldlog and oldlog[-1].date >= log[0].date:
                 raise logerror('Log cache overlaps with new log entries,'
@@ -445,7 +438,7 @@
 
             # write the new cachefile
             ui.note(_('writing cvs log cache %s\n') % cachefile)
-            pickle.dump(log, file(cachefile, 'w'))
+            pickle.dump(log, open(cachefile, 'w'))
         else:
             log = oldlog
 
@@ -484,7 +477,7 @@
 
     # Merge changesets
 
-    listsort(log, key=lambda x:(x.comment, x.author, x.branch, x.date))
+    log.sort(key=lambda x: (x.comment, x.author, x.branch, x.date))
 
     changesets = []
     files = set()
--- a/hgext/convert/p4.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/convert/p4.py	Tue Jul 07 14:20:58 2009 +0200
@@ -92,7 +92,7 @@
 
         # list with depot pathnames, longest first
         vieworder = views.keys()
-        vieworder.sort(key=lambda x: -len(x))
+        vieworder.sort(key=len, reverse=True)
 
         # handle revision limiting
         startrev = self.ui.config('convert', 'p4.startrev', default=0)
--- a/hgext/convert/subversion.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/convert/subversion.py	Tue Jul 07 14:20:58 2009 +0200
@@ -2,7 +2,6 @@
 #
 # Copyright(C) 2007 Daniel Holth et al
 
-import locale
 import os
 import re
 import sys
--- a/hgext/keyword.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/keyword.py	Tue Jul 07 14:20:58 2009 +0200
@@ -78,7 +78,7 @@
 from mercurial import patch, localrepo, templater, templatefilters, util, match
 from mercurial.hgweb import webcommands
 from mercurial.lock import release
-from mercurial.node import nullid, hex
+from mercurial.node import nullid
 from mercurial.i18n import _
 import re, shutil, tempfile, time
 
@@ -495,7 +495,8 @@
                 release(lock, wlock)
 
     # monkeypatches
-    def kwpatchfile_init(orig, self, ui, fname, opener, missing=False, eol=None):
+    def kwpatchfile_init(orig, self, ui, fname, opener,
+                         missing=False, eol=None):
         '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
         rejects or conflicts due to expanded keywords in working dir.'''
         orig(self, ui, fname, opener, missing, eol)
--- a/hgext/mq.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/mq.py	Tue Jul 07 14:20:58 2009 +0200
@@ -1343,19 +1343,24 @@
 
     def qseries(self, repo, missing=None, start=0, length=None, status=None,
                 summary=False):
-        def displayname(patchname):
+        def displayname(pfx, patchname):
             if summary:
                 ph = patchheader(self.join(patchname))
                 msg = ph.message
                 msg = msg and ': ' + msg[0] or ': '
             else:
                 msg = ''
-            return '%s%s' % (patchname, msg)
+            msg = "%s%s%s" % (pfx, patchname, msg)
+            if self.ui.interactive():
+                msg = util.ellipsis(msg, util.termwidth())
+            self.ui.write(msg + '\n')
 
         applied = set([p.name for p in self.applied])
         if length is None:
             length = len(self.series) - start
         if not missing:
+            if self.ui.verbose:
+                idxwidth = len(str(start+length - 1))
             for i in xrange(start, start+length):
                 patch = self.series[i]
                 if patch in applied:
@@ -1366,10 +1371,10 @@
                     stat = 'G'
                 pfx = ''
                 if self.ui.verbose:
-                    pfx = '%d %s ' % (i, stat)
+                    pfx = '%*d %s ' % (idxwidth, i, stat)
                 elif status and status != stat:
                     continue
-                self.ui.write('%s%s\n' % (pfx, displayname(patch)))
+                displayname(pfx, patch)
         else:
             msng_list = []
             for root, dirs, files in os.walk(self.path):
@@ -1383,7 +1388,7 @@
                         msng_list.append(fl)
             for x in sorted(msng_list):
                 pfx = self.ui.verbose and ('D ') or ''
-                self.ui.write("%s%s\n" % (pfx, displayname(x)))
+                displayname(pfx, x)
 
     def issaveline(self, l):
         if l.name == '.hg.patches.save.line':
@@ -1536,7 +1541,7 @@
                 raise util.Abort(_('option "-r" not valid when importing '
                                    'files'))
             rev = cmdutil.revrange(repo, rev)
-            rev.sort(lambda x, y: cmp(y, x))
+            rev.sort(reverse=True)
         if (len(files) > 1 or len(rev) > 1) and patchname:
             raise util.Abort(_('option "-n" not valid when importing multiple '
                                'patches'))
@@ -2329,7 +2334,7 @@
         if ui.verbose:
             guards['NONE'] = noguards
         guards = guards.items()
-        guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:]))
+        guards.sort(key=lambda x: x[0][1:])
         if guards:
             ui.note(_('guards in series file:\n'))
             for guard, count in guards:
--- a/hgext/share.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/hgext/share.py	Tue Jul 07 14:20:58 2009 +0200
@@ -5,7 +5,6 @@
 
 '''share a common history between several working directories'''
 
-import os
 from mercurial.i18n import _
 from mercurial import hg, commands
 
--- a/mercurial/byterange.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/byterange.py	Tue Jul 07 14:20:58 2009 +0200
@@ -208,7 +208,7 @@
     """
     def open_local_file(self, req):
         import mimetypes
-        import mimetools
+        import email
         host = req.get_host()
         file = req.get_selector()
         localfile = urllib.url2pathname(file)
@@ -232,9 +232,9 @@
                 raise RangeError('Requested Range Not Satisfiable')
             size = (lb - fb)
             fo = RangeableFileObject(fo, (fb, lb))
-        headers = mimetools.Message(StringIO(
+        headers = email.message_from_string(
             'Content-Type: %s\nContent-Length: %d\nLast-Modified: %s\n' %
-            (mtype or 'text/plain', size, modified)))
+            (mtype or 'text/plain', size, modified))
         return urllib.addinfourl(fo, headers, 'file:'+file)
 
 
@@ -251,7 +251,7 @@
 import socket
 import sys
 import mimetypes
-import mimetools
+import email
 
 class FTPRangeHandler(urllib2.FTPHandler):
     def ftp_open(self, req):
@@ -325,8 +325,7 @@
                 headers += "Content-Type: %s\n" % mtype
             if retrlen is not None and retrlen >= 0:
                 headers += "Content-Length: %d\n" % retrlen
-            sf = StringIO(headers)
-            headers = mimetools.Message(sf)
+            headers = email.message_from_string(headers)
             return addinfourl(fp, headers, req.get_full_url())
         except ftplib.all_errors, msg:
             raise IOError('ftp error', msg), sys.exc_info()[2]
--- a/mercurial/commands.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/commands.py	Tue Jul 07 14:20:58 2009 +0200
@@ -8,9 +8,9 @@
 from node import hex, nullid, nullrev, short
 from lock import release
 from i18n import _, gettext
-import os, re, sys, subprocess, difflib, time
+import os, re, sys, subprocess, difflib, time, tempfile
 import hg, util, revlog, bundlerepo, extensions, copies, context, error
-import patch, help, mdiff, tempfile, url, encoding
+import patch, help, mdiff, url, encoding
 import archival, changegroup, cmdutil, sshserver, hbisect
 from hgweb import server
 import merge as merge_
@@ -396,8 +396,8 @@
         while size <= changesets:
             tests, size = tests + 1, size * 2
         rev = repo.changelog.rev(node)
-        ui.write(_("Testing changeset %s:%s "
-                   "(%s changesets remaining, ~%s tests)\n")
+        ui.write(_("Testing changeset %d:%s "
+                   "(%d changesets remaining, ~%d tests)\n")
                  % (rev, short(node), changesets, tests))
         if not noupdate:
             cmdutil.bail_if_changed(repo)
@@ -750,7 +750,7 @@
     ui.write("%s\n" % "\n".join(sorted(cmdlist)))
 
 def debugfsinfo(ui, path = "."):
-    file('.debugfsinfo', 'w').write('')
+    open('.debugfsinfo', 'w').write('')
     ui.write('exec: %s\n' % (util.checkexec(path) and 'yes' or 'no'))
     ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no'))
     ui.write('case-sensitive: %s\n' % (util.checkcase('.debugfsinfo')
@@ -983,7 +983,7 @@
         if list(files) != [os.path.basename(fa)]:
             ui.write(_(" unexpected patch output!\n"))
             patchproblems += 1
-        a = file(fa).read()
+        a = open(fa).read()
         if a != b:
             ui.write(_(" patch test failed!\n"))
             patchproblems += 1
@@ -1457,7 +1457,10 @@
         try:
             aliases, i = cmdutil.findcmd(name, table, False)
         except error.AmbiguousCommand, inst:
-            select = lambda c: c.lstrip('^').startswith(inst.args[0])
+            # py3k fix: except vars can't be used outside the scope of the
+            # except block, nor can be used inside a lambda. python issue4617
+            prefix = inst.args[0]
+            select = lambda c: c.lstrip('^').startswith(prefix)
             helplist(_('list of commands:\n\n'), select)
             return
 
--- a/mercurial/context.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/context.py	Tue Jul 07 14:20:58 2009 +0200
@@ -199,7 +199,9 @@
 
         assert (changeid is not None
                 or fileid is not None
-                or changectx is not None)
+                or changectx is not None), \
+                ("bad args: changeid=%r, fileid=%r, changectx=%r"
+                 % (changeid, fileid, changectx))
 
         if filelog:
             self._filelog = filelog
--- a/mercurial/copies.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/copies.py	Tue Jul 07 14:20:58 2009 +0200
@@ -42,7 +42,7 @@
         seen.add(s)
         if fc.path() != orig and fc.path() not in old:
             old[fc.path()] = (depth, fc.path()) # remember depth
-        if fc.rev() < limit and fc.rev() is not None:
+        if fc.rev() is not None and fc.rev() < limit:
             continue
         visit += [(p, depth - 1) for p in fc.parents()]
 
--- a/mercurial/extensions.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/extensions.py	Tue Jul 07 14:20:58 2009 +0200
@@ -166,10 +166,6 @@
 
 def enabled():
     '''return a dict of {name: desc} of extensions, and the max name length'''
-
-    if not enabled:
-        return {}, 0
-
     exts = {}
     maxlength = 0
     exthelps = []
--- a/mercurial/hgweb/common.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/hgweb/common.py	Tue Jul 07 14:20:58 2009 +0200
@@ -69,7 +69,7 @@
         os.stat(path)
         ct = mimetypes.guess_type(path)[0] or "text/plain"
         req.respond(HTTP_OK, ct, length = os.path.getsize(path))
-        return file(path, 'rb').read()
+        return open(path, 'rb').read()
     except TypeError:
         raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename')
     except OSError, err:
--- a/mercurial/hgweb/server.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/hgweb/server.py	Tue Jul 07 14:20:58 2009 +0200
@@ -35,7 +35,7 @@
         for msg in seq:
             self.handler.log_error("HG error:  %s", msg)
 
-class _hgwebhandler(object, BaseHTTPServer.BaseHTTPRequestHandler):
+class _hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler):
 
     url_scheme = 'http'
 
--- a/mercurial/localrepo.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/localrepo.py	Tue Jul 07 14:20:58 2009 +0200
@@ -1707,24 +1707,13 @@
         def identity(x):
             return x
 
-        # A function generating function.  Sets up an environment for the
-        # inner function.
-        def cmp_by_rev_func(revlog):
-            # Compare two nodes by their revision number in the environment's
-            # revision history.  Since the revision number both represents the
-            # most efficient order to read the nodes in, and represents a
-            # topological sorting of the nodes, this function is often useful.
-            def cmp_by_rev(a, b):
-                return cmp(revlog.rev(a), revlog.rev(b))
-            return cmp_by_rev
-
         # If we determine that a particular file or manifest node must be a
         # node that the recipient of the changegroup will already have, we can
         # also assume the recipient will have all the parents.  This function
         # prunes them from the set of missing nodes.
         def prune_parents(revlog, hasset, msngset):
             haslst = list(hasset)
-            haslst.sort(cmp_by_rev_func(revlog))
+            haslst.sort(key=revlog.rev)
             for node in haslst:
                 parentlst = [p for p in revlog.parents(node) if p != nullid]
                 while parentlst:
@@ -1874,7 +1863,7 @@
             add_extra_nodes(1, msng_mnfst_set)
             msng_mnfst_lst = msng_mnfst_set.keys()
             # Sort the manifestnodes by revision number.
-            msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
+            msng_mnfst_lst.sort(key=mnfst.rev)
             # Create a generator for the manifestnodes that calls our lookup
             # and data collection functions back.
             group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
@@ -1912,7 +1901,7 @@
                     yield changegroup.chunkheader(len(fname))
                     yield fname
                     # Sort the filenodes by their revision #
-                    msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
+                    msng_filenode_lst.sort(key=filerevlog.rev)
                     # Create a group generator and only pass in a changenode
                     # lookup function as we need to collect no information
                     # from filenodes.
--- a/mercurial/lsprof.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/lsprof.py	Tue Jul 07 14:20:58 2009 +0200
@@ -26,12 +26,10 @@
         """XXX docstring"""
         if crit not in profiler_entry.__dict__:
             raise ValueError("Can't sort by %s" % crit)
-        self.data.sort(lambda b, a: cmp(getattr(a, crit),
-                                        getattr(b, crit)))
+        self.data.sort(key=lambda x: getattr(x, crit), reverse=True)
         for e in self.data:
             if e.calls:
-                e.calls.sort(lambda b, a: cmp(getattr(a, crit),
-                                              getattr(b, crit)))
+                e.calls.sort(key=lambda x: getattr(x, crit), reverse=True)
 
     def pprint(self, top=None, file=None, limit=None, climit=None):
         """XXX docstring"""
--- a/mercurial/match.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/match.py	Tue Jul 07 14:20:58 2009 +0200
@@ -5,7 +5,8 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
 
-import util, re
+import re
+import util
 
 class match(object):
     def __init__(self, root, cwd, patterns, include=[], exclude=[],
--- a/mercurial/merge.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/merge.py	Tue Jul 07 14:20:58 2009 +0200
@@ -288,7 +288,7 @@
                 continue
             f2, fd, flags, move = a[2:]
             r = ms.resolve(fd, wctx, mctx)
-            if r > 0:
+            if r is not None and r > 0:
                 unresolved += 1
             else:
                 if r is None:
--- a/mercurial/patch.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/patch.py	Tue Jul 07 14:20:58 2009 +0200
@@ -325,10 +325,6 @@
         # looks through the hash and finds candidate lines.  The
         # result is a list of line numbers sorted based on distance
         # from linenum
-        def sorter(a, b):
-            vala = abs(a - linenum)
-            valb = abs(b - linenum)
-            return cmp(vala, valb)
 
         try:
             cand = self.hash[l]
@@ -337,7 +333,7 @@
 
         if len(cand) > 1:
             # resort our list of potentials forward then back.
-            cand.sort(sorter)
+            cand.sort(key=lambda x: abs(x - linenum))
         return cand
 
     def hashlines(self):
@@ -1139,7 +1135,7 @@
         raise util.Abort(_('Unsupported line endings type: %s') % eolmode)
 
     try:
-        fp = file(patchobj, 'rb')
+        fp = open(patchobj, 'rb')
     except TypeError:
         fp = patchobj
     if cwd:
@@ -1422,8 +1418,8 @@
         # If diffstat runs out of room it doesn't print anything, which
         # isn't very useful, so always print at least one + or - if there
         # were at least some changes
-        pluses = '+' * max(adds/factor, int(bool(adds)))
-        minuses = '-' * max(removes/factor, int(bool(removes)))
+        pluses = '+' * max(adds // factor, int(bool(adds)))
+        minuses = '-' * max(removes // factor, int(bool(removes)))
         output.append(' %-*s |  %*.d %s%s\n' % (maxname, filename, countwidth,
                                                 adds+removes, pluses, minuses))
 
--- a/mercurial/posix.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/posix.py	Tue Jul 07 14:20:58 2009 +0200
@@ -9,7 +9,7 @@
 import osutil
 import os, sys, errno, stat, getpass, pwd, grp
 
-posixfile = file
+posixfile = open
 nulldev = '/dev/null'
 normpath = os.path.normpath
 samestat = os.path.samestat
@@ -70,20 +70,20 @@
     if l:
         if not stat.S_ISLNK(s):
             # switch file to link
-            data = file(f).read()
+            data = open(f).read()
             os.unlink(f)
             try:
                 os.symlink(data, f)
             except:
                 # failed to make a link, rewrite file
-                file(f, "w").write(data)
+                open(f, "w").write(data)
         # no chmod needed at this point
         return
     if stat.S_ISLNK(s):
         # switch link to file
         data = os.readlink(f)
         os.unlink(f)
-        file(f, "w").write(data)
+        open(f, "w").write(data)
         s = 0666 & ~umask # avoid restatting for chmod
 
     sx = s & 0100
--- a/mercurial/pure/base85.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/pure/base85.py	Tue Jul 07 14:20:58 2009 +0200
@@ -25,8 +25,8 @@
     longs = len(text) >> 2
     words = struct.unpack('>%dL' % (longs), text)
 
-    out = ''.join(_b85chars[(word / 52200625) % 85] +
-                  _b85chars2[(word / 7225) % 7225] +
+    out = ''.join(_b85chars[(word // 52200625) % 85] +
+                  _b85chars2[(word // 7225) % 7225] +
                   _b85chars2[word % 7225]
                   for word in words)
 
@@ -37,7 +37,7 @@
     olen = l % 4
     if olen:
         olen += 1
-    olen += l / 4 * 5
+    olen += l // 4 * 5
     return out[:olen]
 
 def b85decode(text):
--- a/mercurial/pure/osutil.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/pure/osutil.py	Tue Jul 07 14:20:58 2009 +0200
@@ -8,7 +8,7 @@
 import os
 import stat as _stat
 
-posixfile = file
+posixfile = open
 
 def _mode_to_kind(mode):
     if _stat.S_ISREG(mode): return _stat.S_IFREG
--- a/mercurial/revlog.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/revlog.py	Tue Jul 07 14:20:58 2009 +0200
@@ -879,7 +879,7 @@
         if len(id) < 40:
             try:
                 # hex(node)[:...]
-                l = len(id) / 2  # grab an even number of digits
+                l = len(id) // 2  # grab an even number of digits
                 bin_id = bin(id[:l*2])
                 nl = [n for n in self.nodemap if n[:l] == bin_id]
                 nl = [n for n in nl if hex(n).startswith(id)]
@@ -1354,7 +1354,7 @@
             f.seek(0, 2)
             actual = f.tell()
             s = self._io.size
-            i = max(0, actual / s)
+            i = max(0, actual // s)
             di = actual - (i * s)
             if self._inline:
                 databytes = 0
--- a/mercurial/templatefilters.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/templatefilters.py	Tue Jul 07 14:20:58 2009 +0200
@@ -41,7 +41,7 @@
 
     delta = max(1, int(now - then))
     for t, s in agescales:
-        n = delta / s
+        n = delta // s
         if n >= 2 or s == 1:
             return fmt(t, n)
 
--- a/mercurial/util.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/util.py	Tue Jul 07 14:20:58 2009 +0200
@@ -937,8 +937,8 @@
     t, tz = date or makedate()
     if "%1" in format or "%2" in format:
         sign = (tz > 0) and "-" or "+"
-        minutes = abs(tz) / 60
-        format = format.replace("%1", "%c%02d" % (sign, minutes / 60))
+        minutes = abs(tz) // 60
+        format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
         format = format.replace("%2", "%02d" % (minutes % 60))
     s = time.strftime(format, time.gmtime(float(t) - tz))
     return s
--- a/mercurial/verify.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/mercurial/verify.py	Tue Jul 07 14:20:58 2009 +0200
@@ -147,7 +147,7 @@
     if havemf:
         for c,m in sorted([(c, m) for m in mflinkrevs for c in mflinkrevs[m]]):
             err(c, _("changeset refers to unknown manifest %s") % short(m))
-        del mflinkrevs
+        mflinkrevs = None # del is bad here due to scope issues
 
         for f in sorted(filelinkrevs):
             if f not in filenodes:
--- a/setup.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/setup.py	Tue Jul 07 14:20:58 2009 +0200
@@ -143,7 +143,7 @@
             break
 
 if version:
-    f = file("mercurial/__version__.py", "w")
+    f = open("mercurial/__version__.py", "w")
     f.write('# this file is autogenerated by setup.py\n')
     f.write('version = "%s"\n' % version)
     f.close()
--- a/tests/killdaemons.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/killdaemons.py	Tue Jul 07 14:20:58 2009 +0200
@@ -4,7 +4,7 @@
 
 # Kill off any leftover daemon processes
 try:
-    fp = file(os.environ['DAEMON_PIDS'])
+    fp = open(os.environ['DAEMON_PIDS'])
     for line in fp:
         try:
             pid = int(line)
--- a/tests/run-tests.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/run-tests.py	Tue Jul 07 14:20:58 2009 +0200
@@ -119,6 +119,8 @@
         help="shortcut for --with-hg=<testdir>/../hg")
     parser.add_option("--pure", action="store_true",
         help="use pure Python code instead of C extensions")
+    parser.add_option("-3", "--py3k-warnings", action="store_true",
+        help="enable Py3k warnings on Python 2.6+")
 
     for option, default in defaults.items():
         defaults[option] = int(os.environ.get(*default))
@@ -171,6 +173,10 @@
     if options.interactive and options.jobs > 1:
         print '(--interactive overrides --jobs)'
         options.jobs = 1
+    if options.py3k_warnings:
+        if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0):
+            print 'ERROR: Py3k warnings switch can only be used on Python 2.6+'
+            sys.exit(1)
 
     return (options, args)
 
@@ -299,6 +305,17 @@
     f.close()
     os.chmod(os.path.join(BINDIR, 'diffstat'), 0700)
 
+    if options.py3k_warnings and not options.anycoverage:
+        vlog("# Updating hg command to enable Py3k Warnings switch")
+        f = open(os.path.join(BINDIR, 'hg'), 'r')
+        lines = [line.rstrip() for line in f]
+        lines[0] += ' -3'
+        f.close()
+        f = open(os.path.join(BINDIR, 'hg'), 'w')
+        for line in lines:
+            f.write(line + '\n')
+        f.close()
+
     if options.anycoverage:
         vlog("# Installing coverage wrapper")
         os.environ['COVERAGE_FILE'] = COVERAGE_FILE
@@ -402,7 +419,7 @@
     vlog("# Test", test)
 
     # create a fresh hgrc
-    hgrc = file(HGRCPATH, 'w+')
+    hgrc = open(HGRCPATH, 'w+')
     hgrc.write('[ui]\n')
     hgrc.write('slash = True\n')
     hgrc.write('[defaults]\n')
@@ -432,7 +449,8 @@
     lctest = test.lower()
 
     if lctest.endswith('.py') or firstline == '#!/usr/bin/env python':
-        cmd = '%s "%s"' % (PYTHON, testpath)
+        py3kswitch = options.py3k_warnings and ' -3' or ''
+        cmd = '%s%s "%s"' % (PYTHON, py3kswitch, testpath)
     elif lctest.endswith('.bat'):
         # do not run batch scripts on non-windows
         if os.name != 'nt':
@@ -507,7 +525,7 @@
 
     # Kill off any leftover daemon processes
     try:
-        fp = file(DAEMON_PIDS)
+        fp = open(DAEMON_PIDS)
         for line in fp:
             try:
                 pid = int(line)
--- a/tests/test-context.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/test-context.py	Tue Jul 07 14:20:58 2009 +0200
@@ -7,7 +7,7 @@
 os.chdir('test1')
 
 # create 'foo' with fixed time stamp
-f = file('foo', 'w')
+f = open('foo', 'w')
 f.write('foo\n')
 f.close()
 os.utime('foo', (1000, 1000))
--- a/tests/test-convert-cvs-branch	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/test-convert-cvs-branch	Tue Jul 07 14:20:58 2009 +0200
@@ -83,7 +83,8 @@
 
 cvscall -Q -d `pwd`/cvsmaster2 init >/dev/null 2>&1
 cd cvsmaster2
-export CVSROOT=`pwd`
+CVSROOT=`pwd`
+export CVSROOT
 mkdir foo
 cd ..
 cvscall -Q co -d cvswork2 foo
--- a/tests/test-dispatch.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/test-dispatch.py	Tue Jul 07 14:20:58 2009 +0200
@@ -15,14 +15,14 @@
 os.chdir('test1')
 
 # create file 'foo', add and commit
-f = file('foo', 'wb')
+f = open('foo', 'wb')
 f.write('foo\n')
 f.close()
 testdispatch("add foo")
 testdispatch("commit -m commit1 -d 2000-01-01 foo")
 
 # append to file 'foo' and commit
-f = file('foo', 'ab')
+f = open('foo', 'ab')
 f.write('bar\n')
 f.close()
 testdispatch("commit -m commit2 -d 2000-01-02 foo")
--- a/tests/test-gpg	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/test-gpg	Tue Jul 07 14:20:58 2009 +0200
@@ -7,7 +7,7 @@
 gpg=
 
 [gpg]
-cmd=gpg --no-permission-warning --homedir $TESTDIR/gpg
+cmd=gpg --no-permission-warning --no-secmem-warning --homedir $TESTDIR/gpg
 EOF
 
 hg init r
--- a/tests/test-hook	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/test-hook	Tue Jul 07 14:20:58 2009 +0200
@@ -230,4 +230,22 @@
 
 hg showconfig hooks | sed -e 's/ at .*>/>/'
 
+echo '# test python hook configured with python:[file]:[hook] syntax'
+cd ..
+mkdir d
+cd d
+hg init repo
+mkdir hooks
+
+cd hooks
+cat > testhooks.py <<EOF
+def testhook(**args):
+    print 'hook works'
+EOF
+echo '[hooks]' > ../repo/.hg/hgrc
+echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
+
+cd ../repo
+hg commit
+
 exit 0
--- a/tests/test-hook.out	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/test-hook.out	Tue Jul 07 14:20:58 2009 +0200
@@ -160,3 +160,6 @@
 Automatically installed hook
 committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
 hooks.commit.auto=<function autohook>
+# test python hook configured with python:[file]:[hook] syntax
+hook works
+nothing changed
--- a/tests/test-revlog-ancestry.py	Tue Jul 07 01:25:44 2009 +0200
+++ b/tests/test-revlog-ancestry.py	Tue Jul 07 14:20:58 2009 +0200
@@ -10,7 +10,7 @@
     repo.commit(text=text, date="%d 0" % time)
 
 def addcommit(name, time):
-    f = file(name, 'w')
+    f = open(name, 'w')
     f.write('%s\n' % name)
     f.close()
     repo.add([name])