[PATCH 1 of 8 shelve-ext] shelve: move possible shelve file extensions to a single place
Kostia Balytskyi
ikostia at fb.com
Tue Nov 8 13:33:41 EST 2016
I have already found some bugs in these refactorings, which surface themselves when I am trying to add obsolescence-based shelve. I will fix those and send a v2. In a meantime, any comments are very welcome.
On 11/8/16, 1:51 PM, "Mercurial-devel on behalf of Kostia Balytskyi" <mercurial-devel-bounces at mercurial-scm.org on behalf of ikostia at fb.com> wrote:
# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1478529210 28800
# Mon Nov 07 06:33:30 2016 -0800
# Node ID b2d851fac63c8e12605948c7d182f86974b5096c
# Parent d500ddae7494772e5eb867fccc6876f5f0c21dac
shelve: move possible shelve file extensions to a single place
This and a couple of following patches are a preparation to
implementing obsolescense-enabled shelve which was discussed
on a Sprint. If this refactoring is not done, shelve is going
to look even more hackish than now.
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -62,6 +62,7 @@ testedwith = 'ships-with-hg-core'
backupdir = 'shelve-backup'
shelvedir = 'shelved'
+shelvefileextensions = ['hg', 'patch']
class shelvedfile(object):
"""Helper for the file storing a single shelve
@@ -221,7 +222,7 @@ def cleanupoldbackups(repo):
# keep it, because timestamp can't decide exact order of backups
continue
base = f[:-3]
- for ext in 'hg patch'.split():
+ for ext in shelvefileextensions:
try:
vfs.unlink(base + '.' + ext)
except OSError as err:
@@ -399,7 +400,7 @@ def cleanupcmd(ui, repo):
with repo.wlock():
for (name, _type) in repo.vfs.readdir(shelvedir):
suffix = name.rsplit('.', 1)[-1]
- if suffix in ('hg', 'patch'):
+ if suffix in shelvefileextensions:
shelvedfile(repo, name).movetobackup()
cleanupoldbackups(repo)
@@ -410,8 +411,15 @@ def deletecmd(ui, repo, pats):
with repo.wlock():
try:
for name in pats:
- for suffix in 'hg patch'.split():
- shelvedfile(repo, name, suffix).movetobackup()
+ 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 == 'patch':
+ shfile.movetobackup()
cleanupoldbackups(repo)
except OSError as err:
if err.errno != errno.ENOENT:
@@ -557,7 +565,7 @@ def restorebranch(ui, repo, branchtorest
def unshelvecleanup(ui, repo, name, opts):
"""remove related files after an unshelve"""
if not opts.get('keep'):
- for filetype in 'hg patch'.split():
+ for filetype in shelvefileextensions:
shelvedfile(repo, name, filetype).movetobackup()
cleanupoldbackups(repo)
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel at mercurial-scm.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=DQIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=j4MF6YwF5GBNZqgBlHpqrc4maAhwOiM-cjjiuF_MQoE&s=6ECsPeS8UkS-4d7x6CRYFYeXVrlio1N5b8eBTUHIu3s&e=
More information about the Mercurial-devel
mailing list