[PATCH] convert: remove unused-but-set variable introduced in db9e883566e8

2016-12-17 Thread Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara 
# Date 1482045604 -32400
#  Sun Dec 18 16:20:04 2016 +0900
# Node ID 7d505a99f16d0a7faae231432deef5c9bcfd3ad1
# Parent  07025bd744a09dd5622e16ccef11966fda7b86f2
convert: remove unused-but-set variable introduced in db9e883566e8

Spotted by pyflakes.

diff --git a/hgext/convert/p4.py b/hgext/convert/p4.py
--- a/hgext/convert/p4.py
+++ b/hgext/convert/p4.py
@@ -302,8 +302,6 @@ class p4_source(common.converter_source)
 `p4 describe` output
 """
 desc = self.recode(obj.get("desc", ""))
-shortdesc = desc.split("\n", 1)[0]
-
 date = (int(obj["time"]), 0) # timezone not set
 if parents is None:
 parents = []
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH] registrar: raise a programming error on duplicated registering

2016-12-17 Thread Yuya Nishihara
On Fri, 16 Dec 2016 20:31:29 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David 
> # Date 1481545965 -3600
> #  Mon Dec 12 13:32:45 2016 +0100
> # Node ID f3479f74af0d2b21c89e906c503f4cddf4b3c39b
> # Parent  182cacaa4c32330c0466b7111a75d060830783e8
> registrar: raise a programming error on duplicated registering
> 
> Previous, registering different object with the same name would silently
> overwrite the first value with the second one. We now detect the situation and
> raise an error. No extension in test or core had the issues.
> 
> diff --git a/mercurial/registrar.py b/mercurial/registrar.py
> --- a/mercurial/registrar.py
> +++ b/mercurial/registrar.py
> @@ -8,6 +8,7 @@
>  from __future__ import absolute_import
>  
>  from . import (
> +error,
>  pycompat,
>  util,
>  )
> @@ -55,6 +56,9 @@ class _funcregistrarbase(object):
>  func._origdoc = doc
>  func.__doc__ = self._formatdoc(decl, doc)
>  
> +if name in self._table:
> +raise error.ProgrammingError('duplicate registration for name 
> %s',
> + name)

It should be '% name'.

I slightly prefer raising the error before modifying the func object, but that
would make little difference since ProgrammingError isn't a recoverable error.

>  self._table[name] = func
>  self._extrasetup(name, func, *args, **kwargs)
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH] error: make it clear that ProgrammingError is for mercurial developers

2016-12-17 Thread timeless
Thanks
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 3] chg: start server at a unique address

2016-12-17 Thread Gregory Szorc
It's probably not worth worrying about just yet, but with Linux PID namespaces, 
multiple processes may think they have the same PID, even if that PID maps to 
different values inside the kernel.

Mozilla has encountered problems with multiple hg processes running in separate 
containers and PID namespaces acquiring the same lock from a shared filesystem 
simultaneously because multiple hg processes share the same PID and hostname in 
different "containers."

> On Dec 16, 2016, at 17:49, Jun Wu  wrote:
> 
> # HG changeset patch
> # User Jun Wu 
> # Date 1481938472 0
> #  Sat Dec 17 01:34:32 2016 +
> # Node ID 6c9ce8399350d8287599cd802b91adf73db08759
> # Parent  69d25b06467d65bf6d1e85d34d8fc57ec321b51d
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #  hg pull https://bitbucket.org/quark-zju/hg-draft -r 
> 6c9ce8399350
> chg: start server at a unique address
> 
> See the previous patch for motivation. Previously, the server is started at
> a globally shared address, which requires a lock. This patch appends pid to
> the address so it becomes unique.
> 
> diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
> --- a/contrib/chg/chg.c
> +++ b/contrib/chg/chg.c
> @@ -32,4 +32,5 @@
> struct cmdserveropts {
>char sockname[UNIX_PATH_MAX];
> +char initsockname[UNIX_PATH_MAX];
>char redirectsockname[UNIX_PATH_MAX];
>char lockfile[UNIX_PATH_MAX];
> @@ -164,4 +165,8 @@ static void setcmdserveropts(struct cmds
>if (r < 0 || (size_t)r >= sizeof(opts->lockfile))
>abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
> +r = snprintf(opts->initsockname, sizeof(opts->initsockname),
> +"%s.%u", opts->sockname, (unsigned)getpid());
> +if (r < 0 || (size_t)r >= sizeof(opts->initsockname))
> +abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
> }
> 
> @@ -224,5 +229,5 @@ static void execcmdserver(const struct c
>"serve",
>"--cmdserver", "chgunix",
> -"--address", opts->sockname,
> +"--address", opts->initsockname,
>"--daemon-postexec", "chdir:/",
>};
> @@ -248,5 +253,5 @@ static hgclient_t *retryconnectcmdserver
>int pst = 0;
> 
> -debugmsg("try connect to %s repeatedly", opts->sockname);
> +debugmsg("try connect to %s repeatedly", opts->initsockname);
> 
>unsigned int timeoutsec = 60;  /* default: 60 seconds */
> @@ -256,7 +261,13 @@ static hgclient_t *retryconnectcmdserver
> 
>for (unsigned int i = 0; !timeoutsec || i < timeoutsec * 100; i++) {
> -hgclient_t *hgc = hgc_open(opts->sockname);
> -if (hgc)
> +hgclient_t *hgc = hgc_open(opts->initsockname);
> +if (hgc) {
> +debugmsg("rename %s to %s", opts->initsockname,
> +opts->sockname);
> +int r = rename(opts->initsockname, opts->sockname);
> +if (r != 0)
> +abortmsgerrno("cannot rename");
>return hgc;
> +}
> 
>if (pid > 0) {
> @@ -270,5 +281,5 @@ static hgclient_t *retryconnectcmdserver
>}
> 
> -abortmsg("timed out waiting for cmdserver %s", opts->sockname);
> +abortmsg("timed out waiting for cmdserver %s", opts->initsockname);
>return NULL;
> 
> @@ -313,5 +324,5 @@ static hgclient_t *connectcmdserver(stru
>unlink(opts->sockname);
> 
> -debugmsg("start cmdserver at %s", opts->sockname);
> +debugmsg("start cmdserver at %s", opts->initsockname);
> 
>pid_t pid = fork();
> ___
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 5 of 6] py3: replace os.sep with pycompat.ossep (part 3 of 4)

2016-12-17 Thread Pulkit Goyal
# HG changeset patch
# User Pulkit Goyal <7895pul...@gmail.com>
# Date 1481985864 -19800
#  Sat Dec 17 20:14:24 2016 +0530
# Node ID c816d1b5b807f8076b027f9cb9ffdeafe5fd7e62
# Parent  a82ca84371f5f4b4213aec534ab0ccdfbd04cf9b
py3: replace os.sep with pycompat.ossep (part 3 of 4)

diff -r a82ca84371f5 -r c816d1b5b807 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py  Sat Dec 17 20:02:50 2016 +0530
+++ b/mercurial/cmdutil.py  Sat Dec 17 20:14:24 2016 +0530
@@ -731,7 +731,7 @@
 else:
 striplen = len(abspfx)
 if striplen:
-striplen += len(os.sep)
+striplen += len(pycompat.ossep)
 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:])
 elif destdirexists:
 res = lambda p: os.path.join(dest,
@@ -765,12 +765,12 @@
 abspfx = util.localpath(abspfx)
 striplen = len(abspfx)
 if striplen:
-striplen += len(os.sep)
+striplen += len(pycompat.ossep)
 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])):
 score = evalpath(striplen)
 striplen1 = len(os.path.split(abspfx)[0])
 if striplen1:
-striplen1 += len(os.sep)
+striplen1 += len(pycompat.ossep)
 if evalpath(striplen1) > score:
 striplen = striplen1
 res = lambda p: os.path.join(dest,
diff -r a82ca84371f5 -r c816d1b5b807 mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py Sat Dec 17 20:02:50 2016 +0530
+++ b/mercurial/hgweb/common.py Sat Dec 17 20:14:24 2016 +0530
@@ -12,7 +12,10 @@
 import mimetypes
 import os
 
-from .. import util
+from .. import (
+pycompat,
+util,
+)
 
 httpserver = util.httpserver
 
@@ -139,7 +142,7 @@
 parts = fname.split('/')
 for part in parts:
 if (part in ('', os.curdir, os.pardir) or
-os.sep in part or os.altsep is not None and os.altsep in part):
+pycompat.ossep in part or os.altsep is not None and os.altsep in part):
 return
 fpath = os.path.join(*parts)
 if isinstance(directory, str):
diff -r a82ca84371f5 -r c816d1b5b807 mercurial/subrepo.py
--- a/mercurial/subrepo.py  Sat Dec 17 20:02:50 2016 +0530
+++ b/mercurial/subrepo.py  Sat Dec 17 20:14:24 2016 +0530
@@ -31,6 +31,7 @@
 node,
 pathutil,
 phases,
+pycompat,
 scmutil,
 util,
 )
@@ -1172,7 +1173,7 @@
 changes.append(path)
 for path in changes:
 for ext in externals:
-if path == ext or path.startswith(ext + os.sep):
+if path == ext or path.startswith(ext + pycompat.ossep):
 return True, True, bool(missing)
 return bool(changes), False, bool(missing)
 
diff -r a82ca84371f5 -r c816d1b5b807 mercurial/templater.py
--- a/mercurial/templater.pySat Dec 17 20:02:50 2016 +0530
+++ b/mercurial/templater.pySat Dec 17 20:14:24 2016 +0530
@@ -17,6 +17,7 @@
 error,
 minirst,
 parser,
+pycompat,
 registrar,
 revset as revsetmod,
 templatefilters,
@@ -1243,7 +1244,7 @@
 # only plain name is allowed to honor template paths
 if (not style
 or style in (os.curdir, os.pardir)
-or os.sep in style
+or pycompat.ossep in style
 or os.altsep and os.altsep in style):
 continue
 locations = [os.path.join(style, 'map'), 'map-' + style]
diff -r a82ca84371f5 -r c816d1b5b807 mercurial/windows.py
--- a/mercurial/windows.py  Sat Dec 17 20:02:50 2016 +0530
+++ b/mercurial/windows.py  Sat Dec 17 20:14:24 2016 +0530
@@ -215,7 +215,7 @@
 msvcrt.setmode(fno(), os.O_BINARY)
 
 def pconvert(path):
-return path.replace(os.sep, '/')
+return path.replace(pycompat.ossep, '/')
 
 def localpath(path):
 return path.replace('/', '\\')
@@ -316,7 +316,7 @@
 return executable
 return None
 
-if os.sep in command:
+if pycompat.ossep in command:
 return findexisting(command)
 
 for path in os.environ.get('PATH', '').split(pycompat.ospathsep):
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 4 of 6] py3: replace os.sep with pycompat.ossep (part 2 of 4)

2016-12-17 Thread Pulkit Goyal
# HG changeset patch
# User Pulkit Goyal <7895pul...@gmail.com>
# Date 1481985170 -19800
#  Sat Dec 17 20:02:50 2016 +0530
# Node ID a82ca84371f5f4b4213aec534ab0ccdfbd04cf9b
# Parent  4107888f9b89e178ab8369a6d63ebb2e17dc26b9
py3: replace os.sep with pycompat.ossep (part 2 of 4)

This part also replaces some chunks of os.sep with pycompat.ossep.

diff -r 4107888f9b89 -r a82ca84371f5 mercurial/dirstate.py
--- a/mercurial/dirstate.py Sat Dec 17 19:56:30 2016 +0530
+++ b/mercurial/dirstate.py Sat Dec 17 20:02:50 2016 +0530
@@ -286,7 +286,7 @@
 # self._root ends with a path separator if self._root is '/' or 'C:\'
 rootsep = self._root
 if not util.endswithsep(rootsep):
-rootsep += os.sep
+rootsep += pycompat.ossep
 if cwd.startswith(rootsep):
 return cwd[len(rootsep):]
 else:
diff -r 4107888f9b89 -r a82ca84371f5 mercurial/pathutil.py
--- a/mercurial/pathutil.py Sat Dec 17 19:56:30 2016 +0530
+++ b/mercurial/pathutil.py Sat Dec 17 20:02:50 2016 +0530
@@ -9,6 +9,7 @@
 from . import (
 encoding,
 error,
+pycompat,
 util,
 )
 
@@ -87,8 +88,8 @@
 # This means we won't accidentally traverse a symlink into some other
 # filesystem (which is potentially expensive to access).
 for i in range(len(parts)):
-prefix = os.sep.join(parts[:i + 1])
-normprefix = os.sep.join(normparts[:i + 1])
+prefix = pycompat.ossep.join(parts[:i + 1])
+normprefix = pycompat.ossep.join(normparts[:i + 1])
 if normprefix in self.auditeddir:
 continue
 if self._realfs:
@@ -132,7 +133,7 @@
 if util.endswithsep(root):
 rootsep = root
 else:
-rootsep = root + os.sep
+rootsep = root + pycompat.ossep
 name = myname
 if not os.path.isabs(name):
 name = os.path.join(root, cwd, name)
@@ -202,8 +203,8 @@
 '/'
 '''
 d, p = os.path.splitdrive(path)
-if len(p) != len(os.sep):
-return path + os.sep
+if len(p) != len(pycompat.ossep):
+return path + pycompat.ossep
 else:
 return path
 
diff -r 4107888f9b89 -r a82ca84371f5 mercurial/posix.py
--- a/mercurial/posix.pySat Dec 17 19:56:30 2016 +0530
+++ b/mercurial/posix.pySat Dec 17 20:02:50 2016 +0530
@@ -369,7 +369,7 @@
 # use upper-ing as normcase as same as NTFS workaround
 def normcase(path):
 pathlen = len(path)
-if (pathlen == 0) or (path[0] != os.sep):
+if (pathlen == 0) or (path[0] != pycompat.ossep):
 # treat as relative
 return encoding.upper(path)
 
@@ -381,7 +381,7 @@
 mplen = len(mp)
 if mplen == pathlen: # mount point itself
 return mp
-if path[mplen] == os.sep:
+if path[mplen] == pycompat.ossep:
 return mp + encoding.upper(path[mplen:])
 
 return encoding.upper(path)
@@ -456,7 +456,7 @@
 return executable
 return None
 
-if os.sep in command:
+if pycompat.ossep in command:
 return findexisting(command)
 
 if sys.platform == 'plan9':
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 3 of 6] py3: replace os.sep with pycompat.ossep (part 1 of 4)

2016-12-17 Thread Pulkit Goyal
# HG changeset patch
# User Pulkit Goyal <7895pul...@gmail.com>
# Date 1481984790 -19800
#  Sat Dec 17 19:56:30 2016 +0530
# Node ID 4107888f9b89e178ab8369a6d63ebb2e17dc26b9
# Parent  32865b15b8417a3ad673b72ffc713dffdebcd04a
py3: replace os.sep with pycompat.ossep (part 1 of 4)

os.sep returns unicodes on Python 3. We have pycompat.ossep which returns
bytes. This patch is a part of 4 patch series which will replace all the
occurences of os.sep to pycompat.ossep

diff -r 32865b15b841 -r 4107888f9b89 mercurial/commands.py
--- a/mercurial/commands.py Sat Dec 17 19:47:17 2016 +0530
+++ b/mercurial/commands.py Sat Dec 17 19:56:30 2016 +0530
@@ -2356,7 +2356,7 @@
 def complete(path, acceptable):
 dirstate = repo.dirstate
 spec = os.path.normpath(os.path.join(pycompat.getcwd(), path))
-rootdir = repo.root + os.sep
+rootdir = repo.root + pycompat.ossep
 if spec != repo.root and not spec.startswith(rootdir):
 return [], []
 if os.path.isdir(spec):
@@ -2364,7 +2364,7 @@
 spec = spec[len(rootdir):]
 fixpaths = pycompat.ossep != '/'
 if fixpaths:
-spec = spec.replace(os.sep, '/')
+spec = spec.replace(pycompat.ossep, '/')
 speclen = len(spec)
 fullpaths = opts['full']
 files, dirs = set(), set()
@@ -2372,11 +2372,11 @@
 for f, st in dirstate.iteritems():
 if f.startswith(spec) and st[0] in acceptable:
 if fixpaths:
-f = f.replace('/', os.sep)
+f = f.replace('/', pycompat.ossep)
 if fullpaths:
 addfile(f)
 continue
-s = f.find(os.sep, speclen)
+s = f.find(pycompat.ossep, speclen)
 if s >= 0:
 adddir(f[:s])
 else:
diff -r 32865b15b841 -r 4107888f9b89 mercurial/util.py
--- a/mercurial/util.py Sat Dec 17 19:47:17 2016 +0530
+++ b/mercurial/util.py Sat Dec 17 19:56:30 2016 +0530
@@ -916,7 +916,7 @@
 a.pop()
 b.pop()
 b.reverse()
-return os.sep.join((['..'] * len(a)) + b) or '.'
+return pycompat.ossep.join((['..'] * len(a)) + b) or '.'
 
 def mainfrozen():
 """return True if we are a frozen executable.
