sapling/eden/scm/edenscm/hgext/share.py

85 lines
2.5 KiB
Python
Raw Normal View History

# Portions Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
# Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
2010-01-20 07:20:08 +03:00
# GNU General Public License version 2 or any later version.
"""share a common history between several working directories"""
from __future__ import absolute_import
from edenscm.mercurial import error, hg, registrar
from edenscm.mercurial.i18n import _
repository = hg.repository
2011-08-11 02:04:00 +04:00
cmdtable = {}
command = registrar.command(cmdtable)
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
testedwith = "ships-with-hg-core"
@command(
"share",
[
("U", "noupdate", None, _("do not create a working directory")),
("B", "bookmarks", None, _("also share bookmarks")),
(
"",
"relative",
None,
_("point to source using a relative path " "(EXPERIMENTAL)"),
),
],
_("[-U] [-B] SOURCE [DEST]"),
norepo=True,
)
def share(ui, source, dest=None, noupdate=False, bookmarks=False, relative=False):
"""create a new shared repository
Initialize a new repository and working directory that shares its
history (and optionally bookmarks) with another repository.
2010-09-22 18:23:55 +04:00
.. note::
using rollback or extensions that destroy/modify history (amend,
2010-09-22 18:23:55 +04:00
rebase, etc.) can cause considerable confusion with shared
clones. In particular, if two shared clones are both updated to
the same changeset, and one of them destroys that changeset
with rollback, the other clone will suddenly stop working: all
operations will fail with "abort: working directory has unknown
parent". The only known workaround is to use debugsetparents on
2013-07-12 04:26:53 +04:00
the broken clone to reset it to a changeset that still exists.
"""
hg.share(
ui,
source,
dest=dest,
update=not noupdate,
bookmarks=bookmarks,
relative=relative,
)
subrepo: share instead of clone if the parent repo is shared (issue5675) (BC) Previously, only the top level repo was shared, and then any subrepos were cloned on demand. This is problematic because commits to the parent repo would write an updated .hgsubstate to the share source, but the corresponding subrepo commit would be stuck in the local subrepo. That would prevent an update in the source repo. We already go to great lengths to avoid having inconsistent repos (e.g., `hg push -r rev` will push _everything_ in a subrepo, even if it isn't referenced in one of the parent's outgoing commits). Therefore, this seems like a bug fix, and there's no option to get the old behavior. I can't imagine the previous behavior was useful to anybody. There shouldn't be an issue with svn, since it is centralized. Maybe --git-dir can be used for git subrepos, but I'll leave that to someone more familiar with git. An integer was previously being implicitly returned from commands.share(), which caused dispatch() to start crashing when changing over to returning the shared repo. All error paths appear to raise, so this can be hardcoded to success. The clone command checks for 'is None' in a similar pattern, but since hg.clone() always returns a tuple, that seems wrong? .. fix:: Issue 5675 Creating a share of a repository with a Mercurial subrepository will now share the subrepository. and .. bc:: Mercurial subrepositories are now shared instead of cloned when the parent repository is shared. This prevents dangling subrepository references in the share source. Previously shared repositories with cloned subrepositories will continue to function unchanged.
2017-10-16 05:48:02 +03:00
return 0
@command("unshare", [], "")
2011-08-11 02:04:00 +04:00
def unshare(ui, repo):
"""convert a shared repository to a normal one
Copy the store data to the repo and remove the sharedpath data.
"""
if not repo.shared():
raise error.Abort(_("this is not a shared repo"))
2011-08-11 02:04:00 +04:00
hg.unshare(ui, repo)