Patchwork [2,of,3,V4] share: add option to share bookmarks

login
register
mail settings
Submitter Ryan McElroy
Date Dec. 13, 2014, 11:38 p.m.
Message ID <171b35bf7af924443ac6.1418513935@devbig105.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7081/
State Accepted
Commit cd79fb4d75fdbf30d6a70f9cd648a3ffeb8084d3
Delegated to: Matt Mackall
Headers show

Comments

Ryan McElroy - Dec. 13, 2014, 11:38 p.m.
# HG changeset patch
# User Ryan McElroy <rmcelroy@fb.com>
# Date 1418499166 28800
#      Sat Dec 13 11:32:46 2014 -0800
# Node ID 171b35bf7af924443ac66ebc0d874081b835dd82
# Parent  2690905597384d8748f00b5ed36dfec4c8922051
share: add option to share bookmarks

This patch adds the -B/--bookmarks option to the share command added by the
share extension. All it does for now is create a marker, 'bookmarks.shared',
that will be used by future code to implement the sharing functionality.
Matt Mackall - Dec. 19, 2014, 8:33 p.m.
On Sat, 2014-12-13 at 15:38 -0800, Ryan McElroy wrote:
> # HG changeset patch
> # User Ryan McElroy <rmcelroy@fb.com>
> # Date 1418499166 28800
> #      Sat Dec 13 11:32:46 2014 -0800
> # Node ID 171b35bf7af924443ac66ebc0d874081b835dd82
> # Parent  2690905597384d8748f00b5ed36dfec4c8922051
> share: add option to share bookmarks

This one's queued for default, thanks.

Patch

diff --git a/hgext/share.py b/hgext/share.py
--- a/hgext/share.py
+++ b/hgext/share.py
@@ -15,14 +15,15 @@  command = cmdutil.command(cmdtable)
 testedwith = 'internal'
 
 @command('share',
-    [('U', 'noupdate', None, _('do not create a working copy'))],
-    _('[-U] SOURCE [DEST]'),
+    [('U', 'noupdate', None, _('do not create a working copy')),
+     ('B', 'bookmarks', None, _('also share bookmarks'))],
+    _('[-U] [-B] SOURCE [DEST]'),
     norepo=True)
-def share(ui, source, dest=None, noupdate=False):
+def share(ui, source, dest=None, noupdate=False, bookmarks=False):
     """create a new shared repository
 
     Initialize a new repository and working directory that shares its
-    history with another repository.
+    history (and optionally bookmarks) with another repository.
 
     .. note::
 
@@ -36,7 +37,7 @@  def share(ui, source, dest=None, noupdat
        the broken clone to reset it to a changeset that still exists.
     """
 
-    return hg.share(ui, source, dest, not noupdate)
+    return hg.share(ui, source, dest, not noupdate, bookmarks)
 
 @command('unshare', [], '')
 def unshare(ui, repo):
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -158,7 +158,7 @@  def defaultdest(source):
         return ''
     return os.path.basename(os.path.normpath(path))
 
-def share(ui, source, dest=None, update=True):
+def share(ui, source, dest=None, update=True, bookmarks=True):
     '''create a shared repository'''
 
     if not islocal(source):
@@ -225,6 +225,9 @@  def share(ui, source, dest=None, update=
                 continue
         _update(r, uprev)
 
+    if bookmarks:
+        r.opener('bookmarks.shared', 'w').close()
+
 def copystore(ui, srcrepo, destpath):
     '''copy files from store of srcrepo in destpath
 
diff --git a/tests/test-share.t b/tests/test-share.t
--- a/tests/test-share.t
+++ b/tests/test-share.t
@@ -129,9 +129,9 @@  check that a change does not propagate
   $ cd ..
 
 
-test sharing bookmarks (manually add bookmarks.shared file for now)
+test sharing bookmarks
 
-  $ hg share repo1 repo3 && touch repo3/.hg/bookmarks.shared
+  $ hg share -B repo1 repo3
   updating working directory
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd repo1
@@ -212,7 +212,7 @@  test pushing bookmarks works
 
 test behavior when sharing a shared repo
 
-  $ hg share repo3 repo5 && touch repo5/.hg/bookmarks.shared
+  $ hg share -B repo3 repo5
   updating working directory
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ cd repo5