Show More
@@ -5364,6 +5364,8 b' def paths(ui, repo, search=None):' | |||
|
5364 | 5364 | else: |
|
5365 | 5365 | ui.write("%s = %s\n" % (name, |
|
5366 | 5366 | util.hidepassword(path.loc))) |
|
5367 | for subopt, value in sorted(path.suboptions.items()): | |
|
5368 | ui.write('%s:%s = %s\n' % (name, subopt, value)) | |
|
5367 | 5369 | |
|
5368 | 5370 | @command('phase', |
|
5369 | 5371 | [('p', 'public', False, _('set changeset phase to public')), |
@@ -1127,29 +1127,43 b' command or with Mercurial Queues extensi' | |||
|
1127 | 1127 | ``paths`` |
|
1128 | 1128 | --------- |
|
1129 | 1129 | |
|
1130 |
Assigns symbolic names to repositories. |
|
|
1131 | symbolic name, and the right gives the directory or URL that is the | |
|
1132 | location of the repository. Default paths can be declared by setting | |
|
1133 | the following entries. | |
|
1130 | Assigns symbolic names and behavior to repositories. | |
|
1131 | ||
|
1132 | Options are symbolic names defining the URL or directory that is the | |
|
1133 | location of the repository. Example:: | |
|
1134 | ||
|
1135 | [paths] | |
|
1136 | my_server = https://example.com/my_repo | |
|
1137 | local_path = /home/me/repo | |
|
1138 | ||
|
1139 | These symbolic names can be used from the command line. To pull | |
|
1140 | from ``my_server``: :hg:`pull my_server`. To push to ``local_path``: | |
|
1141 | :hg:`push local_path`. | |
|
1142 | ||
|
1143 | Options containing colons (``:``) denote sub-options that can influence | |
|
1144 | behavior for that specific path. Example:: | |
|
1145 | ||
|
1146 | [paths] | |
|
1147 | my_server = https://example.com/my_path | |
|
1148 | my_server:pushurl = ssh://example.com/my_path | |
|
1149 | ||
|
1150 | The following sub-options can be defined: | |
|
1151 | ||
|
1152 | ``pushurl`` | |
|
1153 | The URL to use for push operations. If not defined, the location | |
|
1154 | defined by the path's main entry is used. | |
|
1155 | ||
|
1156 | The following special named paths exist: | |
|
1134 | 1157 | |
|
1135 | 1158 | ``default`` |
|
1136 |
|
|
|
1137 | (default: repository from which the current repository was cloned) | |
|
1159 | The URL or directory to use when no source or remote is specified. | |
|
1160 | ||
|
1161 | :hg:`clone` will automatically define this path to the location the | |
|
1162 | repository was cloned from. | |
|
1138 | 1163 | |
|
1139 | 1164 | ``default-push`` |
|
1140 | Optional. Directory or URL to use when pushing if no destination | |
|
1141 | is specified. | |
|
1142 | ||
|
1143 | Custom paths can be defined by assigning the path to a name that later can be | |
|
1144 | used from the command line. Example:: | |
|
1145 | ||
|
1146 | [paths] | |
|
1147 | my_path = http://example.com/path | |
|
1148 | ||
|
1149 | To push to the path defined in ``my_path`` run the command:: | |
|
1150 | ||
|
1151 | hg push my_path | |
|
1152 | ||
|
1165 | (deprecated) The URL or directory for the default :hg:`push` location. | |
|
1166 | ``default:pushurl`` should be used instead. | |
|
1153 | 1167 | |
|
1154 | 1168 | ``phases`` |
|
1155 | 1169 | ---------- |
@@ -1063,7 +1063,7 b' class paths(dict):' | |||
|
1063 | 1063 | def __init__(self, ui): |
|
1064 | 1064 | dict.__init__(self) |
|
1065 | 1065 | |
|
1066 | for name, loc in ui.configitems('paths'): | |
|
1066 | for name, loc in ui.configitems('paths', ignoresub=True): | |
|
1067 | 1067 | # No location is the same as not existing. |
|
1068 | 1068 | if not loc: |
|
1069 | 1069 | continue |
@@ -1071,7 +1071,8 b' class paths(dict):' | |||
|
1071 | 1071 | # TODO ignore default-push once all consumers stop referencing it |
|
1072 | 1072 | # since it is handled specifically below. |
|
1073 | 1073 | |
|
1074 | self[name] = path(ui, name, rawloc=loc) | |
|
1074 | loc, sub = ui.configsuboptions('paths', name) | |
|
1075 | self[name] = path(ui, name, rawloc=loc, suboptions=sub) | |
|
1075 | 1076 | |
|
1076 | 1077 | # Handle default-push, which is a one-off that defines the push URL for |
|
1077 | 1078 | # the "default" path. |
@@ -1120,10 +1121,48 b' class paths(dict):' | |||
|
1120 | 1121 | |
|
1121 | 1122 | assert False |
|
1122 | 1123 | |
|
1124 | _pathsuboptions = {} | |
|
1125 | ||
|
1126 | def pathsuboption(option, attr): | |
|
1127 | """Decorator used to declare a path sub-option. | |
|
1128 | ||
|
1129 | Arguments are the sub-option name and the attribute it should set on | |
|
1130 | ``path`` instances. | |
|
1131 | ||
|
1132 | The decorated function will receive as arguments a ``ui`` instance, | |
|
1133 | ``path`` instance, and the string value of this option from the config. | |
|
1134 | The function should return the value that will be set on the ``path`` | |
|
1135 | instance. | |
|
1136 | ||
|
1137 | This decorator can be used to perform additional verification of | |
|
1138 | sub-options and to change the type of sub-options. | |
|
1139 | """ | |
|
1140 | def register(func): | |
|
1141 | _pathsuboptions[option] = (attr, func) | |
|
1142 | return func | |
|
1143 | return register | |
|
1144 | ||
|
1145 | @pathsuboption('pushurl', 'pushloc') | |
|
1146 | def pushurlpathoption(ui, path, value): | |
|
1147 | u = util.url(value) | |
|
1148 | # Actually require a URL. | |
|
1149 | if not u.scheme: | |
|
1150 | ui.warn(_('(paths.%s:pushurl not a URL; ignoring)\n') % path.name) | |
|
1151 | return None | |
|
1152 | ||
|
1153 | # Don't support the #foo syntax in the push URL to declare branch to | |
|
1154 | # push. | |
|
1155 | if u.fragment: | |
|
1156 | ui.warn(_('("#fragment" in paths.%s:pushurl not supported; ' | |
|
1157 | 'ignoring)\n') % path.name) | |
|
1158 | u.fragment = None | |
|
1159 | ||
|
1160 | return str(u) | |
|
1161 | ||
|
1123 | 1162 | class path(object): |
|
1124 | 1163 | """Represents an individual path and its configuration.""" |
|
1125 | 1164 | |
|
1126 |
def __init__(self, ui, name, rawloc=None, |
|
|
1165 | def __init__(self, ui, name, rawloc=None, suboptions=None): | |
|
1127 | 1166 | """Construct a path from its config options. |
|
1128 | 1167 | |
|
1129 | 1168 | ``ui`` is the ``ui`` instance the path is coming from. |
@@ -1151,7 +1190,6 b' class path(object):' | |||
|
1151 | 1190 | self.name = name |
|
1152 | 1191 | self.rawloc = rawloc |
|
1153 | 1192 | self.loc = str(u) |
|
1154 | self.pushloc = pushloc | |
|
1155 | 1193 | |
|
1156 | 1194 | # When given a raw location but not a symbolic name, validate the |
|
1157 | 1195 | # location is valid. |
@@ -1159,6 +1197,19 b' class path(object):' | |||
|
1159 | 1197 | raise ValueError('location is not a URL or path to a local ' |
|
1160 | 1198 | 'repo: %s' % rawloc) |
|
1161 | 1199 | |
|
1200 | suboptions = suboptions or {} | |
|
1201 | ||
|
1202 | # Now process the sub-options. If a sub-option is registered, its | |
|
1203 | # attribute will always be present. The value will be None if there | |
|
1204 | # was no valid sub-option. | |
|
1205 | for suboption, (attr, func) in _pathsuboptions.iteritems(): | |
|
1206 | if suboption not in suboptions: | |
|
1207 | setattr(self, attr, None) | |
|
1208 | continue | |
|
1209 | ||
|
1210 | value = func(ui, self, suboptions[suboption]) | |
|
1211 | setattr(self, attr, value) | |
|
1212 | ||
|
1162 | 1213 | def _isvalidlocalpath(self, path): |
|
1163 | 1214 | """Returns True if the given path is a potentially valid repository. |
|
1164 | 1215 | This is its own function so that extensions can change the definition of |
@@ -1166,6 +1217,19 b' class path(object):' | |||
|
1166 | 1217 | one).""" |
|
1167 | 1218 | return os.path.isdir(os.path.join(path, '.hg')) |
|
1168 | 1219 | |
|
1220 | @property | |
|
1221 | def suboptions(self): | |
|
1222 | """Return sub-options and their values for this path. | |
|
1223 | ||
|
1224 | This is intended to be used for presentation purposes. | |
|
1225 | """ | |
|
1226 | d = {} | |
|
1227 | for subopt, (attr, _func) in _pathsuboptions.iteritems(): | |
|
1228 | value = getattr(self, attr) | |
|
1229 | if value is not None: | |
|
1230 | d[subopt] = value | |
|
1231 | return d | |
|
1232 | ||
|
1169 | 1233 | # we instantiate one globally shared progress bar to avoid |
|
1170 | 1234 | # competing progress bars when multiple UI objects get created |
|
1171 | 1235 | _progresssingleton = None |
@@ -69,3 +69,26 b" Pushing to a path that isn't defined sho" | |||
|
69 | 69 | $ hg --cwd b push doesnotexist |
|
70 | 70 | abort: repository doesnotexist does not exist! |
|
71 | 71 | [255] |
|
72 | ||
|
73 | :pushurl is used when defined | |
|
74 | ||
|
75 | $ hg -q clone a pushurlsource | |
|
76 | $ hg -q clone a pushurldest | |
|
77 | $ cd pushurlsource | |
|
78 | $ cat > .hg/hgrc << EOF | |
|
79 | > [paths] | |
|
80 | > default = https://example.com/not/relevant | |
|
81 | > default:pushurl = file://`pwd`/../pushurldest | |
|
82 | > EOF | |
|
83 | ||
|
84 | $ touch pushurl | |
|
85 | $ hg -q commit -A -m 'add pushurl' | |
|
86 | $ hg push | |
|
87 | pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob) | |
|
88 | searching for changes | |
|
89 | adding changesets | |
|
90 | adding manifests | |
|
91 | adding file changes | |
|
92 | added 1 changesets with 1 changes to 1 files | |
|
93 | ||
|
94 | $ cd .. |
@@ -1207,28 +1207,43 b' Test section lookup' | |||
|
1207 | 1207 | "paths" |
|
1208 | 1208 | ------- |
|
1209 | 1209 | |
|
1210 |
Assigns symbolic names to repositories. |
|
|
1211 | name, and the right gives the directory or URL that is the location of the | |
|
1212 | repository. Default paths can be declared by setting the following | |
|
1213 | entries. | |
|
1210 | Assigns symbolic names and behavior to repositories. | |
|
1211 | ||
|
1212 | Options are symbolic names defining the URL or directory that is the | |
|
1213 | location of the repository. Example: | |
|
1214 | ||
|
1215 | [paths] | |
|
1216 | my_server = https://example.com/my_repo | |
|
1217 | local_path = /home/me/repo | |
|
1218 | ||
|
1219 | These symbolic names can be used from the command line. To pull from | |
|
1220 | "my_server": "hg pull my_server". To push to "local_path": "hg push | |
|
1221 | local_path". | |
|
1222 | ||
|
1223 | Options containing colons (":") denote sub-options that can influence | |
|
1224 | behavior for that specific path. Example: | |
|
1225 | ||
|
1226 | [paths] | |
|
1227 | my_server = https://example.com/my_path | |
|
1228 | my_server:pushurl = ssh://example.com/my_path | |
|
1229 | ||
|
1230 | The following sub-options can be defined: | |
|
1231 | ||
|
1232 | "pushurl" | |
|
1233 | The URL to use for push operations. If not defined, the location | |
|
1234 | defined by the path's main entry is used. | |
|
1235 | ||
|
1236 | The following special named paths exist: | |
|
1214 | 1237 |
|
|
1215 | 1238 | "default" |
|
1216 |
|
|
|
1217 | (default: repository from which the current repository was cloned) | |
|
1239 | The URL or directory to use when no source or remote is specified. | |
|
1240 | ||
|
1241 | "hg clone" will automatically define this path to the location the | |
|
1242 | repository was cloned from. | |
|
1218 | 1243 |
|
|
1219 | 1244 | "default-push" |
|
1220 | Optional. Directory or URL to use when pushing if no destination is | |
|
1221 | specified. | |
|
1222 | ||
|
1223 | Custom paths can be defined by assigning the path to a name that later can | |
|
1224 | be used from the command line. Example: | |
|
1225 | ||
|
1226 | [paths] | |
|
1227 | my_path = http://example.com/path | |
|
1228 | ||
|
1229 | To push to the path defined in "my_path" run the command: | |
|
1230 | ||
|
1231 | hg push my_path | |
|
1245 | (deprecated) The URL or directory for the default "hg push" location. | |
|
1246 | "default:pushurl" should be used instead. | |
|
1232 | 1247 |
|
|
1233 | 1248 | $ hg help glossary.mcguffin |
|
1234 | 1249 | abort: help section not found |
@@ -44,6 +44,59 b'' | |||
|
44 | 44 | [1] |
|
45 | 45 | $ cd .. |
|
46 | 46 | |
|
47 | sub-options for an undeclared path are ignored | |
|
48 | ||
|
49 | $ hg init suboptions | |
|
50 | $ cd suboptions | |
|
51 | ||
|
52 | $ cat > .hg/hgrc << EOF | |
|
53 | > [paths] | |
|
54 | > path0 = https://example.com/path0 | |
|
55 | > path1:pushurl = https://example.com/path1 | |
|
56 | > EOF | |
|
57 | $ hg paths | |
|
58 | path0 = https://example.com/path0 | |
|
59 | ||
|
60 | unknown sub-options aren't displayed | |
|
61 | ||
|
62 | $ cat > .hg/hgrc << EOF | |
|
63 | > [paths] | |
|
64 | > path0 = https://example.com/path0 | |
|
65 | > path0:foo = https://example.com/path1 | |
|
66 | > EOF | |
|
67 | ||
|
68 | $ hg paths | |
|
69 | path0 = https://example.com/path0 | |
|
70 | ||
|
71 | :pushurl must be a URL | |
|
72 | ||
|
73 | $ cat > .hg/hgrc << EOF | |
|
74 | > [paths] | |
|
75 | > default = /path/to/nothing | |
|
76 | > default:pushurl = /not/a/url | |
|
77 | > EOF | |
|
78 | ||
|
79 | $ hg paths | |
|
80 | (paths.default:pushurl not a URL; ignoring) | |
|
81 | default = /path/to/nothing | |
|
82 | ||
|
83 | #fragment is not allowed in :pushurl | |
|
84 | ||
|
85 | $ cat > .hg/hgrc << EOF | |
|
86 | > [paths] | |
|
87 | > default = https://example.com/repo | |
|
88 | > invalid = https://example.com/repo | |
|
89 | > invalid:pushurl = https://example.com/repo#branch | |
|
90 | > EOF | |
|
91 | ||
|
92 | $ hg paths | |
|
93 | ("#fragment" in paths.invalid:pushurl not supported; ignoring) | |
|
94 | default = https://example.com/repo | |
|
95 | invalid = https://example.com/repo | |
|
96 | invalid:pushurl = https://example.com/repo | |
|
97 | ||
|
98 | $ cd .. | |
|
99 | ||
|
47 | 100 | 'file:' disables [paths] entries for clone destination |
|
48 | 101 | |
|
49 | 102 | $ cat >> $HGRCPATH <<EOF |
General Comments 0
You need to be logged in to leave comments.
Login now