Show More
@@ -81,6 +81,64 b' def localpath(path):' | |||
|
81 | 81 | return path[5:] |
|
82 | 82 | return path |
|
83 | 83 | |
|
84 | def share(ui, source, dest, update=True): | |
|
85 | '''create a shared repository''' | |
|
86 | ||
|
87 | if not islocal(source): | |
|
88 | raise util.Abort(_('can only share local repositories')) | |
|
89 | ||
|
90 | if isinstance(source, str): | |
|
91 | origsource = ui.expandpath(source) | |
|
92 | source, rev, checkout = parseurl(origsource, '') | |
|
93 | srcrepo = repository(ui, source) | |
|
94 | else: | |
|
95 | srcrepo = source | |
|
96 | origsource = source = srcrepo.url() | |
|
97 | checkout = None | |
|
98 | ||
|
99 | sharedpath = srcrepo.sharedpath # if our source is already sharing | |
|
100 | ||
|
101 | root = os.path.realpath(dest) | |
|
102 | roothg = os.path.join(root, '.hg') | |
|
103 | ||
|
104 | if os.path.exists(roothg): | |
|
105 | raise util.Abort(_('destination already exists')) | |
|
106 | ||
|
107 | if not os.path.isdir(root): | |
|
108 | os.mkdir(root) | |
|
109 | os.mkdir(roothg) | |
|
110 | ||
|
111 | requirements = '' | |
|
112 | try: | |
|
113 | requirements = srcrepo.opener('requires').read() | |
|
114 | except IOError, inst: | |
|
115 | if inst.errno != errno.ENOENT: | |
|
116 | raise | |
|
117 | ||
|
118 | requirements += 'shared\n' | |
|
119 | file(os.path.join(roothg, 'requires'), 'w').write(requirements) | |
|
120 | file(os.path.join(roothg, 'sharedpath'), 'w').write(sharedpath) | |
|
121 | ||
|
122 | default = srcrepo.ui.config('paths', 'default') | |
|
123 | if default: | |
|
124 | f = file(os.path.join(roothg, 'hgrc'), 'w') | |
|
125 | f.write('[paths]\ndefault = %s\n' % default) | |
|
126 | f.close() | |
|
127 | ||
|
128 | r = repository(ui, root) | |
|
129 | ||
|
130 | if update: | |
|
131 | r.ui.status(_("updating working directory\n")) | |
|
132 | if update is not True: | |
|
133 | checkout = update | |
|
134 | for test in (checkout, 'default', 'tip'): | |
|
135 | try: | |
|
136 | uprev = r.lookup(test) | |
|
137 | break | |
|
138 | except: | |
|
139 | continue | |
|
140 | _update(r, uprev) | |
|
141 | ||
|
84 | 142 | def clone(ui, source, dest=None, pull=False, rev=None, update=True, |
|
85 | 143 | stream=False): |
|
86 | 144 | """Make a copy of an existing repository. |
General Comments 0
You need to be logged in to leave comments.
Login now