@@ -1303,7 +1303,7 @@
 def _makefspathcacheentry(dir):
 return dict((normcase(n), n) for n in os.listdir(dir))
 
-seps = os.sep
+seps = pycompat.ossep
 if os.altsep:
 seps = seps + os.altsep
 # Protect backslashes. This gets silly very quickly.
@@ -1370,7 +1370,8 @@
 
 def endswithsep(path):
 '''Check path ends with os.sep or os.altsep.'''
-return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep)
+return path.endswith(pycompat.ossep) or os.altsep\
+and path.endswith(os.altsep)
 
 def splitpath(path):
 '''Split path by os.sep.
@@ -1378,7 +1379,7 @@
 an alternative of simple "xxx.split(os.sep)".
 It is recommended to use os.path.normpath() before using this
 function if need.'''
-return path.split(os.sep)
+return path.split(pycompat.ossep)
 
 def gui():
 '''Are we running in a GUI?'''
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 6 of 6] py3: replace os.sep with pycompat.ossep (part 4 of 4)

2016-12-17 Thread Pulkit Goyal
# HG changeset patch
# User Pulkit Goyal <7895pul...@gmail.com>
# Date 1481986486 -19800
#  Sat Dec 17 20:24:46 2016 +0530
# Node ID 2fadbc71f79ad9e91892faf650a3fed05dbfd6b8
# Parent  c816d1b5b807f8076b027f9cb9ffdeafe5fd7e62
py3: replace os.sep with pycompat.ossep (part 4 of 4)

