Re: [PATCH 2 of 2] phabricator: add a config knob for `phabsend --amend`

2018-05-17 Thread Matt Harbison

On Thu, 17 May 2018 07:51:31 -0400, Yuya Nishihara  wrote:


On Wed, 16 May 2018 23:03:59 -0400, Matt Harbison wrote:

# HG changeset patch
# User Matt Harbison 
# Date 1526525604 14400
#  Wed May 16 22:53:24 2018 -0400
# Node ID 8c2bbfe099b44820f8722e873852d6bd5811c111
# Parent  8003050dd9ee58fbc1eceda17aec5332830e9da2
phabricator: add a config knob for `phabsend --amend`

Since it's useful for certain workflows, it seems reasonable to not  
have to

remember to specify it.

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -93,6 +93,9 @@ configitem('phabricator', 'repophid',
 configitem('phabricator', 'url',
 default=None,
 )
+configitem('phabsend', 'amend',
+default=False,
+)
 configitem('phabsend', 'confirm',
 default=False,
 )
@@ -473,7 +476,12 @@ def phabsend(ui, repo, *revs, **opts):
 If --amend is set, update commit messages so they have the
 ``Differential Revision`` URL, remove related tags. This is  
similar to what
 arcanist will do, and is more desired in author-push workflows.  
Otherwise,

-use local tags to record the ``Differential Revision`` association.
+use local tags to record the ``Differential Revision``  
association. You
+can also add following to your configuration file to make it  
default

+behaviour::
+
+[phabsend]
+amend = true

 The --confirm option lets you confirm changesets before sending  
them. You
 can also add following to your configuration file to make it  
default

@@ -490,7 +498,8 @@ def phabsend(ui, repo, *revs, **opts):

 if not revs:
 raise error.Abort(_('phabsend requires at least one  
changeset'))

-if opts.get('amend'):
+amend = opts.get('amend') or ui.configbool('phabsend', 'amend')


Looks like --amend is on by default. We'll need a weird tri-state logic
to support --no-amend to override the config value.


Oops.  IDK what I was thinking.

I wonder if we should drop --amend, and just make it a config knob to  
avoid the tri-state.  But I'll wait on that until I get more experience  
using it.

___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH V2] phabricator: register config settings

2018-05-17 Thread Matt Harbison
# HG changeset patch
# User Matt Harbison 
# Date 1526525067 14400
#  Wed May 16 22:44:27 2018 -0400
# Node ID a2ed1f916bba51cb5d1fec26a97c9668810c6588
# Parent  a4a5c3085ea92402224ea4c61fccff3adbc715ec
phabricator: register config settings

I didn't bother registering the deprecated phabricator.auth.*, and I'm not sure
if the two flagged as 'developer config' should be moved to [devel] (or why
there's a distinction between `repophid` and `callsign`).

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -73,6 +73,30 @@ from mercurial.utils import (
 cmdtable = {}
 command = registrar.command(cmdtable)
 
+configtable = {}
+configitem = registrar.configitem(configtable)
+
+# developer config: phabricator.batchsize
+configitem('phabricator', 'batchsize',
+default=12,
+)
+configitem('phabricator', 'callsign',
+default=None,
+)
+configitem('phabricator', 'curlcmd',
+default=None,
+)
+# developer config: phabricator.repophid
+configitem('phabricator', 'repophid',
+default=None,
+)
+configitem('phabricator', 'url',
+default=None,
+)
+configitem('phabsend', 'confirm',
+default=False,
+)
+
 colortable = {
 'phabricator.action.created': 'green',
 'phabricator.action.skipped': 'magenta',
@@ -750,7 +774,7 @@ def querydrev(repo, spec):
 drevs, ancestordrevs = _prefetchdrevs(tree)
 
 # developer config: phabricator.batchsize
-batchsize = repo.ui.configint('phabricator', 'batchsize', 12)
+batchsize = repo.ui.configint('phabricator', 'batchsize')
 
 # Prefetch Differential Revisions in batch
 tofetch = set(drevs)
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3575: narrow: filter set of files to check for case-folding to core

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3575

AFFECTED FILES
  hgext/narrow/narrowmerge.py
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -903,6 +903,23 @@
 return actions
 
 def _checkcollision(repo, wmf, actions):
+"""
+Check for case-folding collisions.
+"""
+
+# If the repo is narrowed, filter out files outside the narrowspec.
+narrowmatch = repo.narrowmatch()
+if not narrowmatch.always():
+wmf = wmf.matches(narrowmatch)
+if actions:
+narrowactions = {}
+for m, actionsfortype in actions.iteritems():
+narrowactions[m] = []
+for (f, args, msg) in actionsfortype:
+if narrowmatch(f):
+narrowactions[m].append((f, args, msg))
+actions = narrowactions
+
 # build provisional merged manifest up
 pmmf = set(wmf)
 
diff --git a/hgext/narrow/narrowmerge.py b/hgext/narrow/narrowmerge.py
--- a/hgext/narrow/narrowmerge.py
+++ b/hgext/narrow/narrowmerge.py
@@ -10,26 +10,9 @@
 from mercurial import (
 copies,
 extensions,
-merge,
 )
 
 def setup():
-def _checkcollision(orig, repo, wmf, actions):
-narrowmatch = repo.narrowmatch()
-if not narrowmatch.always():
-wmf = wmf.matches(narrowmatch)
-if actions:
-narrowactions = {}
-for m, actionsfortype in actions.iteritems():
-narrowactions[m] = []
-for (f, args, msg) in actionsfortype:
-if narrowmatch(f):
-narrowactions[m].append((f, args, msg))
-actions = narrowactions
-return orig(repo, wmf, actions)
-
-extensions.wrapfunction(merge, '_checkcollision', _checkcollision)
-
 def _computenonoverlap(orig, repo, *args, **kwargs):
 u1, u2 = orig(repo, *args, **kwargs)
 narrowmatch = repo.narrowmatch()



To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3576: narrow: filter copies in core

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3576

AFFECTED FILES
  hgext/narrow/__init__.py
  hgext/narrow/narrowmerge.py
  mercurial/copies.py

CHANGE DETAILS

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -254,6 +254,11 @@
 repo.ui.debug("%s:\n   %s\n" % (header % 'local', "\n   ".join(u1)))
 if u2:
 repo.ui.debug("%s:\n   %s\n" % (header % 'other', "\n   ".join(u2)))
+
+narrowmatch = repo.narrowmatch()
+if not narrowmatch.always():
+u1 = [f for f in u1 if narrowmatch(f)]
+u2 = [f for f in u2 if narrowmatch(f)]
 return u1, u2
 
 def _makegetfctx(ctx):
diff --git a/hgext/narrow/narrowmerge.py b/hgext/narrow/narrowmerge.py
deleted file mode 100644
--- a/hgext/narrow/narrowmerge.py
+++ /dev/null
@@ -1,25 +0,0 @@
-# narrowmerge.py - extensions to mercurial merge module to support narrow 
clones
-#
-# Copyright 2017 Google, Inc.
-#
-# This software may be used and distributed according to the terms of the
-# GNU General Public License version 2 or any later version.
-
-from __future__ import absolute_import
-
-from mercurial import (
-copies,
-extensions,
-)
-
-def setup():
-def _computenonoverlap(orig, repo, *args, **kwargs):
-u1, u2 = orig(repo, *args, **kwargs)
-narrowmatch = repo.narrowmatch()
-if narrowmatch.always():
-return u1, u2
-
-u1 = [f for f in u1 if narrowmatch(f)]
-u2 = [f for f in u2 if narrowmatch(f)]
-return u1, u2
-extensions.wrapfunction(copies, '_computenonoverlap', _computenonoverlap)
diff --git a/hgext/narrow/__init__.py b/hgext/narrow/__init__.py
--- a/hgext/narrow/__init__.py
+++ b/hgext/narrow/__init__.py
@@ -29,7 +29,6 @@
 narrowcommands,
 narrowcopies,
 narrowdirstate,
-narrowmerge,
 narrowpatch,
 narrowrepo,
 narrowrevlog,
@@ -64,7 +63,6 @@
 localrepo.featuresetupfuncs.add(featuresetup)
 narrowrevlog.setup()
 narrowbundle2.setup()
-narrowmerge.setup()
 narrowcommands.setup()
 narrowchangegroup.setup()
 narrowwirepeer.uisetup()



To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3574: narrow: filter merge actions in core

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Part of the ongoing effort to move narrow into core.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3574

AFFECTED FILES
  hgext/narrow/narrowmerge.py
  mercurial/merge.py

CHANGE DETAILS

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -1072,6 +1072,33 @@
 repo.ui.warn(_("%s: is both a file and a directory\n") % p)
 raise error.Abort(_("destination manifest contains path conflicts"))
 
+def _filternarrowactions(narrowmatch, branchmerge, actions):
+"""
+Filters out actions that can ignored because the repo is narrowed.
+
+Raise an exception if the merge cannot be completed because the repo is
+narrowed.
+"""
+nooptypes = set(['k']) # TODO: handle with nonconflicttypes
+nonconflicttypes = set('a am c cm f g r e'.split())
+# We mutate the items in the dict during iteration, so iterate
+# over a copy.
+for f, action in list(actions.items()):
+if narrowmatch(f):
+pass
+elif not branchmerge:
+del actions[f] # just updating, ignore changes outside clone
+elif action[0] in nooptypes:
+del actions[f] # merge does not affect file
+elif action[0] in nonconflicttypes:
+raise error.Abort(_('merge affects file \'%s\' outside narrow, '
+'which is not yet supported') % f,
+  hint=_('merging in the other direction '
+ 'may work'))
+else:
+raise error.Abort(_('conflict in file \'%s\' is outside '
+'narrow clone') % f)
+
 def manifestmerge(repo, wctx, p2, pa, branchmerge, force, matcher,
   acceptremote, followcopies, forcefulldiff=False):
 """
@@ -1256,6 +1283,11 @@
 # If we are merging, look for path conflicts.
 checkpathconflicts(repo, wctx, p2, actions)
 
+narrowmatch = repo.narrowmatch()
+if not narrowmatch.always():
+# Updates "actions" in place
+_filternarrowactions(narrowmatch, branchmerge, actions)
+
 return actions, diverge, renamedelete
 
 def _resolvetrivial(repo, wctx, mctx, ancestor, actions):
diff --git a/hgext/narrow/narrowmerge.py b/hgext/narrow/narrowmerge.py
--- a/hgext/narrow/narrowmerge.py
+++ b/hgext/narrow/narrowmerge.py
@@ -7,48 +7,13 @@
 
 from __future__ import absolute_import
 
-from mercurial.i18n import _
 from mercurial import (
 copies,
-error,
 extensions,
 merge,
 )
 
 def setup():
-def _manifestmerge(orig, repo, wctx, p2, pa, branchmerge, *args, **kwargs):
-"""Filter updates to only lay out files that match the narrow spec."""
-actions, diverge, renamedelete = orig(
-repo, wctx, p2, pa, branchmerge, *args, **kwargs)
-
-narrowmatch = repo.narrowmatch()
-if narrowmatch.always():
-return actions, diverge, renamedelete
-
-nooptypes = set(['k']) # TODO: handle with nonconflicttypes
-nonconflicttypes = set('a am c cm f g r e'.split())
-# We mutate the items in the dict during iteration, so iterate
-# over a copy.
-for f, action in list(actions.items()):
-if narrowmatch(f):
-pass
-elif not branchmerge:
-del actions[f] # just updating, ignore changes outside clone
-elif action[0] in nooptypes:
-del actions[f] # merge does not affect file
-elif action[0] in nonconflicttypes:
-raise error.Abort(_('merge affects file \'%s\' outside narrow, 
'
-'which is not yet supported') % f,
-  hint=_('merging in the other direction '
- 'may work'))
-else:
-raise error.Abort(_('conflict in file \'%s\' is outside '
-'narrow clone') % f)
-
-return actions, diverge, renamedelete
-
-extensions.wrapfunction(merge, 'manifestmerge', _manifestmerge)
-
 def _checkcollision(orig, repo, wmf, actions):
 narrowmatch = repo.narrowmatch()
 if not narrowmatch.always():



To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 2] test-http-branchmap: fix stdio mode on Windows

2018-05-17 Thread Matt Harbison
On Sun, 13 May 2018 01:23:36 -0400, Matt Harbison   
wrote:



On Sat, 12 May 2018 22:27:15 -0400, Yuya Nishihara  wrote:


# HG changeset patch
# User Yuya Nishihara 
# Date 1526177393 -32400
#  Sun May 13 11:09:53 2018 +0900
# Node ID 74982ab8ca762a3cfe3648740dae27555232476b
# Parent  af07d426066dd8326c50a5686d7ecd25072d67b3
test-http-branchmap: fix stdio mode on Windows


Works for me, thanks.  I'll clean up the buildbot on Monday.


Gentle ping on this.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3573: hgweb: extract code for emitting multiple changelist records

2018-05-17 Thread indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  changelistentry() exists so extensions can easily monkeypatch the
  function to add additional metadata.
  
  In at least one case at Mozilla, we have an extension doing this
  where performance would greatly benefit if we were able to "batch
  fetch" metadata for all revisions that will eventually have their
  data set.
  
  By extracting the logic for "obtain records for N revisions" into
  a standalone function, we make it possible for a monkeypatched
  function to more efficiently bulk fetch data for N revisions.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3573

AFFECTED FILES
  mercurial/hgweb/webcommands.py
  mercurial/hgweb/webutil.py

CHANGE DETAILS

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -457,6 +457,22 @@
 )
 return entry
 
+def changelistentries(web, revs, maxcount, parityfn):
+"""Emit up to N records for an iterable of revisions."""
+repo = web.repo
+
+count = 0
+for rev in revs:
+if count >= maxcount:
+break
+
+count += 1
+
+entry = changelistentry(web, repo[rev])
+entry['parity'] = next(parityfn)
+
+yield entry
+
 def symrevorshortnode(req, ctx):
 if 'node' in req.qsparams:
 return templatefilters.revescape(req.qsparams['node'])
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -398,14 +398,8 @@
 revs = []
 if pos != -1:
 revs = web.repo.changelog.revs(pos, 0)
-curcount = 0
-for rev in revs:
-curcount += 1
-if curcount > revcount + 1:
-break
 
-entry = webutil.changelistentry(web, web.repo[rev])
-entry['parity'] = next(parity)
+for entry in webutil.changelistentries(web, revs, revcount, parity):
 yield entry
 
 if shortlog:



To: indygreg, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH] test-merge-tools: create repo directory to free $TESTTMP for temporary files

2018-05-17 Thread Pulkit Goyal
On Thu, May 17, 2018 at 6:46 PM Yuya Nishihara  wrote:

> # HG changeset patch
> # User Yuya Nishihara 
> # Date 1526561700 -32400
> #  Thu May 17 21:55:00 2018 +0900
> # Node ID a4a5c3085ea92402224ea4c61fccff3adbc715ec
> # Parent  d1134ca5b1a3a3f7d06c5bef4f16fc30f2642ea4
> test-merge-tools: create repo directory to free $TESTTMP for temporary
> files
>

​Queued this patch. Many thanks!​
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3556: run-tests: update the test case name format

2018-05-17 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  Getting this test failure at the tip of hg-committed with this series 
applied, can you have a look?
  
--- /home/foobar/repo/pushaccess/tests/test-run-tests.t
+++ /home/foobar/repo/pushaccess/tests/test-run-tests.t.err
@@ -1634,9 +1634,24 @@
#endif
   
   ERROR: test-cases-abc.t#B output changed
-  !
+  !.
+  --- $TESTTMP/anothertests/cases/test-cases-abc.t
+  +++ $TESTTMP/anothertests/cases/test-cases-abc.t.B.err
+  @@ -7,7 +7,7 @@
+ $ V=C
+   #endif
+ $ echo $V | sed 's/A/C/'
+  -  C
+  +  B
+   #if C
+ $ [ $V = C ]
+   #endif
+  
+  ERROR: test-cases-abc.t#B output changed
+  !.
   Failed test-cases-abc.t#B: output changed
-  # Ran 1 tests, 0 skipped, 1 failed.
+  Failed test-cases-abc.t#B: output changed
+  # Ran 4 tests, 0 skipped, 2 failed.
   python hash seed: * (glob)
   [1]
 

ERROR: test-run-tests.t output changed

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3556

To: lothiraldan, #hg-reviewers, quark, pulkit
Cc: quark, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH] filemerge: support specfiying a python function to custom merge-tools

2018-05-17 Thread Tom Hindle

On 05/17/2018 07:14 AM, Yuya Nishihara wrote:

On Wed, 16 May 2018 14:22:13 -0600, tom_hin...@sil.org wrote:

# HG changeset patch
# User hindlemail

Can you suggest a proper "user" name?
test-check-commit.t complains that "username is not an email address."


oops sorry. My Username should have been set to:

hindlemail 

(But on the Linux machine, I was running tests on I had just set it to 
hindlemail)





# Date 1526501501 21600
#  Wed May 16 14:11:41 2018 -0600
# Node ID 7e7e8dd8e70bbba7cca9a5f17371697c159e6b14
# Parent  0fa050bc68cb7a3bfb67390f2a84ff1c7efa9778
filemerge: support specfiying a python function to custom merge-tools

Queued, thanks. I'll push this when all blockers are gone.


@@ -551,12 +559,36 @@
  args = util.interpolate(
  br'\$', replace, args,
  lambda s: procutil.shellquote(util.localpath(s)))
-cmd = toolpath + ' ' + args
  if _toolbool(ui, tool, "gui"):
  repo.ui.status(_('running merge tool %s for file %s\n') %
 (tool, fcd.path()))
-repo.ui.debug('launching merge tool: %s\n' % cmd)
-r = ui.system(cmd, cwd=repo.root, environ=env, blockedtag='mergetool')
+if scriptfn is None:
+cmd = toolpath + ' ' + args
+repo.ui.debug('launching merge tool: %s\n' % cmd)
+r = ui.system(cmd, cwd=repo.root, environ=env,
+  blockedtag='mergetool')
+else:
+repo.ui.debug('launching python merge script: %s:%s\n' %
+  (toolpath, scriptfn))
+r = 0
+try:
+# avoid cycle cmdutil->merge->filemerge->extensions->cmdutil
+from . import extensions
+mod = extensions.loadpath(toolpath, 'hgmerge.%s' % scriptfn)

Nit: 'hgmerge.%s' should be a module name, not a function name. Perhaps
'hgmerge.%s' % tool is more correct.

Can you send a follow-up patch once this patch gets pushed?

Yes will do.




+except Exception:
+raise error.Abort(_("loading python merge script failed: %s") %
+ toolpath)
+mergefn = getattr(mod, scriptfn, None)
+if mergefn is None:
+raise error.Abort(_("%s does not have function: %s") %
+  (toolpath, scriptfn))
+argslist = procutil.shellsplit(args)

Strictly speaking, shellsplit() should be avoided as possible. It's a
best-effort function mainly for debugging aids.

As I said before, an alternative approach is to pass parameters as key-value
dict, and ban the use of .args template.


I will look removing procutil.shellsplit.




+# avoid cycle cmdutil->merge->filemerge->hook->extensions->cmdutil
+from . import hook
+ret, raised = hook.pythonhook(ui, repo, "merge", toolpath,
+  mergefn, {'args' : argslist}, True)
+if raised:
+r = 1

When throw=True, hook.pythonhook() would raise exception instead of returning
"raised" value. If throw were False, int(ret) should be copied to r. Which one
did you expect?
I changed this from False -> True, as (iirc) it gave better stack traces 
when python function had errors.

Shall I deal with this in a follow-up patch?




diff -r 0fa050bc68cb -r 7e7e8dd8e70b tests/test-merge-tools.t
--- a/tests/test-merge-tools.t  Sat May 12 00:34:01 2018 -0400
+++ b/tests/test-merge-tools.t  Wed May 16 14:11:41 2018 -0600
@@ -328,6 +328,183 @@
# hg resolve --list
R f
  
+executable set to python script that succeeds:

+
+  $ cat > /tmp/myworkingmerge.py <
Replaced all /tmp with "$TESTTMP/".

Can you add some tests to check that args are passed correctly?


Yes I will send in a follow-up patch.

Thanks!

___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3572: state: don't have a dict like interface for cmdstate class

2018-05-17 Thread pulkit (Pulkit Goyal)
pulkit added inline comments.

INLINE COMMENTS

> martinvonz wrote in state.py:59-63
> Is this a direct consequence of removing the dict interface or could it be 
> split out into a separate patch?

I will split it into a separate patch.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3572

To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2591: state: import the file to write state files from evolve extension

2018-05-17 Thread pulkit (Pulkit Goyal)
pulkit added inline comments.

INLINE COMMENTS

> martinvonz wrote in state.py:79
> Looks like you missed this. (If you didn't and you simply disagree, please 
> explain why you disagree.)

I just simply missed it.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2591

To: pulkit, #hg-reviewers, indygreg
Cc: yuja, indygreg, martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2591: state: import the file to write state files from evolve extension

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
martinvonz added inline comments.

INLINE COMMENTS

> indygreg wrote in state.py:79
> We probably want `canonical=True` here so behavior is deterministic. All that 
> does in reality is sort dicts and sets. I doubt we have any data structures 
> large enough for this to be a problem.

Looks like you missed this. (If you didn't and you simply disagree, please 
explain why you disagree.)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2591

To: pulkit, #hg-reviewers, indygreg
Cc: yuja, indygreg, martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3572: state: don't have a dict like interface for cmdstate class

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
martinvonz added inline comments.

INLINE COMMENTS

> state.py:59-63
> +try:
> +iv = int(version)
> +except ValueError:
> +raise error.ProgrammingError("version of state file should be"
> + " an integer")

Is this a direct consequence of removing the dict interface or could it be 
split out into a separate patch?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3572

To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[Bug 5888] New: Send both patch and hg bundle as multipart/alternative

2018-05-17 Thread mercurial-bugs
https://bz.mercurial-scm.org/show_bug.cgi?id=5888

Bug ID: 5888
   Summary: Send both patch and hg bundle as multipart/alternative
   Product: Mercurial
   Version: 4.6
  Hardware: PC
OS: Linux
Status: UNCONFIRMED
  Severity: feature
  Priority: wish
 Component: patchbomb
  Assignee: bugzi...@mercurial-scm.org
  Reporter: z...@zash.se
CC: mercurial-devel@mercurial-scm.org

Problem:
Importing patches can sometimes be lossy for various reasons, while hg bundles
are not.
However, hg bundles are opaque and tricker to integrate with tooling such as
patchwork, or plain in-line replying from email clients.

Potential improvement:
Send a MIME multipart/alternative container, with the plain text patch as one
part and the hg bundle as the other.
Assuming tooling capable of recursing into MIME containers, one should be able
to get the benefits of both patch submission methods at the cost of a larger
email size.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH] test-merge-tools: create repo directory to free $TESTTMP for temporary files

2018-05-17 Thread Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara 
# Date 1526561700 -32400
#  Thu May 17 21:55:00 2018 +0900
# Node ID a4a5c3085ea92402224ea4c61fccff3adbc715ec
# Parent  d1134ca5b1a3a3f7d06c5bef4f16fc30f2642ea4
test-merge-tools: create repo directory to free $TESTTMP for temporary files

diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t
--- a/tests/test-merge-tools.t
+++ b/tests/test-merge-tools.t
@@ -1,7 +1,8 @@
 test merge-tools configuration - mostly exercising filemerge.py
 
   $ unset HGMERGE # make sure HGMERGE doesn't interfere with the test
-  $ hg init
+  $ hg init repo
+  $ cd repo
 
 revision 0
 
@@ -1446,7 +1447,7 @@ premerge=keep is used and has 'detailed'
   merging f
   labellocal: "working copy"
   labelother: "merge rev"
-  output (arg): "$TESTTMP/f"
+  output (arg): "$TESTTMP/repo/f"
   output (contents):
   <<< working copy: uitmpl 1
   revision 1
@@ -1485,7 +1486,7 @@ mergemarkers=detailed; labellocal and la
   merging f
   labellocal: "working copy: tooltmpl ef83787e2614"
   labelother: "merge rev: tooltmpl 0185f4e0cf02"
-  output (arg): "$TESTTMP/f"
+  output (arg): "$TESTTMP/repo/f"
   output (contents):
   <<< working copy: tooltmpl ef83787e2614
   revision 1
@@ -1585,7 +1586,7 @@ Verify naming of temporary files and tha
   $ hg update -q -C 2
   $ hg merge -y -r tip --tool echo --config merge-tools.echo.args='$base 
$local $other $output'
   merging f and f.txt to f.txt
-  */f~base.* */f~local.*.txt */f~other.*.txt $TESTTMP/f.txt (glob)
+  */f~base.* */f~local.*.txt */f~other.*.txt $TESTTMP/repo/f.txt (glob)
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
 
@@ -1600,7 +1601,7 @@ Verify naming of temporary files and tha
   >--config merge-tools.echo.args='$base $local $other $output' \
   >--config experimental.mergetempdirprefix=$TESTTMP/hgmerge.
   merging f and f.txt to f.txt
-  $TESTTMP/hgmerge.*/f~base $TESTTMP/hgmerge.*/f~local.txt 
$TESTTMP/hgmerge.*/f~other.txt $TESTTMP/f.txt (glob)
+  $TESTTMP/hgmerge.*/f~base $TESTTMP/hgmerge.*/f~local.txt 
$TESTTMP/hgmerge.*/f~other.txt $TESTTMP/repo/f.txt (glob)
   0 files updated, 1 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
 
@@ -1668,3 +1669,5 @@ specified file as expected
   couldn't find merge tool true (for pattern f)
   couldn't find merge tool true
   f = false
+
+  $ cd ..
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH] filemerge: support specfiying a python function to custom merge-tools

2018-05-17 Thread Yuya Nishihara
On Wed, 16 May 2018 14:22:13 -0600, tom_hin...@sil.org wrote:
> # HG changeset patch
> # User hindlemail

Can you suggest a proper "user" name?
test-check-commit.t complains that "username is not an email address."

> # Date 1526501501 21600
> #  Wed May 16 14:11:41 2018 -0600
> # Node ID 7e7e8dd8e70bbba7cca9a5f17371697c159e6b14
> # Parent  0fa050bc68cb7a3bfb67390f2a84ff1c7efa9778
> filemerge: support specfiying a python function to custom merge-tools

Queued, thanks. I'll push this when all blockers are gone.

> @@ -551,12 +559,36 @@
>  args = util.interpolate(
>  br'\$', replace, args,
>  lambda s: procutil.shellquote(util.localpath(s)))
> -cmd = toolpath + ' ' + args
>  if _toolbool(ui, tool, "gui"):
>  repo.ui.status(_('running merge tool %s for file %s\n') %
> (tool, fcd.path()))
> -repo.ui.debug('launching merge tool: %s\n' % cmd)
> -r = ui.system(cmd, cwd=repo.root, environ=env, 
> blockedtag='mergetool')
> +if scriptfn is None:
> +cmd = toolpath + ' ' + args
> +repo.ui.debug('launching merge tool: %s\n' % cmd)
> +r = ui.system(cmd, cwd=repo.root, environ=env,
> +  blockedtag='mergetool')
> +else:
> +repo.ui.debug('launching python merge script: %s:%s\n' %
> +  (toolpath, scriptfn))
> +r = 0
> +try:
> +# avoid cycle cmdutil->merge->filemerge->extensions->cmdutil
> +from . import extensions
> +mod = extensions.loadpath(toolpath, 'hgmerge.%s' % scriptfn)

Nit: 'hgmerge.%s' should be a module name, not a function name. Perhaps
'hgmerge.%s' % tool is more correct.

Can you send a follow-up patch once this patch gets pushed?

> +except Exception:
> +raise error.Abort(_("loading python merge script failed: 
> %s") %
> + toolpath)
> +mergefn = getattr(mod, scriptfn, None)
> +if mergefn is None:
> +raise error.Abort(_("%s does not have function: %s") %
> +  (toolpath, scriptfn))
> +argslist = procutil.shellsplit(args)

Strictly speaking, shellsplit() should be avoided as possible. It's a
best-effort function mainly for debugging aids.

As I said before, an alternative approach is to pass parameters as key-value
dict, and ban the use of .args template.

> +# avoid cycle 
> cmdutil->merge->filemerge->hook->extensions->cmdutil
> +from . import hook
> +ret, raised = hook.pythonhook(ui, repo, "merge", toolpath,
> +  mergefn, {'args' : argslist}, True)
> +if raised:
> +r = 1

When throw=True, hook.pythonhook() would raise exception instead of returning
"raised" value. If throw were False, int(ret) should be copied to r. Which one
did you expect?

> diff -r 0fa050bc68cb -r 7e7e8dd8e70b tests/test-merge-tools.t
> --- a/tests/test-merge-tools.tSat May 12 00:34:01 2018 -0400
> +++ b/tests/test-merge-tools.tWed May 16 14:11:41 2018 -0600
> @@ -328,6 +328,183 @@
># hg resolve --list
>R f
>  
> +executable set to python script that succeeds:
> +
> +  $ cat > /tmp/myworkingmerge.py 

D3553: notify: add option to include function names in the diff output

2018-05-17 Thread yuja (Yuya Nishihara)
yuja added a comment.


  Queued, thanks.
  
  > +  $ hg commit -m changefunction
  >  +  $ hg --cwd ../b --config notify.show-functions=True pull ../a
  
  s/show-functions/showfunc/

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3553

To: joerg.sonnenberger, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3569: py3: convert the report to bytes

2018-05-17 Thread pulkit (Pulkit Goyal)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5046c906b25d: py3: convert the report to bytes (authored by 
pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3569?vs=8719=8723

REVISION DETAIL
  https://phab.mercurial-scm.org/D3569

AFFECTED FILES
  mercurial/dispatch.py

CHANGE DETAILS

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -1028,7 +1028,7 @@
  '** which supports versions %s of Mercurial.\n'
  '** Please disable %s and try your action again.\n'
  '** If that fixes the bug please report it to %s\n')
-   % (name, testedwith, name, report))
+   % (name, testedwith, name, stringutil.forcebytestr(report)))
 else:
 bugtracker = ui.config('ui', 'supportcontact')
 if bugtracker is None:



To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3571: tests: test-parseindex.t works just fine with chg

2018-05-17 Thread spectral (Kyle Lippincott)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGca890999d317: tests: test-parseindex.t works just fine with 
chg (authored by spectral, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3571?vs=8720=8724

REVISION DETAIL
  https://phab.mercurial-scm.org/D3571

AFFECTED FILES
  tests/test-parseindex.t

CHANGE DETAILS

diff --git a/tests/test-parseindex.t b/tests/test-parseindex.t
--- a/tests/test-parseindex.t
+++ b/tests/test-parseindex.t
@@ -1,5 +1,3 @@
-#require no-chg
-
 revlog.parseindex must be able to parse the index file even if
 an index entry is split between two 64k blocks.  The ideal test
 would be to create an index file with inline data where



To: spectral, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3553: notify: add option to include function names in the diff output

2018-05-17 Thread joerg.sonnenberger (Joerg Sonnenberger)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGd1134ca5b1a3: notify: add option to include function names 
in the diff output (authored by joerg.sonnenberger, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D3553?vs=8715=8726#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3553?vs=8715=8726

REVISION DETAIL
  https://phab.mercurial-scm.org/D3553

AFFECTED FILES
  hgext/notify.py
  tests/test-notify.t

CHANGE DETAILS

diff --git a/tests/test-notify.t b/tests/test-notify.t
--- a/tests/test-notify.t
+++ b/tests/test-notify.t
@@ -131,6 +131,9 @@
   notify.diffstat
 Set to True to include a diffstat before diff content. Default: True.
   
+  notify.showfunc
+If set, override "diff.showfunc" for the diff content. Default: None.
+  
   notify.merge
 If True, send notifications for merge changesets. Default: True.
   
@@ -647,3 +650,99 @@
   To: b...@test.com, foo@bar
   
   with template
+
+showfunc diff
+  $ cat <> $HGRCPATH
+  > showfunc = True
+  > template =
+  > maxdiff = -1
+  > EOF
+  $ cd a
+  $ cat > f1 << EOF
+  > int main() {
+  > int a = 0;
+  > int b = 1;
+  > int c = 2;
+  > int d = 3;
+  > return a + b + c + d;
+  > }
+  > EOF
+  $ hg commit -Am addfunction
+  adding f1
+  $ hg --cwd ../b pull ../a
+  pulling from ../a
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  new changesets b86bc16ff894
+  MIME-Version: 1.0
+  Content-Type: text/plain; charset="us-ascii"
+  Content-Transfer-Encoding: 7bit
+  Date: * (glob)
+  Subject: addfunction
+  From: t...@test.com
+  X-Hg-Notification: changeset b86bc16ff894
+  Message-Id:  (glob)
+  To: b...@test.com, foo@bar
+  
+  changeset b86bc16ff894
+  diffs (11 lines):
+  
+  diff -r 14721b538ae3 -r b86bc16ff894 f1
+  --- /dev/nullThu Jan 01 00:00:00 1970 +
+  +++ b/f1 Thu Jan 01 00:00:00 1970 +
+  @@ -0,0 +1,7 @@
+  +int main() {
+  +int a = 0;
+  +int b = 1;
+  +int c = 2;
+  +int d = 3;
+  +return a + b + c + d;
+  +}
+  (run 'hg update' to get a working copy)
+  $ cat > f1 << EOF
+  > int main() {
+  > int a = 0;
+  > int b = 1;
+  > int c = 2;
+  > int e = 3;
+  > return a + b + c + e;
+  > }
+  > EOF
+  $ hg commit -m changefunction
+  $ hg --cwd ../b --config notify.showfunc=True pull ../a
+  pulling from ../a
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  new changesets e81040e9838c
+  MIME-Version: 1.0
+  Content-Type: text/plain; charset="us-ascii"
+  Content-Transfer-Encoding: 7bit
+  Date: * (glob)
+  Subject: changefunction
+  From: t...@test.com
+  X-Hg-Notification: changeset e81040e9838c
+  Message-Id:  (glob)
+  To: b...@test.com, foo@bar
+  
+  changeset e81040e9838c
+  diffs (12 lines):
+  
+  diff -r b86bc16ff894 -r e81040e9838c f1
+  --- a/f1 Thu Jan 01 00:00:00 1970 +
+  +++ b/f1 Thu Jan 01 00:00:00 1970 +
+  @@ -2,6 +2,6 @@ int main() {
+   int a = 0;
+   int b = 1;
+   int c = 2;
+  -int d = 3;
+  -return a + b + c + d;
+  +int e = 3;
+  +return a + b + c + e;
+   }
+  (run 'hg update' to get a working copy)
diff --git a/hgext/notify.py b/hgext/notify.py
--- a/hgext/notify.py
+++ b/hgext/notify.py
@@ -113,6 +113,9 @@
 notify.diffstat
   Set to True to include a diffstat before diff content. Default: True.
 
+notify.showfunc
+  If set, override ``diff.showfunc`` for the diff content. Default: None.
+
 notify.merge
   If True, send notifications for merge changesets. Default: True.
 
@@ -206,6 +209,9 @@
 configitem('notify', 'sources',
 default='serve',
 )
+configitem('notify', 'showfunc',
+default=None,
+)
 configitem('notify', 'strip',
 default=0,
 )
@@ -260,6 +266,9 @@
 self.charsets = mail._charsets(self.ui)
 self.subs = self.subscribers()
 self.merge = self.ui.configbool('notify', 'merge')
+self.showfunc = self.ui.configbool('notify', 'showfunc')
+if self.showfunc is None:
+self.showfunc = self.ui.configbool('diff', 'showfunc')
 
 mapfile = None
 template = (self.ui.config('notify', hooktype) or
@@ -420,8 +429,9 @@
 ref = ref.node()
 else:
 ref = ctx.node()
-chunks = patch.diff(self.repo, prev, ref,
-opts=patch.diffallopts(self.ui))
+diffopts = patch.diffallopts(self.ui)
+diffopts.showfunc = self.showfunc
+chunks = patch.diff(self.repo, prev, ref, opts=diffopts)
 difflines = ''.join(chunks).splitlines()
 
 if self.ui.configbool('notify', 'diffstat'):



To: joerg.sonnenberger, #hg-reviewers
Cc: yuja, mercurial-devel
___

Re: D3553: notify: add option to include function names in the diff output

2018-05-17 Thread Yuya Nishihara
Queued, thanks.

> +  $ hg commit -m changefunction
> +  $ hg --cwd ../b --config notify.show-functions=True pull ../a

s/show-functions/showfunc/
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3536: json: reject unicode on py2 as well

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf5a1aa8c6987: json: reject unicode on py2 as well (authored 
by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3536?vs=8717=8722

REVISION DETAIL
  https://phab.mercurial-scm.org/D3536

AFFECTED FILES
  mercurial/templatefilters.py

CHANGE DETAILS

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -249,13 +249,9 @@
 return pycompat.bytestr(obj)
 elif isinstance(obj, bytes):
 return '"%s"' % encoding.jsonescape(obj, paranoid=paranoid)
-elif isinstance(obj, str):
-# This branch is unreachable on Python 2, because bytes == str
-# and we'll return in the next-earlier block in the elif
-# ladder. On Python 3, this helps us catch bugs before they
-# hurt someone.
+elif isinstance(obj, type(u'')):
 raise error.ProgrammingError(
-'Mercurial only does output with bytes on Python 3: %r' % obj)
+'Mercurial only does output with bytes: %r' % obj)
 elif util.safehasattr(obj, 'keys'):
 out = ['"%s": %s' % (encoding.jsonescape(k, paranoid=paranoid),
  json(v, paranoid))



To: martinvonz, #hg-reviewers, indygreg
Cc: yuja, indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3570: tests: update py3 test since json fields are now sorted

2018-05-17 Thread martinvonz (Martin von Zweigbergk)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1b8238f67bf2: tests: update py3 test since json fields are 
now sorted (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3570?vs=8716=8725

REVISION DETAIL
  https://phab.mercurial-scm.org/D3570

AFFECTED FILES
  tests/test-py3-commands.t

CHANGE DETAILS

diff --git a/tests/test-py3-commands.t b/tests/test-py3-commands.t
--- a/tests/test-py3-commands.t
+++ b/tests/test-py3-commands.t
@@ -198,28 +198,28 @@
   $ $PYTHON3 $HGBIN log -Tjson
   [
{
-"rev": 1,
-"node": "e1e9167203d450ca2f558af628955b5f5afd4489",
+"bookmarks": [],
 "branch": "default",
-"phase": "draft",
-"user": "test",
 "date": [0, 0],
 "desc": "message",
-"bookmarks": [],
+"node": "e1e9167203d450ca2f558af628955b5f5afd4489",
+"parents": ["71c96e924262969ff0d8d3d695b0f75412ccc3d8"],
+"phase": "draft",
+"rev": 1,
 "tags": ["tip"],
-"parents": ["71c96e924262969ff0d8d3d695b0f75412ccc3d8"]
+"user": "test"
},
{
-"rev": 0,
-"node": "71c96e924262969ff0d8d3d695b0f75412ccc3d8",
+"bookmarks": [],
 "branch": "default",
-"phase": "draft",
-"user": "test",
 "date": [0, 0],
 "desc": "commit performed in Python 3",
-"bookmarks": [],
+"node": "71c96e924262969ff0d8d3d695b0f75412ccc3d8",
+"parents": [""],
+"phase": "draft",
+"rev": 0,
 "tags": [],
-"parents": [""]
+"user": "test"
}
   ]
 



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2591: state: import the file to write state files from evolve extension

2018-05-17 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  @martinvonz @yuja I am trying to get this series reviewed in pieces. This one 
and it's child https://phab.mercurial-scm.org/D3572 is ready for review.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2591

To: pulkit, #hg-reviewers, indygreg
Cc: yuja, indygreg, martinvonz, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3572: state: don't have a dict like interface for cmdstate class

2018-05-17 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This patch changes the cmdstate class to stop having a dict like interface and
  delete the __nonzero__ function. After this patch, the save fuction takes a 
dict
  to store the data and read function returns a dict of the data stored.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3572

AFFECTED FILES
  mercurial/state.py

CHANGE DETAILS

diff --git a/mercurial/state.py b/mercurial/state.py
--- a/mercurial/state.py
+++ b/mercurial/state.py
@@ -46,42 +46,35 @@
 """
 self._repo = repo
 self.fname = fname
-if not opts:
-self.opts = {}
-else:
-self.opts = opts
-
-def __nonzero__(self):
-return self.exists()
-
-def __getitem__(self, key):
-return self.opts[key]
 
-def __setitem__(self, key, value):
-updates = {key: value}
-self.opts.update(updates)
+def read(self):
+"""read the existing state file and return a dict of data stored"""
+return self._read()
 
-def load(self):
-"""load the existing state file into the class object"""
-op = self._read()
-self.opts.update(op)
-
-def addopts(self, opts):
-"""add more key-value pairs to the data stored by the object"""
-self.opts.update(opts)
-
-def save(self):
+def save(self, version, data):
 """write all the state data stored to .hg/ file
 
 we use third-party library cbor to serialize data to write in the file.
 """
+try:
+iv = int(version)
+except ValueError:
+raise error.ProgrammingError("version of state file should be"
+ " an integer")
+
 with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp:
+fp.write('%d\n' % iv)
 cbor.dump(self.opts, fp)
 
 def _read(self):
 """reads the state file and returns a dictionary which contain
 data in the same format as it was before storing"""
 with self._repo.vfs(self.fname, 'rb') as fp:
+try:
+version = int(fp.readline())
+except ValueError:
+raise error.ProgrammingError("unknown version of state file"
+ " found")
 return cbor.load(fp)
 
 def delete(self):



To: pulkit, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel