D9715: convert: set date and time for svn commits

2021-01-08 Thread nslsrv (Nikita Slyusarev)
nslsrv created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Committing to subversion repository is changed to use commit dates from
  the source. Subversion always uses commit dates with UTC timezone, so only
  timestamps are used.
  
  Test `test-convert-svn-sink.t` uses `svnxml.py` script to dump history of svn
  repositories. Atm the script is not printing `date` field from svn log. This
  patch changes this to allow checks on correctness of date and time convertion.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/convert/subversion.py
  tests/svnxml.py
  tests/test-convert-hg-svn.t
  tests/test-convert-svn-sink.t

CHANGE DETAILS

diff --git a/tests/test-convert-svn-sink.t b/tests/test-convert-svn-sink.t
--- a/tests/test-convert-svn-sink.t
+++ b/tests/test-convert-svn-sink.t
@@ -54,10 +54,12 @@
2 2 test a
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.00Z
   msg: modify a file
M /a
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: add a file
A /a
A /d1
@@ -95,6 +97,7 @@
3 3 test b
   revision: 3
   author: test
+  date: 1970-01-01T00:00:02.00Z
   msg: rename a file
D /a
A /b (from /a@2)
@@ -131,6 +134,7 @@
4 4 test c
   revision: 4
   author: test
+  date: 1970-01-01T00:00:03.00Z
   msg: copy a file
A /c (from /b@3)
   $ ls a a-hg-wc
@@ -167,6 +171,7 @@
5 5 test .
   revision: 5
   author: test
+  date: 1970-01-01T00:00:04.00Z
   msg: remove a file
D /b
   $ ls a a-hg-wc
@@ -209,6 +214,7 @@
6 6 test c
   revision: 6
   author: test
+  date: 1970-01-01T00:00:05.00Z
   msg: make a file executable
M /c
 #if execbit
@@ -247,6 +253,7 @@
8 8 test newlink
   revision: 8
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: move symlink
D /link
A /newlink (from /link@7)
@@ -278,6 +285,7 @@
7 7 test f
   revision: 7
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: f
D /c
A /d
@@ -315,6 +323,7 @@
1 1 test d1/a
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: add executable file in new directory
A /d1
A /d1/a
@@ -343,6 +352,7 @@
2 2 test d2/a
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.00Z
   msg: copy file to new directory
A /d2
A /d2/a (from /d1/a@1)
@@ -416,21 +426,25 @@
4 4 test right-2
   revision: 4
   author: test
+  date: 1970-01-01T00:00:05.00Z
   msg: merge
A /right-1
A /right-2
   revision: 3
   author: test
+  date: 1970-01-01T00:00:02.00Z
   msg: left-2
M /b
A /left-2
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.00Z
   msg: left-1
M /b
A /left-1
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: base
A /b
 
@@ -459,10 +473,12 @@
2 2 test .hgtags
   revision: 2
   author: test
+  date: 1970-01-01T00:00:01.00Z
   msg: Tagged as v1.0
A /.hgtags
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: Add file a
A /a
   $ rm -rf a a-hg a-hg-wc
@@ -494,10 +510,12 @@
2 2 test exec
   revision: 2
   author: test
+  date: 1970-01-01T00:00:02.00Z
   msg: remove executable bit
M /exec
   revision: 1
   author: test
+  date: 1970-01-01T00:00:01.00Z
   msg: create executable
A /exec
   $ test ! -x a-hg-wc/exec
@@ -540,10 +558,12 @@
2 2 test b
   revision: 2
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: Another change
A /b
   revision: 1
   author: test
+  date: 1970-01-01T00:00:00.00Z
   msg: Some change
A /a
 
diff --git a/tests/test-convert-hg-svn.t b/tests/test-convert-hg-svn.t
--- a/tests/test-convert-hg-svn.t
+++ b/tests/test-convert-hg-svn.t
@@ -24,6 +24,7 @@
   > ACTION="$5"
   > 
   > if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi
+  > if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:date" ]; then exit 0; fi
   > if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-branch" ]; then exit 0; 
fi
   > if [ "$ACTION" = "A" -a "$PROPNAME" = "hg:convert-rev" ]; then exit 0; fi
   > 
diff --git a/tests/svnxml.py b/tests/svnxml.py
--- a/tests/svnxml.py
+++ b/tests/svnxml.py
@@ -15,6 +15,7 @@
 e['revision'] = entry.getAttribute('revision')
 e['author'] = xmltext(entry.getElementsByTagName('author')[0])
 e['msg'] = xmltext(entry.getElementsByTagName('msg')[0])
+e['date'] = xmltext(entry.getElementsByTagName('date')[0])
 e['paths'] = []
 paths = entry.getElementsByTagName('paths')
 if paths:
@@ -42,7 +43,7 @@
 except AttributeError:
 fp = sys.stdout
 for e in entries:
-for k in ('revision', 'author', 'msg'):
+for k in ('revision', 'author', 'date', 'msg'):
 fp.write(('%s: %s\n' % (k, e[k])).encode('utf-8'))
 for path, action, fpath, frev in sorted(e['paths']):
 frominfo = b''

D9714: shelve: extract some repeated creation of shelf instances to variables

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This just looks cleaner to me; I'd be surprised if there's any
  measurable performance improvement.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -463,10 +463,11 @@
 
 def _shelvecreatedcommit(repo, node, name, match):
 info = {b'node': hex(node)}
-Shelf(repo, name).writeinfo(info)
+shelf = Shelf(repo, name)
+shelf.writeinfo(info)
 bases = list(mutableancestors(repo[node]))
-Shelf(repo, name).writebundle(bases, node)
-with Shelf(repo, name).open_patch(b'wb') as fp:
+shelf.writebundle(bases, node)
+with shelf.open_patch(b'wb') as fp:
 cmdutil.exportfile(
 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match
 )
@@ -602,11 +603,12 @@
 raise error.InputError(_(b'no shelved changes specified!'))
 with repo.wlock():
 for name in pats:
