hgext/share.py
author Angel Ezquerra <angel.ezquerra@gmail.com>
Fri, 06 Sep 2013 00:38:28 +0200
changeset 19811 5e10d41e7b9c
parent 19399 02465cafb0a9
child 19997 de16c673455b
permissions -rw-r--r--
merge: let the user choose to merge, keep local or keep remote subrepo revisions When a subrepo has changed on the local and remote revisions, prompt the user whether it wants to merge those subrepo revisions, keep the local revision or keep the remote revision. Up until now mercurial would always perform a merge on a subrepo that had changed on the local and the remote revisions. This is often inconvenient. For example: - You may want to perform the actual subrepo merge after you have merged the parent subrepo files. - Some subrepos may be considered "read only", in the sense that you are not supposed to add new revisions to them. In those cases "merging a subrepo" means choosing which _existing_ revision you want to use on the merged revision. This is often the case for subrepos that contain binary dependencies (such as DLLs, etc). This new prompt makes mercurial better cope with those common scenarios. Notes: - The default behavior (which is the one that is used when ui is not interactive) remains unchanged (i.e. merge is the default action). - This prompt will be shown even if the ui --tool flag is set. - I don't know of a way to test the "keep local" and "keep remote" options (i.e. to force the test to choose those options). # HG changeset patch # User Angel Ezquerra <angel.ezquerra@gmail.com> # Date 1378420708 -7200 # Fri Sep 06 00:38:28 2013 +0200 # Node ID 2fb9cb0c7b26303ac3178b7739975e663075857d # Parent 50d721553198cea51c30f53b76d41dc919280097 merge: let the user choose to merge, keep local or keep remote subrepo revisions When a subrepo has changed on the local and remote revisions, prompt the user whether it wants to merge those subrepo revisions, keep the local revision or keep the remote revision. Up until now mercurial would always perform a merge on a subrepo that had changed on the local and the remote revisions. This is often inconvenient. For example: - You may want to perform the actual subrepo merge after you have merged the parent subrepo files. - Some subrepos may be considered "read only", in the sense that you are not supposed to add new revisions to them. In those cases "merging a subrepo" means choosing which _existing_ revision you want to use on the merged revision. This is often the case for subrepos that contain binary dependencies (such as DLLs, etc). This new prompt makes mercurial better cope with those common scenarios. Notes: - The default behavior (which is the one that is used when ui is not interactive) remains unchanged (i.e. merge is the default action). - This prompt will be shown even if the ui --tool flag is set. - I don't know of a way to test the "keep local" and "keep remote" options (i.e. to force the test to choose those options).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
# Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
#
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10256
diff changeset
     4
# GNU General Public License version 2 or any later version.
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
8894
868670dbc237 extensions: improve the consistency of synopses
Cédric Duval <cedricduval@free.fr>
parents: 8873
diff changeset
     6
'''share a common history between several working directories'''
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8807
diff changeset
     7
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     8
from mercurial.i18n import _
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
     9
from mercurial import hg, commands, util
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    10
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 15082
diff changeset
    11
testedwith = 'internal'
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 15082
diff changeset
    12
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8801
diff changeset
    13
def share(ui, source, dest=None, noupdate=False):
10798
e46c19c586fa share: drop experimental label
Martin Geisler <mg@lazybytes.net>
parents: 10263
diff changeset
    14
    """create a new shared repository
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
9273
4b8b0c124b99 share: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9075
diff changeset
    16
    Initialize a new repository and working directory that shares its
4b8b0c124b99 share: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9075
diff changeset
    17
    history with another repository.
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
12389
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    19
    .. note::
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    20
       using rollback or extensions that destroy/modify history (mq,
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    21
       rebase, etc.) can cause considerable confusion with shared
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    22
       clones. In particular, if two shared clones are both updated to
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    23
       the same changeset, and one of them destroys that changeset
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    24
       with rollback, the other clone will suddenly stop working: all
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    25
       operations will fail with "abort: working directory has unknown
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
    26
       parent". The only known workaround is to use debugsetparents on
19399
02465cafb0a9 share: remove reference to tip
Matt Mackall <mpm@selenic.com>
parents: 18825
diff changeset
    27
       the broken clone to reset it to a changeset that still exists.
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    28
    """
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    29
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    30
    return hg.share(ui, source, dest, not noupdate)
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    31
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    32
def unshare(ui, repo):
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    33
    """convert a shared repository to a normal one
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    34
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    35
    Copy the store data to the repo and remove the sharedpath data.
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    36
    """
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    37
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    38
    if repo.sharedpath == repo.path:
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    39
        raise util.Abort(_("this is not a shared repo"))
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    40
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    41
    destlock = lock = None
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    42
    lock = repo.lock()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    43
    try:
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    44
        # we use locks here because if we race with commit, we
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    45
        # can end up with extra data in the cloned revlogs that's
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    46
        # not pointed to by changesets, thus causing verify to
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    47
        # fail
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    48
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    49
        destlock = hg.copystore(ui, repo, repo.path)
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    50
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    51
        sharefile = repo.join('sharedpath')
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    52
        util.rename(sharefile, sharefile + '.old')
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    53
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    54
        repo.requirements.discard('sharedpath')
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    55
        repo._writerequirements()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    56
    finally:
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    57
        destlock and destlock.release()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    58
        lock and lock.release()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    59
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    60
    # update store, spath, sopener and sjoin of repo
18825
f0564402d059 repo: repo isolation, do not pass on repo.ui for creating new repos
Simon Heimberg <simohe@besonet.ch>
parents: 16743
diff changeset
    61
    repo.__init__(repo.baseui, repo.root)
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    62
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    63
cmdtable = {
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    64
    "share":
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    65
    (share,
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    66
     [('U', 'noupdate', None, _('do not create a working copy'))],
8807
8bf6eb68ddaf share: allow dest to default to the basename of source
Matt Mackall <mpm@selenic.com>
parents: 8801
diff changeset
    67
     _('[-U] SOURCE [DEST]')),
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    68
    "unshare":
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    69
    (unshare,
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    70
    [],
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
    71
    ''),
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    72
}
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    73
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    74
commands.norepo += " share"