[PATCH] shelve: support shared repositories

Oleg Afanasyev olegaf at fb.com
Mon Mar 14 12:34:33 EDT 2016


# HG changeset patch
# User Oleg Afanasyev <olegaf at fb.com>
# Date 1457972723 25200
#      Mon Mar 14 09:25:23 2016 -0700
# Node ID 6ec353e7cc031f453d26925fcbf15a035aaf2c90
# Parent  1c658391b22fb4d98ccfb60c0e57315b55634117
shelve: support shared repositories

Shelve will use shared data instead of its own shelves. That would
allow moving changes from share to share using shelve.

When unshare is performed shelve will not be cloned to new repo. That
would change behaviour from what it is doing now e.g. shelves created
in share will disappear when unshare is done vs now shares have their
own shelves.

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -61,6 +61,12 @@
 
 backupdir = 'shelve-backup'
 
+def shareawarevfs(repo):
+    if repo.shared():
+        return scmutil.vfs(repo.sharedpath)
+    else:
+        return repo.vfs
+
 class shelvedfile(object):
     """Helper for the file storing a single shelve
 
@@ -69,7 +75,7 @@
     def __init__(self, repo, name, filetype=None):
         self.repo = repo
         self.name = name
-        self.vfs = scmutil.vfs(repo.join('shelved'))
+        self.vfs = scmutil.vfs(shareawarevfs(repo).join('shelved'))
         self.backupvfs = scmutil.vfs(repo.join(backupdir))
         self.ui = self.repo.ui
         if filetype:
@@ -387,7 +393,7 @@
     """subcommand that deletes all shelves"""
 
     with repo.wlock():
-        for (name, _type) in repo.vfs.readdir('shelved'):
+        for (name, _type) in shareawarevfs(repo).readdir('shelved'):
             suffix = name.rsplit('.', 1)[-1]
             if suffix in ('hg', 'patch'):
                 shelvedfile(repo, name).movetobackup()
@@ -411,7 +417,7 @@
 def listshelves(repo):
     """return all shelves in repo as list of (time, filename)"""
     try:
-        names = repo.vfs.readdir('shelved')
+        names = shareawarevfs(repo).readdir('shelved')
     except OSError as err:
         if err.errno != errno.ENOENT:
             raise
diff --git a/tests/test-share.t b/tests/test-share.t
--- a/tests/test-share.t
+++ b/tests/test-share.t
@@ -2,6 +2,7 @@
 
   $ echo "[extensions]"      >> $HGRCPATH
   $ echo "share = "          >> $HGRCPATH
+  $ echo "shelve = "         >> $HGRCPATH
 
 prepare repo1
 
@@ -297,6 +298,89 @@
      bm4                       5:92793bfc8cad
   $ cd ..
 
+test sharing shelve
+
+  $ hg init shelfrepo1
+  $ cd shelfrepo1
+  $ echo a > a
+  $ hg commit -A -m'init'
+  adding a
+
+  $ cd ..
+  $ hg share shelfrepo1 shelfrepo2
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+shelve changes in original repo
+
+  $ cd shelfrepo1
+  $ echo b > b
+  $ hg add b
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+shelve changes in shared repo
+
+  $ cd ../shelfrepo2
+  $ echo c > c
+  $ hg add c
+  $ hg shelve
+  shelved as default-01
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+
+test if all shelves are visible in both repos
+
+  $ hg shelve -l
+  default-01      (1s ago)    changes to: init
+  default         (1s ago)    changes to: init
+  $ cd ../shelfrepo1
+  $ hg shelve -l
+  default-01      (1s ago)    changes to: init
+  default         (1s ago)    changes to: init
+
+test if shared changes are unshelved in original repo
+
+  $ hg unshelve
+  unshelving change 'default-01'
+  $ test -f c
+  $ hg shelve -l
+  default         (1s ago)    changes to: init
+
+test if original changes are unshelved in shared repo
+
+  $ cd ../shelfrepo2
+  $ hg shelve -l
+  default         (1s ago)    changes to: init
+  $ hg unshelve
+  unshelving change 'default'
+  $ test -f b
+  $ hg shelve -l
+
+test if first shelf is unshelved in original repo
+
+  $ cd ../shelfrepo1
+  $ hg shelve -l
+  $ cd ..
+
+test shelf behaviour after unshare
+
+  $ hg share shelfrepo1 shelfrepo3
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd shelfrepo1
+  $ hg shelve
+  shelved as default
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ cd ../shelfrepo3
+  $ hg unshare
+  $ hg unshelve
+  abort: no shelved changes to apply!
+  [255]
+  $ cd ../shelfrepo1
+  $ hg shelve -l
+  default         (1s ago)    changes to: init
+
 Explicitly kill daemons to let the test exit on Windows
 
   $ killdaemons.py


More information about the Mercurial-devel mailing list