-if not Shelf(repo, name).exists():
+shelf = Shelf(repo, name)
+if not shelf.exists():
 raise error.InputError(
 _(b"shelved change '%s' not found") % name
 )
-Shelf(repo, name).movetobackup()
+shelf.movetobackup()
 cleanupoldbackups(repo)
 
 
@@ -875,16 +877,17 @@
 """Recreate commit in the repository during the unshelve"""
 repo = repo.unfiltered()
 node = None
-if Shelf(repo, basename).hasinfo():
-node = Shelf(repo, basename).readinfo()[b'node']
+shelf = Shelf(repo, basename)
+if shelf.hasinfo():
+node = shelf.readinfo()[b'node']
 if node is None or node not in repo:
 with ui.configoverride({(b'ui', b'quiet'): True}):
-shelvectx = Shelf(repo, basename).applybundle(tr)
+shelvectx = shelf.applybundle(tr)
 # We might not strip the unbundled changeset, so we should keep track 
of
 # the unshelve node in case we need to reuse it (eg: unshelve --keep)
 if node is None:
 info = {b'node': hex(shelvectx.node())}
-Shelf(repo, basename).writeinfo(info)
+shelf.writeinfo(info)
 else:
 shelvectx = repo[node]
 



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


D9713: shelve: teach new shelf class to check if .shelve file exists

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This removes the only remaining use for `shelvedfile`, so the class
  now goes away.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -72,24 +72,6 @@
 shelveuser = b'shelve@localhost'
 
 
-class shelvedfile(object):
-"""Helper for the file storing a single shelve
-
-Handles common functions on shelve files (.hg/.patch) using
-the vfs layer"""
-
-def __init__(self, repo, name, filetype=None):
-self.name = name
-self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
-if filetype:
-self.fname = name + b'.' + filetype
-else:
-self.fname = name
-
-def exists(self):
-return self.vfs.exists(self.fname)
-
-
 class Shelf(object):
 """Represents a shelf, including possibly multiple files storing it.
 
@@ -113,6 +95,9 @@
 def writeinfo(self, info):
 scmutil.simplekeyvaluefile(self.vfs, self.name + 
b'.shelve').write(info)
 
+def hasinfo(self):
+return self.vfs.exists(self.name + b'.shelve')
+
 def readinfo(self):
 return scmutil.simplekeyvaluefile(
 self.vfs, self.name + b'.shelve'
@@ -890,7 +875,7 @@
 """Recreate commit in the repository during the unshelve"""
 repo = repo.unfiltered()
 node = None
-if shelvedfile(repo, basename, b'shelve').exists():
+if Shelf(repo, basename).hasinfo():
 node = Shelf(repo, basename).readinfo()[b'node']
 if node is None or node not in repo:
 with ui.configoverride({(b'ui', b'quiet'): True}):



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


D9712: shelve: move method for creating backup to new shelf class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -81,7 +81,6 @@
 def __init__(self, repo, name, filetype=None):
 self.name = name
 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
-self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
 if filetype:
 self.fname = name + b'.' + filetype
 else:
@@ -90,22 +89,6 @@
 def exists(self):
 return self.vfs.exists(self.fname)
 
-def backupfilename(self):
-def gennames(base):
-yield base
-base, ext = base.rsplit(b'.', 1)
-for i in itertools.count(1):
-yield b'%s-%d.%s' % (base, i, ext)
-
-for n in gennames(self.fname):
-if not self.backupvfs.exists(n):
-return self.backupvfs.join(n)
-
-def movetobackup(self):
-if not self.backupvfs.isdir():
-self.backupvfs.makedir()
-util.rename(self.vfs.join(self.fname), self.backupfilename())
-
 
 class Shelf(object):
 """Represents a shelf, including possibly multiple files storing it.
@@ -119,6 +102,7 @@
 self.repo = repo
 self.name = name
 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
+self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
 
 def exists(self):
 return self.vfs.exists(self.name + b'.' + patchextension)
@@ -188,6 +172,27 @@
 def open_patch(self, mode=b'rb'):
 return self.vfs(self.name + b'.patch', mode)
 
