annotate hgext/share.py @ 34682:7e3001b74ab3

tersestatus: re-implement the functionality to terse the status The previous terse status implementation was hacking around os.listdir() and was flaky. There have been a lot of instances of mercurial buildbots failing and google's internal builds failing because of the hacky implementation of terse status. Even though I wrote the last implementation but it was hard for me to find the reason for the flake. The new implementation can be slower than the old one but is clean and easy to understand. In this we create a node object for each directory and create a tree like structure starting from the root of the working copy. While building the tree like structure we store some information on the nodes which will be helpful for deciding later whether we can terse the dir or not. Once the whole tree is build we traverse and built the list of files for each status with required tersing. There is no behaviour change as the old test, test-status-terse.t passes with the new implementation. Differential Revision: https://phab.mercurial-scm.org/D985
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 06 Oct 2017 20:54:23 +0530
parents 308aa280ed82
children 68e0bcb90357
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
6 '''share a common history between several working directories
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
7
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
8 Automatic Pooled Storage for Clones
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
9 -----------------------------------
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
10
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
11 When this extension is active, :hg:`clone` can be configured to
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
12 automatically share/pool storage across multiple clones. This
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
13 mode effectively converts :hg:`clone` to :hg:`clone` + :hg:`share`.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
14 The benefit of using this mode is the automatic management of
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
15 store paths and intelligent pooling of related repositories.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
16
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
17 The following ``share.`` config options influence this feature:
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
18
25851
bf3d10f0c34a share: make option docs more check-config friendly
Matt Mackall <mpm@selenic.com>
parents: 25761
diff changeset
19 ``share.pool``
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
20 Filesystem path where shared repository data will be stored. When
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
21 defined, :hg:`clone` will automatically use shared repository
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
22 storage instead of creating a store inside each clone.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
23
25851
bf3d10f0c34a share: make option docs more check-config friendly
Matt Mackall <mpm@selenic.com>
parents: 25761
diff changeset
24 ``share.poolnaming``
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
25 How directory names in ``share.pool`` are constructed.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
26
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
27 "identity" means the name is derived from the first changeset in the
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
28 repository. In this mode, different remotes share storage if their
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
29 root/initial changeset is identical. In this mode, the local shared
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
30 repository is an aggregate of all encountered remote repositories.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
31
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
32 "remote" means the name is derived from the source repository's
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
33 path or URL. In this mode, storage is only shared if the path or URL
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
34 requested in the :hg:`clone` command matches exactly to a repository
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
35 that was cloned before.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
36
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
37 The default naming mode is "identity."
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
38 '''
8873
e872ef2e6758 help: add/fix docstrings for a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8807
diff changeset
39
29485
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
40 from __future__ import absolute_import
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
41
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
42 import errno
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
43 from mercurial.i18n import _
29485
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
44 from mercurial import (
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
45 bookmarks,
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
46 commands,
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
47 error,
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
48 extensions,
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
49 hg,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31334
diff changeset
50 registrar,
31052
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
51 txnutil,
29485
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
52 util,
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
53 )
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
54
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
55 repository = hg.repository
6a98f9408a50 py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29424
diff changeset
56 parseurl = hg.parseurl
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
57
21253
d2ce7a20fe86 share: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 20056
diff changeset
58 cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31334
diff changeset
59 command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29506
diff changeset
60 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24364
diff changeset
61 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24364
diff changeset
62 # be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24364
diff changeset
63 # leave the attribute unspecified.
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29506
diff changeset
64 testedwith = 'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 15082
diff changeset
65
34497
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
66 configtable = {}
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
67 configitem = registrar.configitem(configtable)
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
68
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
69 configitem('share', 'pool',
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
70 default=None,
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
71 )
34498
308aa280ed82 configitems: register the 'share.poolnaming' config
Boris Feld <boris.feld@octobus.net>
parents: 34497
diff changeset
72 configitem('share', 'poolnaming',
308aa280ed82 configitems: register the 'share.poolnaming' config
Boris Feld <boris.feld@octobus.net>
parents: 34497
diff changeset
73 default='identity',
308aa280ed82 configitems: register the 'share.poolnaming' config
Boris Feld <boris.feld@octobus.net>
parents: 34497
diff changeset
74 )
34497
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
75
21253
d2ce7a20fe86 share: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 20056
diff changeset
76 @command('share',
24364
135b23868f45 commands: replace "working copy" with "working directory" in help/messages
Yuya Nishihara <yuya@tcha.org>
parents: 23883
diff changeset
77 [('U', 'noupdate', None, _('do not create a working directory')),
31133
23080c03a604 share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 31052
diff changeset
78 ('B', 'bookmarks', None, _('also share bookmarks')),
23080c03a604 share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 31052
diff changeset
79 ('', 'relative', None, _('point to source using a relative path '
23080c03a604 share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 31052
diff changeset
80 '(EXPERIMENTAL)')),
23080c03a604 share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 31052
diff changeset
81 ],
23614
cd79fb4d75fd share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 23548
diff changeset
82 _('[-U] [-B] SOURCE [DEST]'),
21772
5a4d1a6c605f share: define norepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21253
diff changeset
83 norepo=True)
31133
23080c03a604 share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 31052
diff changeset
84 def share(ui, source, dest=None, noupdate=False, bookmarks=False,
23080c03a604 share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 31052
diff changeset
85 relative=False):
10798
e46c19c586fa share: drop experimental label
Martin Geisler <mg@lazybytes.net>
parents: 10263
diff changeset
86 """create a new shared repository
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
87
9273
4b8b0c124b99 share: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9075
diff changeset
88 Initialize a new repository and working directory that shares its
23614
cd79fb4d75fd share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents: 23548
diff changeset
89 history (and optionally bookmarks) with another repository.
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
90
12389
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
91 .. note::
19997
de16c673455b documentation: add an extra newline after note directive
Simon Heimberg <simohe@besonet.ch>
parents: 19399
diff changeset
92
12389
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
93 using rollback or extensions that destroy/modify history (mq,
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
94 rebase, etc.) can cause considerable confusion with shared
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
95 clones. In particular, if two shared clones are both updated to
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
96 the same changeset, and one of them destroys that changeset
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
97 with rollback, the other clone will suddenly stop working: all
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
98 operations will fail with "abort: working directory has unknown
4ac734b9b3fd Use note admonition
Erik Zielke <ez@aragost.com>
parents: 10798
diff changeset
99 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
100 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
101 """
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
102
27353
98e59d9e0d77 share: pass named arguments
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27186
diff changeset
103 return hg.share(ui, source, dest=dest, update=not noupdate,
31133
23080c03a604 share: add --relative flag to store a relative path to the source
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 31052
diff changeset
104 bookmarks=bookmarks, relative=relative)
8801
28eaf6f8abce share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
105
21253
d2ce7a20fe86 share: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 20056
diff changeset
106 @command('unshare', [], '')
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
107 def unshare(ui, repo):
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
108 """convert a shared repository to a normal one
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
109
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
110 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
111 """
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
112
23666
965788d9ae09 localrepo: introduce shared method to check if a repository is shared
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23626
diff changeset
113 if not repo.shared():
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25851
diff changeset
114 raise error.Abort(_("this is not a shared repo"))
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
115
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
116 destlock = lock = None
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
117 lock = repo.lock()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
118 try:
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
119 # 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
120 # 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
121 # not pointed to by changesets, thus causing verify to
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
122 # fail
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
123
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
124 destlock = hg.copystore(ui, repo, repo.path)
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
125
31334
553680d1b654 share: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31212
diff changeset
126 sharefile = repo.vfs.join('sharedpath')
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
127 util.rename(sharefile, sharefile + '.old')
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
128
31211
ecbd378d9a7e share: fix typo to drop 'shared' requirement on unshare
Yuya Nishihara <yuya@tcha.org>
parents: 31133
diff changeset
129 repo.requirements.discard('shared')
31212
344121b30f32 share: drop 'relshared' requirement as well
Yuya Nishihara <yuya@tcha.org>
parents: 31211
diff changeset
130 repo.requirements.discard('relshared')
15079
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
131 repo._writerequirements()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
132 finally:
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
133 destlock and destlock.release()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
134 lock and lock.release()
ea96bdda593c hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents: 12389
diff changeset
135
25666
1c7e62360068 share: replace reference to 'sopener' with 'svfs'
Siddharth Agarwal <sid0@fb.com>
parents: 25660
diff changeset
136 # update store, spath, svfs and sjoin of repo
20056
cbcd85fa75c0 share: fix unshare calling wrong repo.__init__() method
Brodie Rao <brodie@sf.io>
parents: 19997
diff changeset
137 repo.unfiltered().__init__(repo.baseui, repo.root)
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
138
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
139 # Wrap clone command to pass auto share options.
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
140 def clone(orig, ui, source, *args, **opts):
34497
f9734580f2b6 configitems: register the 'share.pool' config
Boris Feld <boris.feld@octobus.net>
parents: 33515
diff changeset
141 pool = ui.config('share', 'pool')
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
142 if pool:
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
143 pool = util.expandpath(pool)
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
144
33021
24c0a9a7fa86 share: use dict literal instead of dict(key=value)
Yuya Nishihara <yuya@tcha.org>
parents: 33020
diff changeset
145 opts[r'shareopts'] = {
24c0a9a7fa86 share: use dict literal instead of dict(key=value)
Yuya Nishihara <yuya@tcha.org>
parents: 33020
diff changeset
146 'pool': pool,
34498
308aa280ed82 configitems: register the 'share.poolnaming' config
Boris Feld <boris.feld@octobus.net>
parents: 34497
diff changeset
147 'mode': ui.config('share', 'poolnaming'),
33021
24c0a9a7fa86 share: use dict literal instead of dict(key=value)
Yuya Nishihara <yuya@tcha.org>
parents: 33020
diff changeset
148 }
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
149
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
150 return orig(ui, source, *args, **opts)
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
151
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
152 def extsetup(ui):
27186
34d26e22a2b0 bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents: 26933
diff changeset
153 extensions.wrapfunction(bookmarks, '_getbkfile', getbkfile)
33515
3325c7dcabaa bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents: 33021
diff changeset
154 extensions.wrapfunction(bookmarks.bmstore, '_recordchange', recordchange)
26933
a7eecd021782 share: wrap bmstore._writerepo for transaction sensitivity (issue4940)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
155 extensions.wrapfunction(bookmarks.bmstore, '_writerepo', writerepo)
25761
0d37b9b21467 hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25666
diff changeset
156 extensions.wrapcommand(commands.table, 'clone', clone)
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
157
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
158 def _hassharedbookmarks(repo):
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
159 """Returns whether this repo has shared bookmarks"""
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
160 try:
23883
7e71898a7cdc share: replace the bookmarks.shared file with an entry on a new "shared" file
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 23666
diff changeset
161 shared = repo.vfs.read('shared').splitlines()
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25186
diff changeset
162 except IOError as inst:
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
163 if inst.errno != errno.ENOENT:
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
164 raise
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
165 return False
29424
f21e0d91d386 share: move magic string to a constant
Martijn Pieters <mjpieters@fb.com>
parents: 27353
diff changeset
166 return hg.sharedbookmarks in shared
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
167
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
168 def _getsrcrepo(repo):
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
169 """
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
170 Returns the source repository object for a given shared repository.
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
171 If repo is not a shared repository, return None.
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
172 """
23626
012a7b482d68 share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents: 23625
diff changeset
173 if repo.sharedpath == repo.path:
012a7b482d68 share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents: 23625
diff changeset
174 return None
012a7b482d68 share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents: 23625
diff changeset
175
29506
2550604f5ec7 share: don't recreate the source repo each time
Durham Goode <durham@fb.com>
parents: 29485
diff changeset
176 if util.safehasattr(repo, 'srcrepo') and repo.srcrepo:
2550604f5ec7 share: don't recreate the source repo each time
Durham Goode <durham@fb.com>
parents: 29485
diff changeset
177 return repo.srcrepo
2550604f5ec7 share: don't recreate the source repo each time
Durham Goode <durham@fb.com>
parents: 29485
diff changeset
178
23626
012a7b482d68 share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents: 23625
diff changeset
179 # the sharedpath always ends in the .hg; we want the path to the repo
012a7b482d68 share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents: 23625
diff changeset
180 source = repo.vfs.split(repo.sharedpath)[0]
012a7b482d68 share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents: 23625
diff changeset
181 srcurl, branches = parseurl(source)
29506
2550604f5ec7 share: don't recreate the source repo each time
Durham Goode <durham@fb.com>
parents: 29485
diff changeset
182 srcrepo = repository(repo.ui, srcurl)
2550604f5ec7 share: don't recreate the source repo each time
Durham Goode <durham@fb.com>
parents: 29485
diff changeset
183 repo.srcrepo = srcrepo
2550604f5ec7 share: don't recreate the source repo each time
Durham Goode <durham@fb.com>
parents: 29485
diff changeset
184 return srcrepo
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
185
27186
34d26e22a2b0 bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents: 26933
diff changeset
186 def getbkfile(orig, repo):
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
187 if _hassharedbookmarks(repo):
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
188 srcrepo = _getsrcrepo(repo)
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
189 if srcrepo is not None:
31052
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
190 # just orig(srcrepo) doesn't work as expected, because
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
191 # HG_PENDING refers repo.root.
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
192 try:
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
193 fp, pending = txnutil.trypending(repo.root, repo.vfs,
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
194 'bookmarks')
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
195 if pending:
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
196 # only in this case, bookmark information in repo
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
197 # is up-to-date.
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
198 return fp
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
199 fp.close()
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
200 except IOError as inst:
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
201 if inst.errno != errno.ENOENT:
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
202 raise
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
203
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
204 # otherwise, we should read bookmarks from srcrepo,
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
205 # because .hg/bookmarks in srcrepo might be already
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
206 # changed via another sharing repo
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
207 repo = srcrepo
31052
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
208
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
209 # TODO: Pending changes in repo are still invisible in
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
210 # srcrepo, because bookmarks.pending is written only into repo.
0332b8fafd05 bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 29841
diff changeset
211 # See also https://www.mercurial-scm.org/wiki/SharedRepository
27186
34d26e22a2b0 bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents: 26933
diff changeset
212 return orig(repo)
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
213
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
214 def recordchange(orig, self, tr):
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
215 # Continue with write to local bookmarks file as usual
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
216 orig(self, tr)
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
217
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
218 if _hassharedbookmarks(self._repo):
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
219 srcrepo = _getsrcrepo(self._repo)
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
220 if srcrepo is not None:
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
221 category = 'share-bookmarks'
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
222 tr.addpostclose(category, lambda tr: self._writerepo(srcrepo))
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
223
26933
a7eecd021782 share: wrap bmstore._writerepo for transaction sensitivity (issue4940)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
224 def writerepo(orig, self, repo):
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
225 # First write local bookmarks file in case we ever unshare
26933
a7eecd021782 share: wrap bmstore._writerepo for transaction sensitivity (issue4940)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
226 orig(self, repo)
a7eecd021782 share: wrap bmstore._writerepo for transaction sensitivity (issue4940)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
227
23548
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
228 if _hassharedbookmarks(self._repo):
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
229 srcrepo = _getsrcrepo(self._repo)
141baca16059 share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents: 21772
diff changeset
230 if srcrepo is not None:
26933
a7eecd021782 share: wrap bmstore._writerepo for transaction sensitivity (issue4940)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
231 orig(self, srcrepo)