Patchwork [1,of,8,shelve-ext,v2] shelve: move possible shelve file extensions to a single place

login
register
mail settings
Submitter Kostia Balytskyi
Date Nov. 10, 2016, 11:37 a.m.
Message ID <ee1dc341d44f9408bdf9.1478777845@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/17437/
State Accepted
Headers show

Comments

Kostia Balytskyi - Nov. 10, 2016, 11:37 a.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1478776040 28800
#      Thu Nov 10 03:07:20 2016 -0800
# Node ID ee1dc341d44f9408bdf960eb5a97abf1a1c69930
# Parent  494d5cec0b07653a6b5daaaaec768dea92ffa987
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.

This particular commit introduces a slight behavior change. Previously,
if only .hg/shelve/name.patch file exists, but .hg/name.hg does not,
'hg shelve -d name' would fail saying "shelve not found". Now deletion
will only fail if .patch file does not exist (since .patch is used
as an indicator of an existing shelve). Other shelve files being absent
are skipped silently to accommodate for future introduction of obs-based
shelve, which will mean that for some shelves .hg and .patch files exist,
while for others .hg and .oshelve.
Yuya Nishihara - Nov. 13, 2016, 11:16 a.m.
On Thu, 10 Nov 2016 03:37:25 -0800, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia@fb.com>
> # Date 1478776040 28800
> #      Thu Nov 10 03:07:20 2016 -0800
> # Node ID ee1dc341d44f9408bdf960eb5a97abf1a1c69930
> # Parent  494d5cec0b07653a6b5daaaaec768dea92ffa987
> shelve: move possible shelve file extensions to a single place

The overall series looks very nice. Queued them, thanks.

Patch

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,8 +565,10 @@  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():
-            shelvedfile(repo, name, filetype).movetobackup()
+        for filetype in shelvefileextensions:
+            shfile = shelvedfile(repo, name, filetype)
+            if shfile.exists():
+                shfile.movetobackup()
         cleanupoldbackups(repo)
 
 def unshelvecontinue(ui, repo, state, opts):