Re: D4281: branchmap: load branchmap as an iterable

2018-08-16 Thread Yuya Nishihara
>  def read(repo):
>  try:
>  f = repo.cachevfs(_filename(repo))
> -lines = f.read().split('\n')
> -f.close()
> -except (IOError, OSError):
> -return None
> -
> -try:
> -cachekey = lines.pop(0).split(" ", 2)
> +cachekey = next(f).split(" ", 2)

Several tests fail, probably because of missed rstrip().

>  partial.setdefault(label, []).append(node)
>  if state == 'c':
>  partial._closednodes.add(node)
> +
> +except (IOError, OSError):
> +return None
> +
>  except Exception as inst:
>  if repo.ui.debugflag:
>  msg = 'invalid branchheads cache'

Missed `finally: f.close()`?
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4281: branchmap: load branchmap as an iterable

2018-08-16 Thread yuja (Yuya Nishihara)
yuja added a comment.


  >   def read(repo):
  >   try:
  >   f = repo.cachevfs(_filename(repo))
  > 
  > - lines = f.read().split('\n')
  > - f.close()
  > - except (IOError, OSError):
  > - return None -
  > - try:
  > - cachekey = lines.pop(0).split(" ", 2) +cachekey = next(f).split(" 
", 2)
  
  Several tests fail, probably because of missed rstrip().
  
  >   partial.setdefault(label, []).append(node)
  >   if state == 'c':
  >   partial._closednodes.add(node)
  > 
  > +
  >  +except (IOError, OSError):
  >  +return None
  >  +
  > 
  >   except Exception as inst:
  >   if repo.ui.debugflag:
  >   msg = 'invalid branchheads cache'
  
  Missed `finally: f.close()`?

REPOSITORY
  rHG Mercurial

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

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


D4281: branchmap: load branchmap as an iterable

2018-08-15 Thread mjpieters (Martijn Pieters)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG9a800691f075: branchmap: load branchmap as an iterable 
(authored by mjpieters, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4281?vs=10353=10374

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

AFFECTED FILES
  mercurial/branchmap.py

CHANGE DETAILS

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -40,13 +40,7 @@
 def read(repo):
 try:
 f = repo.cachevfs(_filename(repo))
-lines = f.read().split('\n')
-f.close()
-except (IOError, OSError):
-return None
-
-try:
-cachekey = lines.pop(0).split(" ", 2)
+cachekey = next(f).split(" ", 2)
 last, lrev = cachekey[:2]
 last, lrev = bin(last), int(lrev)
 filteredhash = None
@@ -58,7 +52,7 @@
 # invalidate the cache
 raise ValueError(r'tip differs')
 cl = repo.changelog
-for l in lines:
+for l in f:
 if not l:
 continue
 node, state, label = l.split(" ", 2)
@@ -72,6 +66,10 @@
 partial.setdefault(label, []).append(node)
 if state == 'c':
 partial._closednodes.add(node)
+
+except (IOError, OSError):
+return None
+
 except Exception as inst:
 if repo.ui.debugflag:
 msg = 'invalid branchheads cache'



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


D4281: branchmap: load branchmap as an iterable

2018-08-13 Thread mjpieters (Martijn Pieters)
mjpieters created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This avoids reading all the file into memory if the cache turns out to be
  invalid.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/branchmap.py

CHANGE DETAILS

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -40,13 +40,7 @@
 def read(repo):
 try:
 f = repo.cachevfs(_filename(repo))
-lines = f.read().split('\n')
-f.close()
-except (IOError, OSError):
-return None
-
-try:
-cachekey = lines.pop(0).split(" ", 2)
+cachekey = next(f).split(" ", 2)
 last, lrev = cachekey[:2]
 last, lrev = bin(last), int(lrev)
 filteredhash = None
@@ -58,7 +52,7 @@
 # invalidate the cache
 raise ValueError(r'tip differs')
 cl = repo.changelog
-for l in lines:
+for l in f:
 if not l:
 continue
 node, state, label = l.split(" ", 2)
@@ -72,6 +66,10 @@
 partial.setdefault(label, []).append(node)
 if state == 'c':
 partial._closednodes.add(node)
+
+except (IOError, OSError):
+return None
+
 except Exception as inst:
 if repo.ui.debugflag:
 msg = 'invalid branchheads cache'



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