Mercurial > hg
annotate hgext/share.py @ 26833:6474b64045fb stable
packaging: rework version detection and declaration (issue4912)
Previously the -rc in our rc tags got dropped, meaning that those
packages looked newer to the packaging system than the later release
build. This rectifies the issue, though some damage may already have
been done on 3.6-rc builds.
I'm mostly cargo-culting the RPM version format - there don't appear
to be rules for RPM about how to handle this. Hopefully an RPM
enthusiast can fix up what I've done as a followup.
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 26 Oct 2015 14:19:37 -0400 |
parents | 56b2bcea2529 |
children | a7eecd021782 |
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 | 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 |
8801
28eaf6f8abce
share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
40 from mercurial.i18n import _ |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25851
diff
changeset
|
41 from mercurial import cmdutil, commands, hg, util, extensions, bookmarks, error |
23548
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
42 from mercurial.hg import repository, parseurl |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
43 import errno |
15079
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
44 |
21253
d2ce7a20fe86
share: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20056
diff
changeset
|
45 cmdtable = {} |
d2ce7a20fe86
share: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20056
diff
changeset
|
46 command = cmdutil.command(cmdtable) |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24364
diff
changeset
|
47 # Note for extension authors: ONLY specify testedwith = 'internal' for |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
24364
diff
changeset
|
48 # 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
|
49 # 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
|
50 # leave the attribute unspecified. |
16743
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
15082
diff
changeset
|
51 testedwith = 'internal' |
38caf405d010
hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents:
15082
diff
changeset
|
52 |
21253
d2ce7a20fe86
share: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20056
diff
changeset
|
53 @command('share', |
24364
135b23868f45
commands: replace "working copy" with "working directory" in help/messages
Yuya Nishihara <yuya@tcha.org>
parents:
23883
diff
changeset
|
54 [('U', 'noupdate', None, _('do not create a working directory')), |
23614
cd79fb4d75fd
share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
23548
diff
changeset
|
55 ('B', 'bookmarks', None, _('also share bookmarks'))], |
cd79fb4d75fd
share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
23548
diff
changeset
|
56 _('[-U] [-B] SOURCE [DEST]'), |
21772
5a4d1a6c605f
share: define norepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21253
diff
changeset
|
57 norepo=True) |
23614
cd79fb4d75fd
share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
23548
diff
changeset
|
58 def share(ui, source, dest=None, noupdate=False, bookmarks=False): |
10798
e46c19c586fa
share: drop experimental label
Martin Geisler <mg@lazybytes.net>
parents:
10263
diff
changeset
|
59 """create a new shared repository |
8801
28eaf6f8abce
share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
60 |
9273
4b8b0c124b99
share: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9075
diff
changeset
|
61 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
|
62 history (and optionally bookmarks) with another repository. |
8801
28eaf6f8abce
share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
63 |
12389 | 64 .. note:: |
19997
de16c673455b
documentation: add an extra newline after note directive
Simon Heimberg <simohe@besonet.ch>
parents:
19399
diff
changeset
|
65 |
12389 | 66 using rollback or extensions that destroy/modify history (mq, |
67 rebase, etc.) can cause considerable confusion with shared | |
68 clones. In particular, if two shared clones are both updated to | |
69 the same changeset, and one of them destroys that changeset | |
70 with rollback, the other clone will suddenly stop working: all | |
71 operations will fail with "abort: working directory has unknown | |
72 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
|
73 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
|
74 """ |
28eaf6f8abce
share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
75 |
23614
cd79fb4d75fd
share: add option to share bookmarks
Ryan McElroy <rmcelroy@fb.com>
parents:
23548
diff
changeset
|
76 return hg.share(ui, source, dest, not noupdate, bookmarks) |
8801
28eaf6f8abce
share: add experimental share extension
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
77 |
21253
d2ce7a20fe86
share: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20056
diff
changeset
|
78 @command('unshare', [], '') |
15079
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
79 def unshare(ui, repo): |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
80 """convert a shared repository to a normal one |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
81 |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
82 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
|
83 """ |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
84 |
23666
965788d9ae09
localrepo: introduce shared method to check if a repository is shared
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23626
diff
changeset
|
85 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
|
86 raise error.Abort(_("this is not a shared repo")) |
15079
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
87 |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
88 destlock = lock = None |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
89 lock = repo.lock() |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
90 try: |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
91 # 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
|
92 # 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
|
93 # not pointed to by changesets, thus causing verify to |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
94 # fail |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
95 |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
96 destlock = hg.copystore(ui, repo, repo.path) |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
97 |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
98 sharefile = repo.join('sharedpath') |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
99 util.rename(sharefile, sharefile + '.old') |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
100 |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
101 repo.requirements.discard('sharedpath') |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
102 repo._writerequirements() |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
103 finally: |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
104 destlock and destlock.release() |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
105 lock and lock.release() |
ea96bdda593c
hgext: introduce unshare command
Simon Heimberg <simohe@besonet.ch>
parents:
12389
diff
changeset
|
106 |
25666
1c7e62360068
share: replace reference to 'sopener' with 'svfs'
Siddharth Agarwal <sid0@fb.com>
parents:
25660
diff
changeset
|
107 # 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
|
108 repo.unfiltered().__init__(repo.baseui, repo.root) |
23548
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
109 |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
110 # 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
|
111 def clone(orig, ui, source, *args, **opts): |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
112 pool = ui.config('share', 'pool', None) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
113 if pool: |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
114 pool = util.expandpath(pool) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
115 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
116 opts['shareopts'] = dict( |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
117 pool=pool, |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
118 mode=ui.config('share', 'poolnaming', 'identity'), |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
119 ) |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
120 |
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
121 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
|
122 |
23548
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
123 def extsetup(ui): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
124 extensions.wrapfunction(bookmarks.bmstore, 'getbkfile', getbkfile) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
125 extensions.wrapfunction(bookmarks.bmstore, 'recordchange', recordchange) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
126 extensions.wrapfunction(bookmarks.bmstore, 'write', write) |
25761
0d37b9b21467
hg: support for auto sharing stores when cloning
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25666
diff
changeset
|
127 extensions.wrapcommand(commands.table, 'clone', clone) |
23548
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
128 |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
129 def _hassharedbookmarks(repo): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
130 """Returns whether this repo has shared bookmarks""" |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
131 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
|
132 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
|
133 except IOError as inst: |
23548
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
134 if inst.errno != errno.ENOENT: |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
135 raise |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
136 return False |
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
|
137 return 'bookmarks' in shared |
23548
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
138 |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
139 def _getsrcrepo(repo): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
140 """ |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
141 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
|
142 If repo is not a shared repository, return None. |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
143 """ |
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
|
144 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
|
145 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
|
146 |
012a7b482d68
share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
23625
diff
changeset
|
147 # 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
|
148 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
|
149 srcurl, branches = parseurl(source) |
012a7b482d68
share: use the 'sharedpath' attr on repo instead of reloading from the file
Matt Harbison <matt_harbison@yahoo.com>
parents:
23625
diff
changeset
|
150 return repository(repo.ui, srcurl) |
23548
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
151 |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
152 def getbkfile(orig, self, repo): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
153 if _hassharedbookmarks(repo): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
154 srcrepo = _getsrcrepo(repo) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
155 if srcrepo is not None: |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
156 repo = srcrepo |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
157 return orig(self, repo) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
158 |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
159 def recordchange(orig, self, tr): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
160 # Continue with write to local bookmarks file as usual |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
161 orig(self, tr) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
162 |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
163 if _hassharedbookmarks(self._repo): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
164 srcrepo = _getsrcrepo(self._repo) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
165 if srcrepo is not None: |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
166 category = 'share-bookmarks' |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
167 tr.addpostclose(category, lambda tr: self._writerepo(srcrepo)) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
168 |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
169 def write(orig, self): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
170 # First write local bookmarks file in case we ever unshare |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
171 orig(self) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
172 if _hassharedbookmarks(self._repo): |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
173 srcrepo = _getsrcrepo(self._repo) |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
174 if srcrepo is not None: |
141baca16059
share: implement shared bookmark functionality
Ryan McElroy <rmcelroy@fb.com>
parents:
21772
diff
changeset
|
175 self._writerepo(srcrepo) |