diff -r c816d1b5b807 -r 2fadbc71f79a hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.pySat Dec 17 20:14:24 2016 +0530
+++ b/hgext/convert/cvsps.pySat Dec 17 20:24:46 2016 +0530
@@ -12,6 +12,7 @@
 from mercurial.i18n import _
 from mercurial import (
 hook,
+pycompat,
 util,
 )
 
@@ -136,8 +137,8 @@
 except IOError:
 raise logerror(_('not a CVS sandbox'))
 
-if prefix and not prefix.endswith(os.sep):
-prefix += os.sep
+if prefix and not prefix.endswith(pycompat.ossep):
+prefix += pycompat.ossep
 
 # Use the Root file in the sandbox, if it exists
 try:
diff -r c816d1b5b807 -r 2fadbc71f79a hgext/win32mbcs.py
--- a/hgext/win32mbcs.pySat Dec 17 20:14:24 2016 +0530
+++ b/hgext/win32mbcs.pySat Dec 17 20:24:46 2016 +0530
@@ -53,6 +53,7 @@
 from mercurial import (
 encoding,
 error,
+pycompat,
 )
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' 
for
@@ -97,7 +98,7 @@
 except UnicodeError:
 us = s
 if us and us[-1] not in ':/\\':
-s += os.sep
+s += pycompat.ossep
 return s
 
 
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 1 of 6] py3: use %d instead of %s for integers

2016-12-17 Thread Pulkit Goyal
# HG changeset patch
# User Pulkit Goyal <7895pul...@gmail.com>
# Date 1481983600 -19800
#  Sat Dec 17 19:36:40 2016 +0530
# Node ID ea408eb4d17eb54f68ffcbabb1c32cacfb64955d
# Parent  935092e525b0ee5656d0830162a1c2adf8248de3
py3: use %d instead of %s for integers

Python 3 returns an error if we use %s as type specifiers for integers.

diff -r 935092e525b0 -r ea408eb4d17e mercurial/commands.py
--- a/mercurial/commands.py Fri Dec 16 09:48:14 2016 -0800
+++ b/mercurial/commands.py Sat Dec 17 19:36:40 2016 +0530
@@ -1892,7 +1892,7 @@
 fm.write('pythonexe', _("checking Python executable (%s)\n"),
  sys.executable)
 fm.write('pythonver', _("checking Python version (%s)\n"),
- ("%s.%s.%s" % sys.version_info[:3]))
+ ("%d.%d.%d" % sys.version_info[:3]))
 fm.write('pythonlib', _("checking Python lib (%s)...\n"),
  os.path.dirname(os.__file__))
 
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 2 of 6] py3: replace os.pathsep with pycompat.ospathsep

