D663: dirstate: perform transactions with _map using single call, where possible

2017-09-15 Thread mbolin (Michael Bolin)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG6d734a3a76e2: dirstate: perform transactions with _map 
using single call, where possible (authored by mbolin, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D663?vs=1817&id=1842

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -550,7 +550,8 @@
 for d in util.finddirs(f):
 if d in self._dirs:
 break
-if d in self._map and self[d] != 'r':
+entry = self._map.get(d)
+if entry is not None and entry[0] != 'r':
 raise error.Abort(
 _('file %r in dirstate clashes with %r') % (d, f))
 if oldstate in "?r" and "_dirs" in self.__dict__:
@@ -580,22 +581,23 @@
 
 def normallookup(self, f):
 '''Mark a file normal, but possibly dirty.'''
-if self._pl[1] != nullid and f in self._map:
+if self._pl[1] != nullid:
 # if there is a merge going on and the file was either
 # in state 'm' (-1) or coming from other parent (-2) before
 # being removed, restore that state.
-entry = self._map[f]
-if entry[0] == 'r' and entry[2] in (-1, -2):
-source = self._copymap.get(f)
-if entry[2] == -1:
-self.merge(f)
-elif entry[2] == -2:
-self.otherparent(f)
-if source:
-self.copy(source, f)
-return
-if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
-return
+entry = self._map.get(f)
+if entry is not None:
+if entry[0] == 'r' and entry[2] in (-1, -2):
+source = self._copymap.get(f)
+if entry[2] == -1:
+self.merge(f)
+elif entry[2] == -2:
+self.otherparent(f)
+if source:
+self.copy(source, f)
+return
+if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
+return
 self._addpath(f, 'n', 0, -1, -1)
 self._copymap.pop(f, None)
 if f in self._nonnormalset:
@@ -624,14 +626,15 @@
 self._dirty = True
 self._droppath(f)
 size = 0
-if self._pl[1] != nullid and f in self._map:
-# backup the previous state
-entry = self._map[f]
-if entry[0] == 'm': # merge
-size = -1
-elif entry[0] == 'n' and entry[2] == -2: # other parent
-size = -2
-self._otherparentset.add(f)
+if self._pl[1] != nullid:
+entry = self._map.get(f)
+if entry is not None:
+# backup the previous state
+if entry[0] == 'm': # merge
+size = -1
+elif entry[0] == 'n' and entry[2] == -2: # other parent
+size = -2
+self._otherparentset.add(f)
 self._map[f] = dirstatetuple('r', 0, size, 0)
 self._nonnormalset.add(f)
 if size == 0:



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


D663: dirstate: perform transactions with _map using single call, where possible

2017-09-15 Thread yuja (Yuya Nishihara)
yuja accepted this revision.
yuja added a comment.
This revision is now accepted and ready to land.


  Queued, thanks.

REPOSITORY
  rHG Mercurial

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

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


D663: dirstate: perform transactions with _map using single call, where possible

2017-09-14 Thread mbolin (Michael Bolin)
mbolin added inline comments.

INLINE COMMENTS

> yuja wrote in dirstate.py:554
> test-add.t fails here. It was `self[d]`, not `self._map[d]`.

My bad: fixed without bringing the extra lookup back.

REPOSITORY
  rHG Mercurial

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

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


D663: dirstate: perform transactions with _map using single call, where possible

2017-09-14 Thread mbolin (Michael Bolin)
mbolin updated this revision to Diff 1817.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D663?vs=1687&id=1817

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -550,7 +550,8 @@
 for d in util.finddirs(f):
 if d in self._dirs:
 break
-if d in self._map and self[d] != 'r':
+entry = self._map.get(d)
+if entry is not None and entry[0] != 'r':
 raise error.Abort(
 _('file %r in dirstate clashes with %r') % (d, f))
 if oldstate in "?r" and "_dirs" in self.__dict__:
@@ -580,22 +581,23 @@
 
 def normallookup(self, f):
 '''Mark a file normal, but possibly dirty.'''
-if self._pl[1] != nullid and f in self._map:
+if self._pl[1] != nullid:
 # if there is a merge going on and the file was either
 # in state 'm' (-1) or coming from other parent (-2) before
 # being removed, restore that state.
-entry = self._map[f]
-if entry[0] == 'r' and entry[2] in (-1, -2):
-source = self._copymap.get(f)
-if entry[2] == -1:
-self.merge(f)
-elif entry[2] == -2:
-self.otherparent(f)
-if source:
-self.copy(source, f)
-return
-if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
-return
+entry = self._map.get(f)
+if entry is not None:
+if entry[0] == 'r' and entry[2] in (-1, -2):
+source = self._copymap.get(f)
+if entry[2] == -1:
+self.merge(f)
+elif entry[2] == -2:
+self.otherparent(f)
+if source:
+self.copy(source, f)
+return
+if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
+return
 self._addpath(f, 'n', 0, -1, -1)
 self._copymap.pop(f, None)
 if f in self._nonnormalset:
@@ -624,14 +626,15 @@
 self._dirty = True
 self._droppath(f)
 size = 0
-if self._pl[1] != nullid and f in self._map:
-# backup the previous state
-entry = self._map[f]
-if entry[0] == 'm': # merge
-size = -1
-elif entry[0] == 'n' and entry[2] == -2: # other parent
-size = -2
-self._otherparentset.add(f)
+if self._pl[1] != nullid:
+entry = self._map.get(f)
+if entry is not None:
+# backup the previous state
+if entry[0] == 'm': # merge
+size = -1
+elif entry[0] == 'n' and entry[2] == -2: # other parent
+size = -2
+self._otherparentset.add(f)
 self._map[f] = dirstatetuple('r', 0, size, 0)
 self._nonnormalset.add(f)
 if size == 0:



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


D663: dirstate: perform transactions with _map using single call, where possible

2017-09-13 Thread yuja (Yuya Nishihara)
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> dirstate.py:554
> +entry = self._map.get(d)
> +if entry is not None and entry != 'r':
>  raise error.Abort(

test-add.t fails here. It was `self[d]`, not `self._map[d]`.

REPOSITORY
  rHG Mercurial

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

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


D663: dirstate: perform transactions with _map using single call, where possible

2017-09-10 Thread phillco (Phil Cohen)
phillco accepted this revision.
phillco added a comment.


  These look good to me.

INLINE COMMENTS

> dirstate.py:585-587
>  # if there is a merge going on and the file was either
>  # in state 'm' (-1) or coming from other parent (-2) before
>  # being removed, restore that state.

Possibly move this comment to just above line 590?

REPOSITORY
  rHG Mercurial

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

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


D663: dirstate: perform transactions with _map using single call, where possible

2017-09-08 Thread mbolin (Michael Bolin)
mbolin created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is in the same style as https://phab.mercurial-scm.org/D493.
  
  In general, this replaces patterns such as:
  
f in self._map:
entry = self._map[f]
  
  with:
  
entry = self._map.get(f):
if entry is not None:
# use entry

TEST PLAN
  `make tests`

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/dirstate.py

CHANGE DETAILS

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -550,7 +550,8 @@
 for d in util.finddirs(f):
 if d in self._dirs:
 break
-if d in self._map and self[d] != 'r':
+entry = self._map.get(d)
+if entry is not None and entry != 'r':
 raise error.Abort(
 _('file %r in dirstate clashes with %r') % (d, f))
 if oldstate in "?r" and "_dirs" in self.__dict__:
@@ -580,22 +581,23 @@
 
 def normallookup(self, f):
 '''Mark a file normal, but possibly dirty.'''
-if self._pl[1] != nullid and f in self._map:
+if self._pl[1] != nullid:
 # if there is a merge going on and the file was either
 # in state 'm' (-1) or coming from other parent (-2) before
 # being removed, restore that state.
-entry = self._map[f]
-if entry[0] == 'r' and entry[2] in (-1, -2):
-source = self._copymap.get(f)
-if entry[2] == -1:
-self.merge(f)
-elif entry[2] == -2:
-self.otherparent(f)
-if source:
-self.copy(source, f)
-return
-if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
-return
+entry = self._map.get(f)
+if entry is not None:
+if entry[0] == 'r' and entry[2] in (-1, -2):
+source = self._copymap.get(f)
+if entry[2] == -1:
+self.merge(f)
+elif entry[2] == -2:
+self.otherparent(f)
+if source:
+self.copy(source, f)
+return
+if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
+return
 self._addpath(f, 'n', 0, -1, -1)
 self._copymap.pop(f, None)
 if f in self._nonnormalset:
@@ -624,14 +626,15 @@
 self._dirty = True
 self._droppath(f)
 size = 0
-if self._pl[1] != nullid and f in self._map:
-# backup the previous state
-entry = self._map[f]
-if entry[0] == 'm': # merge
-size = -1
-elif entry[0] == 'n' and entry[2] == -2: # other parent
-size = -2
-self._otherparentset.add(f)
+if self._pl[1] != nullid:
+entry = self._map.get(f)
+if entry is not None:
+# backup the previous state
+if entry[0] == 'm': # merge
+size = -1
+elif entry[0] == 'n' and entry[2] == -2: # other parent
+size = -2
+self._otherparentset.add(f)
 self._map[f] = dirstatetuple('r', 0, size, 0)
 self._nonnormalset.add(f)
 if size == 0:



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