+def _backupfilename(self, filename):
+def gennames(base):
+yield base
+base, ext = base.rsplit(b'.', 1)
+for i in itertools.count(1):
+yield b'%s-%d.%s' % (base, i, ext)
+
+for n in gennames(filename):
+if not self.backupvfs.exists(n):
+return self.backupvfs.join(n)
+
+def movetobackup(self):
+if not self.backupvfs.isdir():
+self.backupvfs.makedir()
+for suffix in shelvefileextensions:
+filename = self.name + b'.' + suffix
+if self.vfs.exists(filename):
+util.rename(
+self.vfs.join(filename), self._backupfilename(filename)
+)
+
 
 class shelvedstate(object):
 """Handle persistence during unshelving operations.
@@ -602,10 +607,7 @@
 
 with repo.wlock():
 for _mtime, name in listshelves(repo):
-for suffix in shelvefileextensions:
-shfile = shelvedfile(repo, name, suffix)
-if shfile.exists():
-shfile.movetobackup()
+Shelf(repo, name).movetobackup()
 cleanupoldbackups(repo)
 
 
@@ -619,10 +621,7 @@
 raise error.InputError(
 _(b"shelved change '%s' not found") % name
 )
-for suffix in shelvefileextensions:
-shfile = shelvedfile(repo, name, suffix)
-if shfile.exists():
-shfile.movetobackup()
+Shelf(repo, name).movetobackup()
 cleanupoldbackups(repo)
 
 
@@ -791,10 +790,7 @@
 def unshelvecleanup(ui, repo, name, opts):
 """remove related files after an unshelve"""
 if not opts.get(b'keep'):
-for filetype in shelvefileextensions:
-shfile = shelvedfile(repo, name, filetype)
-if shfile.exists():
-shfile.movetobackup()
+Shelf(repo, name).movetobackup()
 cleanupoldbackups(repo)
 
 



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


D9710: shelve: use listshelves() in cleanup function

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The point of this patch is to make it so all the callers of
  `shelvedfile.movetobackup()` look the same, so I can move it over to
  the new `Shelf` class next.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -602,10 +602,11 @@
 """subcommand that deletes all shelves"""
 
 with repo.wlock():
-for (name, _type) in repo.vfs.readdir(shelvedir):
-suffix = name.rsplit(b'.', 1)[-1]
-if suffix in shelvefileextensions:
-shelvedfile(repo, name).movetobackup()
+for _mtime, name in listshelves(repo):
+for suffix in shelvefileextensions:
+shfile = shelvedfile(repo, name, suffix)
+if shfile.exists():
+shfile.movetobackup()
 cleanupoldbackups(repo)
 
 



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


D9708: shelve: make listshelves() return shelf names instead of filenames

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  All three callers now prefer the shelf name over the filename (already
  before my recent patches, two out of three callers preferred the shelf
  name).

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -643,7 +643,7 @@
 if not pfx or sfx != patchextension:
 continue
 mtime = Shelf(repo, pfx).mtime()
-info.append((mtime, shelvedfile(repo, pfx).filename()))
+info.append((mtime, pfx))
 return sorted(info, reverse=True)
 
 
@@ -656,22 +656,21 @@
 namelabel = b'shelve.newest'
 ui.pager(b'shelve')
 for mtime, name in listshelves(repo):
-sname = util.split(name)[1]
-if pats and sname not in pats:
+if pats and name not in pats:
 continue
-ui.write(sname, label=namelabel)
+ui.write(name, label=namelabel)
 namelabel = b'shelve.name'
 if ui.quiet:
 ui.write(b'\n')
 continue
-ui.write(b' ' * (16 - len(sname)))
+ui.write(b' ' * (16 - len(name)))
 used = 16
 date = dateutil.makedate(mtime)
 age = b'(%s)' % templatefilters.age(date, abbrev=True)
 ui.write(age, label=b'shelve.age')
 ui.write(b' ' * (12 - len(age)))
 used += 12
-with Shelf(repo, sname).open_patch() as fp:
+with Shelf(repo, name).open_patch() as fp:
 while True:
 line = fp.readline()
 if not line:
@@ -701,8 +700,7 @@
 if not shelves:
 raise error.Abort(_(b"there are no shelves to show"))
 mtime, name = shelves[0]
-sname = util.split(name)[1]
-pats = [sname]
+pats = [name]
 
 for shelfname in pats:
 if not Shelf(repo, shelfname).exists():
@@ -1122,7 +1120,7 @@
 shelved = listshelves(repo)
 if not shelved:
 raise error.StateError(_(b'no shelved changes to apply!'))
-basename = util.split(shelved[0][1])[1]
+basename = shelved[0][1]
 ui.status(_(b"unshelving change '%s'\n") % basename)
 else:
 basename = shelved[0]



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


D9711: shelve: make gennames() helper generate relative backup paths

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  When I saw `gennames()`, I thought it was meant to take a relative
  filename as argument. Maybe it was or maybe it wasn't, but it seems
  simpler to pass it a relative path anyway, so that's what this patch
  does. That also makes the call to backupvfs.exists() more natural (I
  expect a relative path to be passed there too).

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -97,10 +97,9 @@
 for i in itertools.count(1):
 yield b'%s-%d.%s' % (base, i, ext)
 
-name = self.backupvfs.join(self.fname)
-for n in gennames(name):
+for n in gennames(self.fname):
 if not self.backupvfs.exists(n):
-return n
+return self.backupvfs.join(n)
 
 def movetobackup(self):
 if not self.backupvfs.isdir():



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


D9709: shelve: inline shelvedfile.filename() since there are no callers outside class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -90,9 +90,6 @@
 def exists(self):
 return self.vfs.exists(self.fname)
 
-def filename(self):
-return self.vfs.join(self.fname)
-
 def backupfilename(self):
 def gennames(base):
 yield base
@@ -108,7 +105,7 @@
 def movetobackup(self):
 if not self.backupvfs.isdir():
 self.backupvfs.makedir()
-util.rename(self.filename(), self.backupfilename())
+util.rename(self.vfs.join(self.fname), self.backupfilename())
 
 
 class Shelf(object):



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


D9707: shelve: move method for getting stat (mtime) to new shelf class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Only the mtime was needed, so I made it restricted to that in the
  move.
  
  The new `Shelf` class expects its argument to be a shelf name (not a
  arbitrary filename like `shelvedfile` would accept), so only the
  shelf name is now passed in.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -110,9 +110,6 @@
 self.backupvfs.makedir()
 util.rename(self.filename(), self.backupfilename())
 
-def stat(self):
-return self.vfs.stat(self.fname)
-
 
 class Shelf(object):
 """Represents a shelf, including possibly multiple files storing it.
@@ -130,6 +127,9 @@
 def exists(self):
 return self.vfs.exists(self.name + b'.' + patchextension)
 
+def mtime(self):
+return self.vfs.stat(self.name + b'.' + patchextension)[stat.ST_MTIME]
+
 def writeinfo(self, info):
 scmutil.simplekeyvaluefile(self.vfs, self.name + 
b'.shelve').write(info)
 
@@ -642,8 +642,8 @@
 pfx, sfx = name.rsplit(b'.', 1)
 if not pfx or sfx != patchextension:
 continue
-st = shelvedfile(repo, name).stat()
-info.append((st[stat.ST_MTIME], shelvedfile(repo, pfx).filename()))
+mtime = Shelf(repo, pfx).mtime()
+info.append((mtime, shelvedfile(repo, pfx).filename()))
 return sorted(info, reverse=True)
 
 



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


D9706: shelve: open patch using new shelf class instead of open()

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  For some reason the existing code didn't use `shelvedfile().opener()`
  so here we migrate to `shelf().open_patch()` from the `open()` system
  call instead.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -28,7 +28,6 @@
 import stat
 
 from .i18n import _
-from .pycompat import open
 from .node import (
 bin,
 hex,
@@ -672,7 +671,7 @@
 ui.write(age, label=b'shelve.age')
 ui.write(b' ' * (12 - len(age)))
 used += 12
-with open(name + b'.' + patchextension, b'rb') as fp:
+with Shelf(repo, sname).open_patch() as fp:
 while True:
 line = fp.readline()
 if not line:



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


D9705: shelve: move function for opening .patch file to new shelf class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The `opener()` method was used specifically for the `.patch` file, and
  the new `Shelf` class deals with all files involved in a shelf, so I
  renamed the function in the process.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -114,9 +114,6 @@
 def stat(self):
 return self.vfs.stat(self.fname)
 
-def opener(self, mode=b'rb'):
-return self.vfs(self.fname, mode)
-
 
 class Shelf(object):
 """Represents a shelf, including possibly multiple files storing it.
@@ -193,6 +190,9 @@
 finally:
 fp.close()
 
+def open_patch(self, mode=b'rb'):
+return self.vfs(self.name + b'.patch', mode)
+
 
 class shelvedstate(object):
 """Handle persistence during unshelving operations.
@@ -481,7 +481,7 @@
 Shelf(repo, name).writeinfo(info)
 bases = list(mutableancestors(repo[node]))
 Shelf(repo, name).writebundle(bases, node)
-with shelvedfile(repo, name, patchextension).opener(b'wb') as fp:
+with Shelf(repo, name).open_patch(b'wb') as fp:
 cmdutil.exportfile(
 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match
 )



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


D9703: shelve: move method for writing bundle to new shelf class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -84,7 +84,6 @@
 self.name = name
 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
-self.ui = self.repo.ui
 if filetype:
 self.fname = name + b'.' + filetype
 else:
@@ -143,26 +142,6 @@
 finally:
 fp.close()
 
-def writebundle(self, bases, node):
-cgversion = changegroup.safeversion(self.repo)
-if cgversion == b'01':
-btype = b'HG10BZ'
-compression = None
-else:
-btype = b'HG20'
-compression = b'BZ'
-
-repo = self.repo.unfiltered()
-
-outgoing = discovery.outgoing(
-repo, missingroots=bases, ancestorsof=[node]
-)
-cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve')
-
-bundle2.writebundle(
-self.ui, cg, self.fname, btype, self.vfs, compression=compression
-)
-
 
 class Shelf(object):
 """Represents a shelf, including possibly multiple files storing it.
@@ -188,6 +167,32 @@
 self.vfs, self.name + b'.shelve'
 ).read()
 
+def writebundle(self, bases, node):
+cgversion = changegroup.safeversion(self.repo)
+if cgversion == b'01':
+btype = b'HG10BZ'
+compression = None
+else:
+btype = b'HG20'
+compression = b'BZ'
+
+repo = self.repo.unfiltered()
+
+outgoing = discovery.outgoing(
+repo, missingroots=bases, ancestorsof=[node]
+)
+cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve')
+
+bundle_filename = self.vfs.join(self.name + b'.hg')
+bundle2.writebundle(
+self.repo.ui,
+cg,
+bundle_filename,
+btype,
+self.vfs,
+compression=compression,
+)
+
 
 class shelvedstate(object):
 """Handle persistence during unshelving operations.
@@ -475,7 +480,7 @@
 info = {b'node': hex(node)}
 Shelf(repo, name).writeinfo(info)
 bases = list(mutableancestors(repo[node]))
-shelvedfile(repo, name, b'hg').writebundle(bases, node)
+Shelf(repo, name).writebundle(bases, node)
 with shelvedfile(repo, name, patchextension).opener(b'wb') as fp:
 cmdutil.exportfile(
 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match



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


D9704: shelve: move method for reading .hg to new shelf class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -80,7 +80,6 @@
 the vfs layer"""
 
 def __init__(self, repo, name, filetype=None):
-self.repo = repo
 self.name = name
 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
@@ -118,30 +117,6 @@
 def opener(self, mode=b'rb'):
 return self.vfs(self.fname, mode)
 
-def applybundle(self, tr):
-fp = self.opener()
-try:
-targetphase = phases.internal
-if not phases.supportinternal(self.repo):
-targetphase = phases.secret
-gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
-pretip = self.repo[b'tip']
-bundle2.applybundle(
-self.repo,
-gen,
-tr,
-source=b'unshelve',
-url=b'bundle:' + self.vfs.join(self.fname),
-targetphase=targetphase,
-)
-shelvectx = self.repo[b'tip']
-if pretip == shelvectx:
-shelverev = tr.changes[b'revduplicates'][-1]
-shelvectx = self.repo[shelverev]
-return shelvectx
-finally:
-fp.close()
-
 
 class Shelf(object):
 """Represents a shelf, including possibly multiple files storing it.
@@ -193,6 +168,31 @@
 compression=compression,
 )
 
+def applybundle(self, tr):
+filename = self.name + b'.hg'
+fp = self.vfs(filename)
+try:
+targetphase = phases.internal
+if not phases.supportinternal(self.repo):
+targetphase = phases.secret
+gen = exchange.readbundle(self.repo.ui, fp, filename, self.vfs)
+pretip = self.repo[b'tip']
+bundle2.applybundle(
+self.repo,
+gen,
+tr,
+source=b'unshelve',
+url=b'bundle:' + self.vfs.join(filename),
+targetphase=targetphase,
+)
+shelvectx = self.repo[b'tip']
+if pretip == shelvectx:
+shelverev = tr.changes[b'revduplicates'][-1]
+shelvectx = self.repo[shelverev]
+return shelvectx
+finally:
+fp.close()
+
 
 class shelvedstate(object):
 """Handle persistence during unshelving operations.
@@ -904,7 +904,7 @@
 node = Shelf(repo, basename).readinfo()[b'node']
 if node is None or node not in repo:
 with ui.configoverride({(b'ui', b'quiet'): True}):
-shelvectx = shelvedfile(repo, basename, b'hg').applybundle(tr)
+shelvectx = Shelf(repo, basename).applybundle(tr)
 # We might not strip the unbundled changeset, so we should keep track 
of
 # the unshelve node in case we need to reuse it (eg: unshelve --keep)
 if node is None:



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


D9702: shelve: move method for reading .shelve file to new shelf class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -163,9 +163,6 @@
 self.ui, cg, self.fname, btype, self.vfs, compression=compression
 )
 
-def readinfo(self):
-return scmutil.simplekeyvaluefile(self.vfs, self.fname).read()
-
 
 class Shelf(object):
 """Represents a shelf, including possibly multiple files storing it.
@@ -186,6 +183,11 @@
 def writeinfo(self, info):
 scmutil.simplekeyvaluefile(self.vfs, self.name + 
b'.shelve').write(info)
 
+def readinfo(self):
+return scmutil.simplekeyvaluefile(
+self.vfs, self.name + b'.shelve'
+).read()
+
 
 class shelvedstate(object):
 """Handle persistence during unshelving operations.
@@ -894,7 +896,7 @@
 repo = repo.unfiltered()
 node = None
 if shelvedfile(repo, basename, b'shelve').exists():
-node = shelvedfile(repo, basename, b'shelve').readinfo()[b'node']
+node = Shelf(repo, basename).readinfo()[b'node']
 if node is None or node not in repo:
 with ui.configoverride({(b'ui', b'quiet'): True}):
 shelvectx = shelvedfile(repo, basename, b'hg').applybundle(tr)



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


D9699: shelve: raise more specific errors

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py
  tests/test-shelve.t

CHANGE DETAILS

diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -278,10 +278,10 @@
 
   $ hg unshelve
   abort: no shelved changes to apply!
-  [255]
+  [20]
   $ hg unshelve foo
   abort: shelved change 'foo' not found
-  [255]
+  [10]
 
 named shelves, specific filenames, and "commit messages" should all work
 (this tests also that editor is invoked, if '--edit' is specified)
@@ -979,7 +979,7 @@
   default (*s ago)changes to: create conflict (glob)
   $ hg shelve --delete doesnotexist
   abort: shelved change 'doesnotexist' not found
-  [255]
+  [10]
   $ hg shelve --delete default
 
   $ cd ..
@@ -1408,7 +1408,7 @@
 -- using --continue with --interactive should throw an error
   $ hg unshelve --continue -i
   abort: cannot use both continue and interactive
-  [255]
+  [10]
 
   $ cat bar1
   A
@@ -1511,4 +1511,4 @@
 -- test for --interactive --keep
   $ hg unshelve -i --keep
   abort: --keep on --interactive is not yet supported
-  [255]
+  [10]
diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -592,11 +592,13 @@
 def deletecmd(ui, repo, pats):
 """subcommand that deletes a specific shelve"""
 if not pats:
-raise error.Abort(_(b'no shelved changes specified!'))
+raise error.InputError(_(b'no shelved changes specified!'))
 with repo.wlock():
 for name in pats:
 if not shelvedfile(repo, name, patchextension).exists():
-raise error.Abort(_(b"shelved change '%s' not found") % name)
+raise error.InputError(
+_(b"shelved change '%s' not found") % name
+)
 for suffix in shelvefileextensions:
 shfile = shelvedfile(repo, name, suffix)
 if shfile.exists():
@@ -1066,12 +1068,14 @@
 shelved.append(opts[b"name"])
 
 if interactive and opts.get(b'keep'):
-raise error.Abort(_(b'--keep on --interactive is not yet supported'))
+raise error.InputError(
+_(b'--keep on --interactive is not yet supported')
+)
 if abortf or continuef:
 if abortf and continuef:
-raise error.Abort(_(b'cannot use both abort and continue'))
+raise error.InputError(_(b'cannot use both abort and continue'))
 if shelved:
-raise error.Abort(
+raise error.InputError(
 _(
 b'cannot combine abort/continue with '
 b'naming a shelved change'
@@ -1084,22 +1088,24 @@
 if abortf:
 return unshelveabort(ui, repo, state)
 elif continuef and interactive:
-raise error.Abort(_(b'cannot use both continue and interactive'))
+raise error.InputError(
+_(b'cannot use both continue and interactive')
+)
 elif continuef:
 return unshelvecontinue(ui, repo, state, opts)
 elif len(shelved) > 1:
-raise error.Abort(_(b'can only unshelve one change at a time'))
+raise error.InputError(_(b'can only unshelve one change at a time'))
 elif not shelved:
 shelved = listshelves(repo)
 if not shelved:
-raise error.Abort(_(b'no shelved changes to apply!'))
+raise error.StateError(_(b'no shelved changes to apply!'))
 basename = util.split(shelved[0][1])[1]
 ui.status(_(b"unshelving change '%s'\n") % basename)
 else:
 basename = shelved[0]
 
 if not shelvedfile(repo, basename, patchextension).exists():
-raise error.Abort(_(b"shelved change '%s' not found") % basename)
+raise error.InputError(_(b"shelved change '%s' not found") % basename)
 
 return _dounshelve(ui, repo, basename, opts)
 



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


D9701: shelve: move method for writing .shelve to new shelf class

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -163,9 +163,6 @@
 self.ui, cg, self.fname, btype, self.vfs, compression=compression
 )
 
-def writeinfo(self, info):
-scmutil.simplekeyvaluefile(self.vfs, self.fname).write(info)
-
 def readinfo(self):
 return scmutil.simplekeyvaluefile(self.vfs, self.fname).read()
 
@@ -186,6 +183,9 @@
 def exists(self):
 return self.vfs.exists(self.name + b'.' + patchextension)
 
+def writeinfo(self, info):
+scmutil.simplekeyvaluefile(self.vfs, self.name + 
b'.shelve').write(info)
+
 
 class shelvedstate(object):
 """Handle persistence during unshelving operations.
@@ -471,7 +471,7 @@
 
 def _shelvecreatedcommit(repo, node, name, match):
 info = {b'node': hex(node)}
-shelvedfile(repo, name, b'shelve').writeinfo(info)
+Shelf(repo, name).writeinfo(info)
 bases = list(mutableancestors(repo[node]))
 shelvedfile(repo, name, b'hg').writebundle(bases, node)
 with shelvedfile(repo, name, patchextension).opener(b'wb') as fp:
@@ -902,7 +902,7 @@
 # the unshelve node in case we need to reuse it (eg: unshelve --keep)
 if node is None:
 info = {b'node': hex(shelvectx.node())}
-shelvedfile(repo, basename, b'shelve').writeinfo(info)
+Shelf(repo, basename).writeinfo(info)
 else:
 shelvectx = repo[node]
 



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


D9700: shelve: introduce class representing a shelf

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I'm about to make phase-based shelve not write `.hg` and `.patch`
  files. Having a class that represents a single shelf, regardless of
  which files it uses will help. I'm starting small with just a
  `.exists()` function. I plan to eventually remove the `shelvedfile`
  class once all functionality has been moved to the new class.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -170,6 +170,23 @@
 return scmutil.simplekeyvaluefile(self.vfs, self.fname).read()
 
 
+class Shelf(object):
+"""Represents a shelf, including possibly multiple files storing it.
+
+Old shelves will have a .patch and a .hg file. Newer shelves will
+also have a .shelve file. This class abstracts away some of the
+differences and lets you work with the shelf as a whole.
+"""
+
+def __init__(self, repo, name):
+self.repo = repo
+self.name = name
+self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
+
+def exists(self):
+return self.vfs.exists(self.name + b'.' + patchextension)
+
+
 class shelvedstate(object):
 """Handle persistence during unshelving operations.
 
@@ -364,7 +381,7 @@
 label = label.replace(b'.', b'_', 1)
 
 if name:
-if shelvedfile(repo, name, patchextension).exists():
+if Shelf(repo, name).exists():
 e = _(b"a shelved change named '%s' already exists") % name
 raise error.Abort(e)
 
@@ -378,7 +395,7 @@
 
 else:
 for n in gennames():
-if not shelvedfile(repo, n, patchextension).exists():
+if not Shelf(repo, n).exists():
 name = n
 break
 
@@ -595,7 +612,7 @@
 raise error.InputError(_(b'no shelved changes specified!'))
 with repo.wlock():
 for name in pats:
-if not shelvedfile(repo, name, patchextension).exists():
+if not Shelf(repo, name).exists():
 raise error.InputError(
 _(b"shelved change '%s' not found") % name
 )
@@ -682,7 +699,7 @@
 pats = [sname]
 
 for shelfname in pats:
-if not shelvedfile(repo, shelfname, patchextension).exists():
+if not Shelf(repo, shelfname).exists():
 raise error.Abort(_(b"cannot find shelf %s") % shelfname)
 
 listcmd(ui, repo, pats, opts)
@@ -1104,7 +1121,7 @@
 else:
 basename = shelved[0]
 
-if not shelvedfile(repo, basename, patchextension).exists():
+if not Shelf(repo, basename).exists():
 raise error.InputError(_(b"shelved change '%s' not found") % basename)
 
 return _dounshelve(ui, repo, basename, opts)



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


D9698: shelve: trust caller of shelvedfile.opener() to check that the file exists

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The only place we call `shelvedfile.opener()` is when we're about to
  apply a bundle. The file should always exist. If it doesn't, the
  `.hg/` directory is corrupt and we don't provide any guarantees about
  supporting corrupt repos (besides, telling the user that the shelve
  doesn't exist when `hg shelve --list` lists it is not very helpful).

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -117,12 +117,7 @@
 return self.vfs.stat(self.fname)
 
 def opener(self, mode=b'rb'):
-try:
-return self.vfs(self.fname, mode)
-except IOError as err:
-if err.errno != errno.ENOENT:
-raise
-raise error.Abort(_(b"shelved change '%s' not found") % self.name)
+return self.vfs(self.fname, mode)
 
 def applybundle(self, tr):
 fp = self.opener()



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


D9697: shelve: rewrite check for unknown shelf to delete

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The code would try to delete the shelf's .patch file and if that
  raised an exception, it would convert it to an `error.Abort`. This
  patch rewrites it so the check is done upfront. I find it easier to
  read that way. It's now clear enough that I removed the comment
  explaining it as well.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -600,20 +600,12 @@
 raise error.Abort(_(b'no shelved changes specified!'))
 with repo.wlock():
 for name in pats:
-try:
-for suffix in shelvefileextensions:
-shfile = shelvedfile(repo, name, suffix)
-# patch file is necessary, as it should
-# be present for any kind of shelve,
-# but the .hg file is optional as in future we
-# will add obsolete shelve with does not create a
-# bundle
-if shfile.exists() or suffix == patchextension:
-shfile.movetobackup()
-except OSError as err:
-if err.errno != errno.ENOENT:
-raise
+if not shelvedfile(repo, name, patchextension).exists():
 raise error.Abort(_(b"shelved change '%s' not found") % name)
+for suffix in shelvefileextensions:
+shfile = shelvedfile(repo, name, suffix)
+if shfile.exists():
+shfile.movetobackup()
 cleanupoldbackups(repo)
 
 



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


D9696: shelve: remove a bundlerepo method

2021-01-08 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  It was added in 43816070284e 
 
(shelve: add a bundlerepo method,
  2014-10-10), but I haven't been able to find a place it was used.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/shelve.py

CHANGE DETAILS

diff --git a/mercurial/shelve.py b/mercurial/shelve.py
--- a/mercurial/shelve.py
+++ b/mercurial/shelve.py
@@ -38,7 +38,6 @@
 from . import (
 bookmarks,
 bundle2,
-bundlerepo,
 changegroup,
 cmdutil,
 discovery,
@@ -149,12 +148,6 @@
 finally:
 fp.close()
 
-def bundlerepo(self):
-path = self.vfs.join(self.fname)
-return bundlerepo.instance(
-self.repo.baseui, b'bundle://%s+%s' % (self.repo.root, path), False
-)
-
 def writebundle(self, bases, node):
 cgversion = changegroup.safeversion(self.repo)
 if cgversion == b'01':



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


D9695: upgrade: don't perform anything if nothing to do

2021-01-08 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Before this patch, upgrade will process everything, re-clone all revlogs, 
write
  requirements file again even there is no change to be made.
  
  This patch makes it exit earlier.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py
  tests/test-lfs-serve.t
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -471,30 +471,7 @@
 
   $ hg init modern
   $ hg -R modern debugupgraderepo --run
-  upgrade will perform the following actions:
-  
-  requirements
- preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
-  
-  processed revlogs:
-- all-filelogs
-- changelog
-- manifest
-  
-  beginning upgrade...
-  repository locked and read-only
-  creating temporary repository to stage upgraded data: 
$TESTTMP/modern/.hg/upgrade.* (glob)
-  (it is safe to interrupt this process any time before data migration 
completes)
-  data fully upgraded in a temporary repository
-  marking source repository as being upgraded; clients will be unable to read 
from repository
-  starting in-place swap of repository data
-  replaced files will be backed up at $TESTTMP/modern/.hg/upgradebackup.* 
(glob)
-  replacing store...
-  store replacement complete; repository was inconsistent for *s (glob)
-  finalizing requirements file and making repository readable again
-  removing temporary repository $TESTTMP/modern/.hg/upgrade.* (glob)
-  copy of old repository backed up at $TESTTMP/modern/.hg/upgradebackup.* 
(glob)
-  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
+  nothing to do
 
 Upgrading a repository to generaldelta works
 
@@ -1025,41 +1002,7 @@
   $ touch .hg/store/.XX_special_filename
 
   $ hg debugupgraderepo --run
-  upgrade will perform the following actions:
-  
-  requirements
- preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
-  
-  processed revlogs:
-- all-filelogs
-- changelog
-- manifest
-  
-  beginning upgrade...
-  repository locked and read-only
-  creating temporary repository to stage upgraded data: 
$TESTTMP/store-filenames/.hg/upgrade.* (glob)
-  (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 3 total revisions (1 in filelogs, 1 in manifests, 1 in changelog)
-  migrating 301 bytes in store; 107 bytes tracked data
-  migrating 1 filelogs containing 1 revisions (64 bytes in store; 0 bytes 
tracked data)
-  finished migrating 1 filelog revisions across 1 filelogs; change in size: 0 
bytes
-  migrating 1 manifests containing 1 revisions (110 bytes in store; 45 bytes 
tracked data)
-  finished migrating 1 manifest revisions across 1 manifests; change in size: 
0 bytes
-  migrating changelog containing 1 revisions (127 bytes in store; 62 bytes 
tracked data)
-  finished migrating 1 changelog revisions; change in size: 0 bytes
-  finished migrating 3 total revisions; total change in store size: 0 bytes
-  copying .XX_special_filename
-  copying phaseroots
-  data fully upgraded in a temporary repository
-  marking source repository as being upgraded; clients will be unable to read 
from repository
-  starting in-place swap of repository data
-  replaced files will be backed up at 
$TESTTMP/store-filenames/.hg/upgradebackup.* (glob)
-  replacing store...
-  store replacement complete; repository was inconsistent for *s (glob)
-  finalizing requirements file and making repository readable again
-  removing temporary repository $TESTTMP/store-filenames/.hg/upgrade.* (glob)
-  copy of old repository backed up at 
$TESTTMP/store-filenames/.hg/upgradebackup.* (glob)
-  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified
+  nothing to do
   $ hg debugupgraderepo --run --optimize 're-delta-fulladd'
   upgrade will perform the following actions:
   
@@ -1132,40 +1075,7 @@
   store
 
   $ hg debugupgraderepo --run
-  upgrade will perform the following actions:
-  
-  requirements
- preserved: dotencode, fncache, generaldelta, largefiles, revlogv1, 
sparserevlog, store
-  
-  processed revlogs:
-- all-filelogs
-- changelog
-- manifest
-  
-  beginning upgrade...
-  repository locked and read-only
-  creating temporary repository to stage upgraded data: 
$TESTTMP/largefilesrepo/.hg/upgrade.* (glob)
-  (it is safe to interrupt this process any time before data migration 
completes)
-  migrating 3 total revisions (1 in filelogs, 1 in manifests, 1 in changelog)
-  migrating 355 bytes in store; 160 bytes tracked data
-  migrating 1 filelogs containing 1 revisions (106 bytes in store; 41 bytes 
tracked data)
-  

D9693: downgrade: if a compression is removed, consider that too

2021-01-08 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  For compression format variant, the result of `fromrepo()` and `fromconfig()` 
is
  not a boolean and we have to actually equate those to find change.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

diff --git a/mercurial/upgrade_utils/actions.py 
b/mercurial/upgrade_utils/actions.py
--- a/mercurial/upgrade_utils/actions.py
+++ b/mercurial/upgrade_utils/actions.py
@@ -467,6 +467,12 @@
 downgrades = []
 
 for fv in allformatvariant:
+if fv.name == b'compression':
+# If there is a compression change between repository
+# and config, destination repository compression will change
+# and current compression will be removed.
+if fv.fromrepo(repo) != fv.fromconfig(repo):
+downgrades.append(fv)
 # format variant exist in repo but does not exist in new repository
 # config
 if fv.fromrepo(repo) and not fv.fromconfig(repo):



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


D9694: upgrade: demonstrate that a no-op upgrade still performs everything

2021-01-08 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  An upgrade operation which is not adding or removing anything should ideally
  error out. However, it does the whole cloning and everything. Next patch will
  fix it.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  tests/test-upgrade-repo.t

CHANGE DETAILS

diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -1644,3 +1644,42 @@
   sparserevlog
   store
   $ hg debugsidedata -c 0
+
+Demonstrate that nothing to perform upgrade will still run all the way through
+FIXME: this should return early
+
+  $ hg debugupgraderepo --run
+  upgrade will perform the following actions:
+  
+  requirements
+ preserved: dotencode, exp-sidedata-flag, fncache, generaldelta, 
revlog-compression-zstd, revlogv1, sparserevlog, store
+  
+  processed revlogs:
+- all-filelogs
+- changelog
+- manifest
+  
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage upgraded data: 
$TESTTMP/sparserevlogrepo/.hg/upgrade.1xrhgkjm
+  (it is safe to interrupt this process any time before data migration 
completes)
+  migrating 3 total revisions (1 in filelogs, 1 in manifests, 1 in changelog)
+  migrating 297 bytes in store; 103 bytes tracked data
+  migrating 1 filelogs containing 1 revisions (64 bytes in store; 0 bytes 
tracked data)
+  finished migrating 1 filelog revisions across 1 filelogs; change in size: 0 
bytes
+  migrating 1 manifests containing 1 revisions (110 bytes in store; 45 bytes 
tracked data)
+  finished migrating 1 manifest revisions across 1 manifests; change in size: 
0 bytes
+  migrating changelog containing 1 revisions (123 bytes in store; 58 bytes 
tracked data)
+  finished migrating 1 changelog revisions; change in size: 0 bytes
+  finished migrating 3 total revisions; total change in store size: 0 bytes
+  copying phaseroots
+  data fully upgraded in a temporary repository
+  marking source repository as being upgraded; clients will be unable to read 
from repository
+  starting in-place swap of repository data
+  replaced files will be backed up at 
$TESTTMP/sparserevlogrepo/.hg/upgradebackup.0xno10pk
+  replacing store...
+  store replacement complete; repository was inconsistent for 0.0s
+  finalizing requirements file and making repository readable again
+  removing temporary repository $TESTTMP/sparserevlogrepo/.hg/upgrade.1xrhgkjm
+  copy of old repository backed up at 
$TESTTMP/sparserevlogrepo/.hg/upgradebackup.0xno10pk
+  the old repository will not be deleted; remove it to free up disk space once 
the upgraded repository is verified



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


D9692: sharesafe: introduce config to disallow outdated shares from working

2021-01-08 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  After this patch, we have config option to control all aspects of shares
  when share source is upgraded or downgraded.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -397,6 +397,9 @@
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-disallow-outdated-shares=true
+  abort: source repository uses share-safe while current share does not
+  [255]
 
   $ hg log -GT "{node}: {desc}\n" -R ../nss-share
   warning: source repository supports share-safe functionality. Reshare to 
upgrade.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -608,6 +608,15 @@
 requirements,
 )
 elif ui.configbool(
+b'experimental', b'sharesafe-disallow-outdated-shares'
+):
+raise error.Abort(
+_(
+b'source repository uses share-safe while'
+b' current share does not'
+)
+)
+elif ui.configbool(
 b'experimental', b'sharesafe-warn-outdated-shares'
 ):
 ui.warn(
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1084,6 +1084,11 @@
 )
 coreconfigitem(
 b'experimental',
+b'sharesafe-disallow-outdated-shares',
+default=False,
+)
+coreconfigitem(
+b'experimental',
 b'sharesafe-warn-outdated-shares',
 default=True,
 )



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


D9691: sharesafe: make warning about outdated share configurable

2021-01-08 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If the source repository upgrades to use sharesafe mode, we show a warning in
  shares. This patch makes that warning configurable and some might not want 
their
  users see this warning.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  tests/test-share-safe.t

CHANGE DETAILS

diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -392,6 +392,12 @@
 
 Make sure existing shares still works
 
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config 
experimental.sharesafe-warn-outdated-shares=false
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
   $ hg log -GT "{node}: {desc}\n" -R ../nss-share
   warning: source repository supports share-safe functionality. Reshare to 
upgrade.
   @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -607,7 +607,9 @@
 storevfs,
 requirements,
 )
-else:
+elif ui.configbool(
+b'experimental', b'sharesafe-warn-outdated-shares'
+):
 ui.warn(
 _(
 b'warning: source repository supports share-safe 
functionality.'
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1084,6 +1084,11 @@
 )
 coreconfigitem(
 b'experimental',
+b'sharesafe-warn-outdated-shares',
+default=True,
+)
+coreconfigitem(
+b'experimental',
 b'single-head-per-branch',
 default=False,
 )



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


D9690: debuglock: rename flag names to better clarity

2021-01-08 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `--force-lock` sounds as if we are taking the lock however in reality it's the
  opposite.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/debugcommands.py
  relnotes/next
  tests/test-completion.t

CHANGE DETAILS

diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -295,7 +295,7 @@
   debuginstall: template
   debugknown: 
   debuglabelcomplete: 
-  debuglocks: force-lock, force-wlock, set-lock, set-wlock
+  debuglocks: force-free-lock, force-free-wlock, set-lock, set-wlock
   debugmanifestfulltextcache: clear, add
   debugmergestate: style, template
   debugnamecomplete: 
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -53,6 +53,8 @@
 
 == Backwards Compatibility Changes ==
 
+ * `--force-lock` and `--force-wlock` options on `hg debuglock` command are
+   renamed to `--force-free-lock` and `--force-free-wlock` respectively.
 
 
 == Internal API Changes ==
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1889,10 +1889,10 @@
 @command(
 b'debuglocks',
 [
-(b'L', b'force-lock', None, _(b'free the store lock (DANGEROUS)')),
+(b'L', b'force-free-lock', None, _(b'free the store lock 
(DANGEROUS)')),
 (
 b'W',
-b'force-wlock',
+b'force-free-wlock',
 None,
 _(b'free the working state lock (DANGEROUS)'),
 ),
@@ -1931,11 +1931,11 @@
 
 """
 
-if opts.get('force_lock'):
+if opts.get('force_free_lock'):
 repo.svfs.unlink(b'lock')
-if opts.get('force_wlock'):
+if opts.get('force_free_wlock'):
 repo.vfs.unlink(b'wlock')
-if opts.get('force_lock') or opts.get('force_wlock'):
+if opts.get('force_free_lock') or opts.get('force_free_wlock'):
 return 0
 
 locks = []



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