2016-12-17 Thread Pulkit Goyal
# HG changeset patch
# User Pulkit Goyal <7895pul...@gmail.com>
# Date 1481984237 -19800
#  Sat Dec 17 19:47:17 2016 +0530
# Node ID 32865b15b8417a3ad673b72ffc713dffdebcd04a
# Parent  ea408eb4d17eb54f68ffcbabb1c32cacfb64955d
py3: replace os.pathsep with pycompat.ospathsep

os.pathsep returns unicode on Python 3. We already have pycompat.ospathsep
which return bytes on Python 3. This patch replaces all the occurences of
os.pathsep in the codebase(excluding tests) to pycompat.ospathsep.

diff -r ea408eb4d17e -r 32865b15b841 mercurial/posix.py
--- a/mercurial/posix.pySat Dec 17 19:36:40 2016 +0530
+++ b/mercurial/posix.pySat Dec 17 19:47:17 2016 +0530
@@ -23,6 +23,7 @@
 from .i18n import _
 from . import (
 encoding,
+pycompat,
 )
 
 posixfile = open
@@ -461,7 +462,7 @@
 if sys.platform == 'plan9':
 return findexisting(os.path.join('/bin', command))
 
-for path in os.environ.get('PATH', '').split(os.pathsep):
+for path in os.environ.get('PATH', '').split(pycompat.ospathsep):
 executable = findexisting(os.path.join(path, command))
 if executable is not None:
 return executable
