Patchwork [06,of,10,shelve-ext] shelve: add obs-based shelve functionality

login
register
mail settings
Submitter Kostia Balytskyi
Date Nov. 29, 2016, 3:23 p.m.
Message ID <d1356cbb72cfe91a2b42.1480432980@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/17788/
State Accepted
Headers show

Comments

Kostia Balytskyi - Nov. 29, 2016, 3:23 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1480427179 28800
#      Tue Nov 29 05:46:19 2016 -0800
# Node ID d1356cbb72cfe91a2b427098c66bc00937912d79
# Parent  7f225df4c58b4f62a7883f95349cdb9e9c86e15e
shelve: add obs-based shelve functionality

Obsolescense-based shelve works in a following way:
1. In order to shelve some changes, it creates a commit, records its
node into a .oshelve file and prunes created commit.
2. In order to finish a shelve operation, transaction is just
closed and not aborted.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -379,9 +379,16 @@  def _nothingtoshelvemessaging(ui, repo, 
     else:
         ui.status(_("nothing changed\n"))
 
-def _shelvecreatedcommit(repo, node, name):
-    bases = list(mutableancestors(repo[node]))
-    shelvedfile(repo, name, 'hg').writebundle(bases, node)
+def _shelvecreatedcommit(ui, repo, node, name, tr):
+    if isobsshelve(repo, ui):
+        unfi = repo.unfiltered()
+        obsolete.createmarkers(repo, [(unfi[node], ())])
+        shelvedfile(repo, name, 'oshelve').writejson({
+            'node': nodemod.hex(node)
+        })
+    else:
+        bases = list(mutableancestors(repo[node]))
+        shelvedfile(repo, name, 'hg').writebundle(bases, node)
     cmdutil.export(repo, [node],
                    fp=shelvedfile(repo, name, patchextension).opener('wb'),
                    opts=mdiff.diffopts(git=True))
@@ -393,8 +400,12 @@  def _includeunknownfiles(repo, pats, opt
         extra['shelve_unknown'] = '\0'.join(s.unknown)
         repo[None].add(s.unknown)
 
-def _finishshelve(repo):
-    _aborttransaction(repo)
+def _finishshelve(ui, repo, tr):
+    if isobsshelve(repo, ui):
+        tr.close()
+        tr.release()
+    else:
+        _aborttransaction(repo)
 
 def _docreatecmd(ui, repo, pats, opts):
     wctx = repo[None]
@@ -416,9 +427,12 @@  def _docreatecmd(ui, repo, pats, opts):
     try:
         lock = repo.lock()
 
-        # use an uncommitted transaction to generate the bundle to avoid
-        # pull races. ensure we don't print the abort message to stderr.
-        tr = repo.transaction('commit', report=lambda x: None)
+        # depending on whether shelve is traditional or
+        # obsolescense-based, we either abort or commit this
+        # transaction in the end. If we abort it, we don't
+        # want to print anything to stderr
+        report = None if isobsshelve(repo, ui) else (lambda x: None)
+        tr = repo.transaction('commit', report=report)
 
         interactive = opts.get('interactive', False)
         includeunknown = (opts.get('unknown', False) and
@@ -444,7 +458,7 @@  def _docreatecmd(ui, repo, pats, opts):
             _nothingtoshelvemessaging(ui, repo, pats, opts)
             return 1
 
-        _shelvecreatedcommit(repo, node, name)
+        _shelvecreatedcommit(ui, repo, node, name, tr)
 
         if ui.formatted():
             desc = util.ellipsis(desc, ui.termwidth())
@@ -453,7 +467,7 @@  def _docreatecmd(ui, repo, pats, opts):
         if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
             repo.dirstate.setbranch(origbranch)
 
-        _finishshelve(repo)
+        _finishshelve(ui, repo, tr)
     finally:
         lockmod.release(tr, lock)