author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
Sun, 09 Jul 2006 01:30:30 +0200 | |
changeset 2579 | 0875cda033fd |
parent 2555 | d6605381c6df |
child 2595 | edb66cb05ded |
permissions | -rw-r--r-- |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
1 |
# hg.py - repository classes for mercurial |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
2 |
# |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
3 |
# Copyright 2005 Matt Mackall <mpm@selenic.com> |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
4 |
# |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
6 |
# of the GNU General Public License, incorporated herein by reference. |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
7 |
|
1089 | 8 |
from node import * |
9 |
from repo import * |
|
262 | 10 |
from demandload import * |
2431
d90a9d7c7d4d
replace old-http:// syntax by static-http:// and deprecate the redundant hg://
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1945
diff
changeset
|
11 |
from i18n import gettext as _ |
1945
dec6d3c13dbf
new type of repo: bundle://path/to/repo+/path/to/bundlename
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1102
diff
changeset
|
12 |
demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo") |
2472
e6ec81a8feea
make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
13 |
demandload(globals(), "os util") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
14 |
|
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
15 |
def bundle(ui, path): |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
16 |
if path.startswith('bundle://'): |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
17 |
path = path[9:] |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
18 |
else: |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
19 |
path = path[7:] |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
20 |
s = path.split("+", 1) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
21 |
if len(s) == 1: |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
22 |
repopath, bundlename = "", s[0] |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
23 |
else: |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
24 |
repopath, bundlename = s |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
25 |
return bundlerepo.bundlerepository(ui, repopath, bundlename) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
26 |
|
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
27 |
def hg(ui, path): |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
28 |
ui.warn(_("hg:// syntax is deprecated, please use http:// instead\n")) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
29 |
return httprepo.httprepository(ui, path.replace("hg://", "http://")) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
30 |
|
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
31 |
def local_(ui, path, create=0): |
2472
e6ec81a8feea
make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
32 |
if path.startswith('file:'): |
e6ec81a8feea
make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
33 |
path = path[5:] |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
34 |
return localrepo.localrepository(ui, path, create) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
35 |
|
2549
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2479
diff
changeset
|
36 |
def ssh_(ui, path, create=0): |
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2479
diff
changeset
|
37 |
return sshrepo.sshrepository(ui, path, create) |
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2479
diff
changeset
|
38 |
|
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
39 |
def old_http(ui, path): |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
40 |
ui.warn(_("old-http:// syntax is deprecated, " |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
41 |
"please use static-http:// instead\n")) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
42 |
return statichttprepo.statichttprepository( |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
43 |
ui, path.replace("old-http://", "http://")) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
44 |
|
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
45 |
def static_http(ui, path): |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
46 |
return statichttprepo.statichttprepository( |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
47 |
ui, path.replace("static-http://", "http://")) |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
48 |
|
2472
e6ec81a8feea
make repo scheme table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
49 |
schemes = { |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
50 |
'bundle': bundle, |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
51 |
'file': local_, |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
52 |
'hg': hg, |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
53 |
'http': lambda ui, path: httprepo.httprepository(ui, path), |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
54 |
'https': lambda ui, path: httprepo.httpsrepository(ui, path), |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
55 |
'old-http': old_http, |
2549
e1831f06eef1
Added ability to clone from a local repository to a (new) remote one.
Sean Meiners <sean.meiners@linspire.com>
parents:
2479
diff
changeset
|
56 |
'ssh': ssh_, |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
57 |
'static-http': static_http, |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
58 |
} |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
59 |
|
60 | 60 |
def repository(ui, path=None, create=0): |
2479
10ec8039e1d8
hg.repository: many routines expect path to be a string even if empty.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2475
diff
changeset
|
61 |
if not path: path = '' |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
62 |
scheme = path |
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
63 |
if scheme: |
2579
0875cda033fd
use __contains__, index or split instead of str.find
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2555
diff
changeset
|
64 |
scheme = scheme.split(":", 1)[0] |
2555
d6605381c6df
hg.py: move exception handling code to try to avoid hiding errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2549
diff
changeset
|
65 |
ctor = schemes.get(scheme) or schemes['file'] |
d6605381c6df
hg.py: move exception handling code to try to avoid hiding errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2549
diff
changeset
|
66 |
if create: |
d6605381c6df
hg.py: move exception handling code to try to avoid hiding errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2549
diff
changeset
|
67 |
try: |
2469
2e91ba371c4c
hg.repository: make protocol table driven.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2431
diff
changeset
|
68 |
return ctor(ui, path, create) |
2555
d6605381c6df
hg.py: move exception handling code to try to avoid hiding errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2549
diff
changeset
|
69 |
except TypeError: |
d6605381c6df
hg.py: move exception handling code to try to avoid hiding errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2549
diff
changeset
|
70 |
raise util.Abort(_('cannot create new repository over "%s" protocol') % |
d6605381c6df
hg.py: move exception handling code to try to avoid hiding errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2549
diff
changeset
|
71 |
scheme) |
d6605381c6df
hg.py: move exception handling code to try to avoid hiding errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2549
diff
changeset
|
72 |
return ctor(ui, path) |