diff -r ea408eb4d17e -r 32865b15b841 mercurial/scmwindows.py
--- a/mercurial/scmwindows.py   Sat Dec 17 19:36:40 2016 +0530
+++ b/mercurial/scmwindows.py   Sat Dec 17 19:47:17 2016 +0530
@@ -4,6 +4,7 @@
 
 from . import (
 osutil,
+pycompat,
 util,
 win32,
 )
@@ -33,7 +34,7 @@
 if not isinstance(value, str) or not value:
 return rcpath
 value = util.localpath(value)
-for p in value.split(os.pathsep):
+for p in value.split(pycompat.ospathsep):
 if p.lower().endswith('mercurial.ini'):
 rcpath.append(p)
 elif os.path.isdir(p):
diff -r ea408eb4d17e -r 32865b15b841 mercurial/windows.py
--- a/mercurial/windows.py  Sat Dec 17 19:36:40 2016 +0530
+++ b/mercurial/windows.py  Sat Dec 17 19:47:17 2016 +0530
@@ -18,6 +18,7 @@
 from . import (
 encoding,
 osutil,
+pycompat,
 win32,
 )
 
@@ -303,7 +304,7 @@
 An extension from PATHEXT is found and added if not present.
 If command isn't found None is returned.'''
 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD')
-pathexts = [ext for ext in pathext.lower().split(os.pathsep)]
+pathexts = [ext for ext in pathext.lower().split(pycompat.ospathsep)]
 if os.path.splitext(command)[1].lower() in pathexts:
 pathexts = ['']
 
@@ -318,7 +319,7 @@
 if os.sep in command:
 return findexisting(command)
 
-for path in os.environ.get('PATH', '').split(os.pathsep):
+for path in os.environ.get('PATH', '').split(pycompat.ospathsep):
 executable = findexisting(os.path.join(path, command))
 if executable is not None:
 return executable
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 1 of 4 v5] revlog: add ability to apply transforms on flags

2016-12-17 Thread Pierre-Yves David



On 12/14/2016 12:58 PM, Remi Chaintron wrote:

# HG changeset patch
# User Remi Chaintron 
# Date 1481716603 0
#  Wed Dec 14 11:56:43 2016 +
# Branch stable
# Node ID 7599256f2800bbacc3b478ac8d2c4a5746eb4cd1
# Parent  d34c04da52a8f2eb61b51bb0aa9cedf1e4b43474
revlog: add ability to apply transforms on flags

Add a mechanism for extensions/subclasses of revlog to register transforms on
read/write operations on revlog, based on revision flags.

Due to some operations being non-commutative, transforms applied in a specific
order when writing the contents of the revlog need to be applied on the reverse
order when reading.
In order to allow the composition of such operation, the 'processflags' method
applies transforms on flags in the order defined by REVIDX_FLAGS_ORDER.

Extensions can use the `localrepository.registerflagtransform()` method to
register default transforms on flags in `reposetup()` in order to ensure their
transform will not override/be overridden by other extensions' transforms.


As a general principle, we don't add new methods on localrepo. Its 
tempting to add stuff to that central object but this lead to horrible 
horrible class bloat in the past. In addition, your method does not 
seems to make any use of the repo itself. (if we did not wrote that down 
somewhere, we should)


Instead, you should go for one of these two options:
- a small function defined next to the dictionary
- our shiny and nice "registrar" mechanism. See 
https://www.mercurial-scm.org/repo/hg/file/tip/hgext/rebase.py#l109 for 
an example.


I would probably pick registrar because the code exists, but given the 
low amount of registrees it might be overkill.


Couple of feedback inlined



diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -147,7 +147,9 @@
 delta = self._chunk(chain.pop())
 text = mdiff.patches(text, [delta])

-self.checkhash(text, node, rev=rev)
+text, validatehash = self.processflags(text, self.flags(rev))
+if validatehash is True:


Should be:

  if validatehash:


+self.checkhash(text, node, rev=rev)
 self._cache = (node, rev, text)
 return text

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -48,6 +48,7 @@
 phases,
 pushkey,
 repoview,
+revlog,
 revset,
 scmutil,
 store,
@@ -1959,6 +1960,21 @@
 fp.close()
 return self.pathto(fp.name[len(self.root) + 1:])

+def registerflagtransform(self, flag, transform):
+"""Register transform on revlog flags.
+
+Extensions can rely on this method to set default transforms on revlog
+flags, and ensure they are not overwritten by/overwriting other
+extensions'.
+"""
+if not flag & revlog.REVIDX_KNOWN_FLAGS:
+raise error.Abort(_("Cannot register transform on unknown flag."))


note that we neither capitalize nor punctuate our error messages.


+transform = revlog.REVIDX_FLAGS_TRANSFORMS.get(flag, None)
+if transform is not None:
+raise error.Abort(
+_("Cannot register multiple transforms on flags."))


ditto


+revlog.REVIDX_FLAGS_TRANSFORMS[flag] = transform
+
 # used to avoid circular references so destructors work
 def aftertrans(files):
 renamefiles = [tuple(t) for t in files]
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -56,6 +56,12 @@
 REVIDX_ISCENSORED = (1 << 15) # revision has censor metadata, must be verified
 REVIDX_DEFAULT_FLAGS = 0
 REVIDX_KNOWN_FLAGS = REVIDX_ISCENSORED
+# stable order in which flags need to be processed and their transforms applied
+REVIDX_FLAGS_ORDER = [
+REVIDX_ISCENSORED,
+]
+REVIDX_FLAGS_TRANSFORMS = { }


Small nits: as we have no "public" accessors of this, we could add a '_' 
in front of it to discourage people to access it directly.



+

 # max size of revlog with inline data
 _maxinline = 131072
@@ -1203,11 +1209,6 @@
 if rev is None:
 rev = self.rev(node)

-# check rev flags
-if self.flags(rev) & ~REVIDX_KNOWN_FLAGS:
-raise RevlogError(_('incompatible revision flag %x') %
-  (self.flags(rev) & ~REVIDX_KNOWN_FLAGS))
-
 chain, stopped = self._deltachain(rev, stoprev=cachedrev)
 if stopped:
 text = self._cache[2]
@@ -1221,7 +1222,11 @@
 bins = bins[1:]

 text = mdiff.patches(text, bins)
-self.checkhash(text, node, rev=rev)
+
+text, validatehash = self.processflags(text, self.flags(rev))
+if validatehash:
+self.checkhash(text, node, rev=rev)
+
 self._cache = (node, rev, text)
 return text

@@ -1233,6 +1238,45 @@
 """
 return hash(text, p1, p2)

+def