##// END OF EJS Templates
requirements: show all missing features in the error message....
Pierre-Yves David -
r14746:72e4fcb4 stable
parent child Browse files
Show More
@@ -1,707 +1,711 b''
1 1 # scmutil.py - Mercurial core utility functions
2 2 #
3 3 # Copyright Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from i18n import _
9 9 import util, error, osutil, revset, similar
10 10 import match as matchmod
11 11 import os, errno, stat, sys, glob
12 12
13 13 def checkfilename(f):
14 14 '''Check that the filename f is an acceptable filename for a tracked file'''
15 15 if '\r' in f or '\n' in f:
16 16 raise util.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f)
17 17
18 18 def checkportable(ui, f):
19 19 '''Check if filename f is portable and warn or abort depending on config'''
20 20 checkfilename(f)
21 21 abort, warn = checkportabilityalert(ui)
22 22 if abort or warn:
23 23 msg = util.checkwinfilename(f)
24 24 if msg:
25 25 msg = "%s: %r" % (msg, f)
26 26 if abort:
27 27 raise util.Abort(msg)
28 28 ui.warn(_("warning: %s\n") % msg)
29 29
30 30 def checkportabilityalert(ui):
31 31 '''check if the user's config requests nothing, a warning, or abort for
32 32 non-portable filenames'''
33 33 val = ui.config('ui', 'portablefilenames', 'warn')
34 34 lval = val.lower()
35 35 bval = util.parsebool(val)
36 36 abort = os.name == 'nt' or lval == 'abort'
37 37 warn = bval or lval == 'warn'
38 38 if bval is None and not (warn or abort or lval == 'ignore'):
39 39 raise error.ConfigError(
40 40 _("ui.portablefilenames value is invalid ('%s')") % val)
41 41 return abort, warn
42 42
43 43 class casecollisionauditor(object):
44 44 def __init__(self, ui, abort, existingiter):
45 45 self._ui = ui
46 46 self._abort = abort
47 47 self._map = {}
48 48 for f in existingiter:
49 49 self._map[f.lower()] = f
50 50
51 51 def __call__(self, f):
52 52 fl = f.lower()
53 53 map = self._map
54 54 if fl in map and map[fl] != f:
55 55 msg = _('possible case-folding collision for %s') % f
56 56 if self._abort:
57 57 raise util.Abort(msg)
58 58 self._ui.warn(_("warning: %s\n") % msg)
59 59 map[fl] = f
60 60
61 61 class pathauditor(object):
62 62 '''ensure that a filesystem path contains no banned components.
63 63 the following properties of a path are checked:
64 64
65 65 - ends with a directory separator
66 66 - under top-level .hg
67 67 - starts at the root of a windows drive
68 68 - contains ".."
69 69 - traverses a symlink (e.g. a/symlink_here/b)
70 70 - inside a nested repository (a callback can be used to approve
71 71 some nested repositories, e.g., subrepositories)
72 72 '''
73 73
74 74 def __init__(self, root, callback=None):
75 75 self.audited = set()
76 76 self.auditeddir = set()
77 77 self.root = root
78 78 self.callback = callback
79 79
80 80 def __call__(self, path):
81 81 '''Check the relative path.
82 82 path may contain a pattern (e.g. foodir/**.txt)'''
83 83
84 84 if path in self.audited:
85 85 return
86 86 # AIX ignores "/" at end of path, others raise EISDIR.
87 87 if util.endswithsep(path):
88 88 raise util.Abort(_("path ends in directory separator: %s") % path)
89 89 normpath = os.path.normcase(path)
90 90 parts = util.splitpath(normpath)
91 91 if (os.path.splitdrive(path)[0]
92 92 or parts[0].lower() in ('.hg', '.hg.', '')
93 93 or os.pardir in parts):
94 94 raise util.Abort(_("path contains illegal component: %s") % path)
95 95 if '.hg' in path.lower():
96 96 lparts = [p.lower() for p in parts]
97 97 for p in '.hg', '.hg.':
98 98 if p in lparts[1:]:
99 99 pos = lparts.index(p)
100 100 base = os.path.join(*parts[:pos])
101 101 raise util.Abort(_('path %r is inside nested repo %r')
102 102 % (path, base))
103 103
104 104 parts.pop()
105 105 prefixes = []
106 106 while parts:
107 107 prefix = os.sep.join(parts)
108 108 if prefix in self.auditeddir:
109 109 break
110 110 curpath = os.path.join(self.root, prefix)
111 111 try:
112 112 st = os.lstat(curpath)
113 113 except OSError, err:
114 114 # EINVAL can be raised as invalid path syntax under win32.
115 115 # They must be ignored for patterns can be checked too.
116 116 if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
117 117 raise
118 118 else:
119 119 if stat.S_ISLNK(st.st_mode):
120 120 raise util.Abort(
121 121 _('path %r traverses symbolic link %r')
122 122 % (path, prefix))
123 123 elif (stat.S_ISDIR(st.st_mode) and
124 124 os.path.isdir(os.path.join(curpath, '.hg'))):
125 125 if not self.callback or not self.callback(curpath):
126 126 raise util.Abort(_('path %r is inside nested repo %r') %
127 127 (path, prefix))
128 128 prefixes.append(prefix)
129 129 parts.pop()
130 130
131 131 self.audited.add(path)
132 132 # only add prefixes to the cache after checking everything: we don't
133 133 # want to add "foo/bar/baz" before checking if there's a "foo/.hg"
134 134 self.auditeddir.update(prefixes)
135 135
136 136 class abstractopener(object):
137 137 """Abstract base class; cannot be instantiated"""
138 138
139 139 def __init__(self, *args, **kwargs):
140 140 '''Prevent instantiation; don't call this from subclasses.'''
141 141 raise NotImplementedError('attempted instantiating ' + str(type(self)))
142 142
143 143 def read(self, path):
144 144 fp = self(path, 'rb')
145 145 try:
146 146 return fp.read()
147 147 finally:
148 148 fp.close()
149 149
150 150 def write(self, path, data):
151 151 fp = self(path, 'wb')
152 152 try:
153 153 return fp.write(data)
154 154 finally:
155 155 fp.close()
156 156
157 157 def append(self, path, data):
158 158 fp = self(path, 'ab')
159 159 try:
160 160 return fp.write(data)
161 161 finally:
162 162 fp.close()
163 163
164 164 class opener(abstractopener):
165 165 '''Open files relative to a base directory
166 166
167 167 This class is used to hide the details of COW semantics and
168 168 remote file access from higher level code.
169 169 '''
170 170 def __init__(self, base, audit=True):
171 171 self.base = base
172 172 self._audit = audit
173 173 if audit:
174 174 self.auditor = pathauditor(base)
175 175 else:
176 176 self.auditor = util.always
177 177 self.createmode = None
178 178 self._trustnlink = None
179 179
180 180 @util.propertycache
181 181 def _cansymlink(self):
182 182 return util.checklink(self.base)
183 183
184 184 def _fixfilemode(self, name):
185 185 if self.createmode is None:
186 186 return
187 187 os.chmod(name, self.createmode & 0666)
188 188
189 189 def __call__(self, path, mode="r", text=False, atomictemp=False):
190 190 if self._audit:
191 191 r = util.checkosfilename(path)
192 192 if r:
193 193 raise util.Abort("%s: %r" % (r, path))
194 194 self.auditor(path)
195 195 f = os.path.join(self.base, path)
196 196
197 197 if not text and "b" not in mode:
198 198 mode += "b" # for that other OS
199 199
200 200 nlink = -1
201 201 dirname, basename = os.path.split(f)
202 202 # If basename is empty, then the path is malformed because it points
203 203 # to a directory. Let the posixfile() call below raise IOError.
204 204 if basename and mode not in ('r', 'rb'):
205 205 if atomictemp:
206 206 if not os.path.isdir(dirname):
207 207 util.makedirs(dirname, self.createmode)
208 208 return util.atomictempfile(f, mode, self.createmode)
209 209 try:
210 210 if 'w' in mode:
211 211 util.unlink(f)
212 212 nlink = 0
213 213 else:
214 214 # nlinks() may behave differently for files on Windows
215 215 # shares if the file is open.
216 216 fd = util.posixfile(f)
217 217 nlink = util.nlinks(f)
218 218 if nlink < 1:
219 219 nlink = 2 # force mktempcopy (issue1922)
220 220 fd.close()
221 221 except (OSError, IOError), e:
222 222 if e.errno != errno.ENOENT:
223 223 raise
224 224 nlink = 0
225 225 if not os.path.isdir(dirname):
226 226 util.makedirs(dirname, self.createmode)
227 227 if nlink > 0:
228 228 if self._trustnlink is None:
229 229 self._trustnlink = nlink > 1 or util.checknlink(f)
230 230 if nlink > 1 or not self._trustnlink:
231 231 util.rename(util.mktempcopy(f), f)
232 232 fp = util.posixfile(f, mode)
233 233 if nlink == 0:
234 234 self._fixfilemode(f)
235 235 return fp
236 236
237 237 def symlink(self, src, dst):
238 238 self.auditor(dst)
239 239 linkname = os.path.join(self.base, dst)
240 240 try:
241 241 os.unlink(linkname)
242 242 except OSError:
243 243 pass
244 244
245 245 dirname = os.path.dirname(linkname)
246 246 if not os.path.exists(dirname):
247 247 util.makedirs(dirname, self.createmode)
248 248
249 249 if self._cansymlink:
250 250 try:
251 251 os.symlink(src, linkname)
252 252 except OSError, err:
253 253 raise OSError(err.errno, _('could not symlink to %r: %s') %
254 254 (src, err.strerror), linkname)
255 255 else:
256 256 f = self(dst, "w")
257 257 f.write(src)
258 258 f.close()
259 259 self._fixfilemode(dst)
260 260
261 261 def audit(self, path):
262 262 self.auditor(path)
263 263
264 264 class filteropener(abstractopener):
265 265 '''Wrapper opener for filtering filenames with a function.'''
266 266
267 267 def __init__(self, opener, filter):
268 268 self._filter = filter
269 269 self._orig = opener
270 270
271 271 def __call__(self, path, *args, **kwargs):
272 272 return self._orig(self._filter(path), *args, **kwargs)
273 273
274 274 def canonpath(root, cwd, myname, auditor=None):
275 275 '''return the canonical path of myname, given cwd and root'''
276 276 if util.endswithsep(root):
277 277 rootsep = root
278 278 else:
279 279 rootsep = root + os.sep
280 280 name = myname
281 281 if not os.path.isabs(name):
282 282 name = os.path.join(root, cwd, name)
283 283 name = os.path.normpath(name)
284 284 if auditor is None:
285 285 auditor = pathauditor(root)
286 286 if name != rootsep and name.startswith(rootsep):
287 287 name = name[len(rootsep):]
288 288 auditor(name)
289 289 return util.pconvert(name)
290 290 elif name == root:
291 291 return ''
292 292 else:
293 293 # Determine whether `name' is in the hierarchy at or beneath `root',
294 294 # by iterating name=dirname(name) until that causes no change (can't
295 295 # check name == '/', because that doesn't work on windows). For each
296 296 # `name', compare dev/inode numbers. If they match, the list `rel'
297 297 # holds the reversed list of components making up the relative file
298 298 # name we want.
299 299 root_st = os.stat(root)
300 300 rel = []
301 301 while True:
302 302 try:
303 303 name_st = os.stat(name)
304 304 except OSError:
305 305 break
306 306 if util.samestat(name_st, root_st):
307 307 if not rel:
308 308 # name was actually the same as root (maybe a symlink)
309 309 return ''
310 310 rel.reverse()
311 311 name = os.path.join(*rel)
312 312 auditor(name)
313 313 return util.pconvert(name)
314 314 dirname, basename = os.path.split(name)
315 315 rel.append(basename)
316 316 if dirname == name:
317 317 break
318 318 name = dirname
319 319
320 320 raise util.Abort('%s not under root' % myname)
321 321
322 322 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):
323 323 '''yield every hg repository under path, recursively.'''
324 324 def errhandler(err):
325 325 if err.filename == path:
326 326 raise err
327 327 if followsym and hasattr(os.path, 'samestat'):
328 328 def adddir(dirlst, dirname):
329 329 match = False
330 330 samestat = os.path.samestat
331 331 dirstat = os.stat(dirname)
332 332 for lstdirstat in dirlst:
333 333 if samestat(dirstat, lstdirstat):
334 334 match = True
335 335 break
336 336 if not match:
337 337 dirlst.append(dirstat)
338 338 return not match
339 339 else:
340 340 followsym = False
341 341
342 342 if (seen_dirs is None) and followsym:
343 343 seen_dirs = []
344 344 adddir(seen_dirs, path)
345 345 for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler):
346 346 dirs.sort()
347 347 if '.hg' in dirs:
348 348 yield root # found a repository
349 349 qroot = os.path.join(root, '.hg', 'patches')
350 350 if os.path.isdir(os.path.join(qroot, '.hg')):
351 351 yield qroot # we have a patch queue repo here
352 352 if recurse:
353 353 # avoid recursing inside the .hg directory
354 354 dirs.remove('.hg')
355 355 else:
356 356 dirs[:] = [] # don't descend further
357 357 elif followsym:
358 358 newdirs = []
359 359 for d in dirs:
360 360 fname = os.path.join(root, d)
361 361 if adddir(seen_dirs, fname):
362 362 if os.path.islink(fname):
363 363 for hgname in walkrepos(fname, True, seen_dirs):
364 364 yield hgname
365 365 else:
366 366 newdirs.append(d)
367 367 dirs[:] = newdirs
368 368
369 369 def osrcpath():
370 370 '''return default os-specific hgrc search path'''
371 371 path = systemrcpath()
372 372 path.extend(userrcpath())
373 373 path = [os.path.normpath(f) for f in path]
374 374 return path
375 375
376 376 _rcpath = None
377 377
378 378 def rcpath():
379 379 '''return hgrc search path. if env var HGRCPATH is set, use it.
380 380 for each item in path, if directory, use files ending in .rc,
381 381 else use item.
382 382 make HGRCPATH empty to only look in .hg/hgrc of current repo.
383 383 if no HGRCPATH, use default os-specific path.'''
384 384 global _rcpath
385 385 if _rcpath is None:
386 386 if 'HGRCPATH' in os.environ:
387 387 _rcpath = []
388 388 for p in os.environ['HGRCPATH'].split(os.pathsep):
389 389 if not p:
390 390 continue
391 391 p = util.expandpath(p)
392 392 if os.path.isdir(p):
393 393 for f, kind in osutil.listdir(p):
394 394 if f.endswith('.rc'):
395 395 _rcpath.append(os.path.join(p, f))
396 396 else:
397 397 _rcpath.append(p)
398 398 else:
399 399 _rcpath = osrcpath()
400 400 return _rcpath
401 401
402 402 if os.name != 'nt':
403 403
404 404 def rcfiles(path):
405 405 rcs = [os.path.join(path, 'hgrc')]
406 406 rcdir = os.path.join(path, 'hgrc.d')
407 407 try:
408 408 rcs.extend([os.path.join(rcdir, f)
409 409 for f, kind in osutil.listdir(rcdir)
410 410 if f.endswith(".rc")])
411 411 except OSError:
412 412 pass
413 413 return rcs
414 414
415 415 def systemrcpath():
416 416 path = []
417 417 # old mod_python does not set sys.argv
418 418 if len(getattr(sys, 'argv', [])) > 0:
419 419 p = os.path.dirname(os.path.dirname(sys.argv[0]))
420 420 path.extend(rcfiles(os.path.join(p, 'etc/mercurial')))
421 421 path.extend(rcfiles('/etc/mercurial'))
422 422 return path
423 423
424 424 def userrcpath():
425 425 return [os.path.expanduser('~/.hgrc')]
426 426
427 427 else:
428 428
429 429 _HKEY_LOCAL_MACHINE = 0x80000002L
430 430
431 431 def systemrcpath():
432 432 '''return default os-specific hgrc search path'''
433 433 rcpath = []
434 434 filename = util.executablepath()
435 435 # Use mercurial.ini found in directory with hg.exe
436 436 progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
437 437 if os.path.isfile(progrc):
438 438 rcpath.append(progrc)
439 439 return rcpath
440 440 # Use hgrc.d found in directory with hg.exe
441 441 progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
442 442 if os.path.isdir(progrcd):
443 443 for f, kind in osutil.listdir(progrcd):
444 444 if f.endswith('.rc'):
445 445 rcpath.append(os.path.join(progrcd, f))
446 446 return rcpath
447 447 # else look for a system rcpath in the registry
448 448 value = util.lookupreg('SOFTWARE\\Mercurial', None,
449 449 _HKEY_LOCAL_MACHINE)
450 450 if not isinstance(value, str) or not value:
451 451 return rcpath
452 452 value = value.replace('/', os.sep)
453 453 for p in value.split(os.pathsep):
454 454 if p.lower().endswith('mercurial.ini'):
455 455 rcpath.append(p)
456 456 elif os.path.isdir(p):
457 457 for f, kind in osutil.listdir(p):
458 458 if f.endswith('.rc'):
459 459 rcpath.append(os.path.join(p, f))
460 460 return rcpath
461 461
462 462 def userrcpath():
463 463 '''return os-specific hgrc search path to the user dir'''
464 464 home = os.path.expanduser('~')
465 465 path = [os.path.join(home, 'mercurial.ini'),
466 466 os.path.join(home, '.hgrc')]
467 467 userprofile = os.environ.get('USERPROFILE')
468 468 if userprofile:
469 469 path.append(os.path.join(userprofile, 'mercurial.ini'))
470 470 path.append(os.path.join(userprofile, '.hgrc'))
471 471 return path
472 472
473 473 def revsingle(repo, revspec, default='.'):
474 474 if not revspec:
475 475 return repo[default]
476 476
477 477 l = revrange(repo, [revspec])
478 478 if len(l) < 1:
479 479 raise util.Abort(_('empty revision set'))
480 480 return repo[l[-1]]
481 481
482 482 def revpair(repo, revs):
483 483 if not revs:
484 484 return repo.dirstate.p1(), None
485 485
486 486 l = revrange(repo, revs)
487 487
488 488 if len(l) == 0:
489 489 return repo.dirstate.p1(), None
490 490
491 491 if len(l) == 1:
492 492 return repo.lookup(l[0]), None
493 493
494 494 return repo.lookup(l[0]), repo.lookup(l[-1])
495 495
496 496 _revrangesep = ':'
497 497
498 498 def revrange(repo, revs):
499 499 """Yield revision as strings from a list of revision specifications."""
500 500
501 501 def revfix(repo, val, defval):
502 502 if not val and val != 0 and defval is not None:
503 503 return defval
504 504 return repo.changelog.rev(repo.lookup(val))
505 505
506 506 seen, l = set(), []
507 507 for spec in revs:
508 508 # attempt to parse old-style ranges first to deal with
509 509 # things like old-tag which contain query metacharacters
510 510 try:
511 511 if isinstance(spec, int):
512 512 seen.add(spec)
513 513 l.append(spec)
514 514 continue
515 515
516 516 if _revrangesep in spec:
517 517 start, end = spec.split(_revrangesep, 1)
518 518 start = revfix(repo, start, 0)
519 519 end = revfix(repo, end, len(repo) - 1)
520 520 step = start > end and -1 or 1
521 521 for rev in xrange(start, end + step, step):
522 522 if rev in seen:
523 523 continue
524 524 seen.add(rev)
525 525 l.append(rev)
526 526 continue
527 527 elif spec and spec in repo: # single unquoted rev
528 528 rev = revfix(repo, spec, None)
529 529 if rev in seen:
530 530 continue
531 531 seen.add(rev)
532 532 l.append(rev)
533 533 continue
534 534 except error.RepoLookupError:
535 535 pass
536 536
537 537 # fall through to new-style queries if old-style fails
538 538 m = revset.match(repo.ui, spec)
539 539 for r in m(repo, range(len(repo))):
540 540 if r not in seen:
541 541 l.append(r)
542 542 seen.update(l)
543 543
544 544 return l
545 545
546 546 def expandpats(pats):
547 547 if not util.expandglobs:
548 548 return list(pats)
549 549 ret = []
550 550 for p in pats:
551 551 kind, name = matchmod._patsplit(p, None)
552 552 if kind is None:
553 553 try:
554 554 globbed = glob.glob(name)
555 555 except re.error:
556 556 globbed = [name]
557 557 if globbed:
558 558 ret.extend(globbed)
559 559 continue
560 560 ret.append(p)
561 561 return ret
562 562
563 563 def match(ctx, pats=[], opts={}, globbed=False, default='relpath'):
564 564 if pats == ("",):
565 565 pats = []
566 566 if not globbed and default == 'relpath':
567 567 pats = expandpats(pats or [])
568 568
569 569 m = ctx.match(pats, opts.get('include'), opts.get('exclude'),
570 570 default)
571 571 def badfn(f, msg):
572 572 ctx._repo.ui.warn("%s: %s\n" % (m.rel(f), msg))
573 573 m.bad = badfn
574 574 return m
575 575
576 576 def matchall(repo):
577 577 return matchmod.always(repo.root, repo.getcwd())
578 578
579 579 def matchfiles(repo, files):
580 580 return matchmod.exact(repo.root, repo.getcwd(), files)
581 581
582 582 def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None):
583 583 if dry_run is None:
584 584 dry_run = opts.get('dry_run')
585 585 if similarity is None:
586 586 similarity = float(opts.get('similarity') or 0)
587 587 # we'd use status here, except handling of symlinks and ignore is tricky
588 588 added, unknown, deleted, removed = [], [], [], []
589 589 audit_path = pathauditor(repo.root)
590 590 m = match(repo[None], pats, opts)
591 591 for abs in repo.walk(m):
592 592 target = repo.wjoin(abs)
593 593 good = True
594 594 try:
595 595 audit_path(abs)
596 596 except (OSError, util.Abort):
597 597 good = False
598 598 rel = m.rel(abs)
599 599 exact = m.exact(abs)
600 600 if good and abs not in repo.dirstate:
601 601 unknown.append(abs)
602 602 if repo.ui.verbose or not exact:
603 603 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
604 604 elif repo.dirstate[abs] != 'r' and (not good or not os.path.lexists(target)
605 605 or (os.path.isdir(target) and not os.path.islink(target))):
606 606 deleted.append(abs)
607 607 if repo.ui.verbose or not exact:
608 608 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
609 609 # for finding renames
610 610 elif repo.dirstate[abs] == 'r':
611 611 removed.append(abs)
612 612 elif repo.dirstate[abs] == 'a':
613 613 added.append(abs)
614 614 copies = {}
615 615 if similarity > 0:
616 616 for old, new, score in similar.findrenames(repo,
617 617 added + unknown, removed + deleted, similarity):
618 618 if repo.ui.verbose or not m.exact(old) or not m.exact(new):
619 619 repo.ui.status(_('recording removal of %s as rename to %s '
620 620 '(%d%% similar)\n') %
621 621 (m.rel(old), m.rel(new), score * 100))
622 622 copies[new] = old
623 623
624 624 if not dry_run:
625 625 wctx = repo[None]
626 626 wlock = repo.wlock()
627 627 try:
628 628 wctx.forget(deleted)
629 629 wctx.add(unknown)
630 630 for new, old in copies.iteritems():
631 631 wctx.copy(old, new)
632 632 finally:
633 633 wlock.release()
634 634
635 635 def updatedir(ui, repo, patches, similarity=0):
636 636 '''Update dirstate after patch application according to metadata'''
637 637 if not patches:
638 638 return []
639 639 copies = []
640 640 removes = set()
641 641 cfiles = patches.keys()
642 642 cwd = repo.getcwd()
643 643 if cwd:
644 644 cfiles = [util.pathto(repo.root, cwd, f) for f in patches.keys()]
645 645 for f in patches:
646 646 gp = patches[f]
647 647 if not gp:
648 648 continue
649 649 if gp.op == 'RENAME':
650 650 copies.append((gp.oldpath, gp.path))
651 651 removes.add(gp.oldpath)
652 652 elif gp.op == 'COPY':
653 653 copies.append((gp.oldpath, gp.path))
654 654 elif gp.op == 'DELETE':
655 655 removes.add(gp.path)
656 656
657 657 wctx = repo[None]
658 658 for src, dst in copies:
659 659 dirstatecopy(ui, repo, wctx, src, dst, cwd=cwd)
660 660 if (not similarity) and removes:
661 661 wctx.remove(sorted(removes), True)
662 662
663 663 for f in patches:
664 664 gp = patches[f]
665 665 if gp and gp.mode:
666 666 islink, isexec = gp.mode
667 667 dst = repo.wjoin(gp.path)
668 668 # patch won't create empty files
669 669 if gp.op == 'ADD' and not os.path.lexists(dst):
670 670 flags = (isexec and 'x' or '') + (islink and 'l' or '')
671 671 repo.wwrite(gp.path, '', flags)
672 672 util.setflags(dst, islink, isexec)
673 673 addremove(repo, cfiles, similarity=similarity)
674 674 files = patches.keys()
675 675 files.extend([r for r in removes if r not in files])
676 676 return sorted(files)
677 677
678 678 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None):
679 679 """Update the dirstate to reflect the intent of copying src to dst. For
680 680 different reasons it might not end with dst being marked as copied from src.
681 681 """
682 682 origsrc = repo.dirstate.copied(src) or src
683 683 if dst == origsrc: # copying back a copy?
684 684 if repo.dirstate[dst] not in 'mn' and not dryrun:
685 685 repo.dirstate.normallookup(dst)
686 686 else:
687 687 if repo.dirstate[origsrc] == 'a' and origsrc == src:
688 688 if not ui.quiet:
689 689 ui.warn(_("%s has not been committed yet, so no copy "
690 690 "data will be stored for %s.\n")
691 691 % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd)))
692 692 if repo.dirstate[dst] in '?r' and not dryrun:
693 693 wctx.add([dst])
694 694 elif not dryrun:
695 695 wctx.copy(origsrc, dst)
696 696
697 697 def readrequires(opener, supported):
698 698 '''Reads and parses .hg/requires and checks if all entries found
699 699 are in the list of supported features.'''
700 700 requirements = set(opener.read("requires").splitlines())
701 missings = []
701 702 for r in requirements:
702 703 if r not in supported:
703 704 if not r or not r[0].isalnum():
704 705 raise error.RequirementError(_(".hg/requires file is corrupt"))
706 missings.append(r)
707 missings.sort()
708 if missings:
705 709 raise error.RequirementError(_("unknown repository format: "
706 "requires feature '%s' (upgrade Mercurial)") % r)
710 "requires features '%s' (upgrade Mercurial)") % "', '".join(missings))
707 711 return requirements
@@ -1,281 +1,281 b''
1 1 commit date test
2 2
3 3 $ hg init test
4 4 $ cd test
5 5 $ echo foo > foo
6 6 $ hg add foo
7 7 $ HGEDITOR=true hg commit -m ""
8 8 abort: empty commit message
9 9 [255]
10 10 $ hg commit -d '0 0' -m commit-1
11 11 $ echo foo >> foo
12 12 $ hg commit -d '1 4444444' -m commit-3
13 13 abort: impossible time zone offset: 4444444
14 14 [255]
15 15 $ hg commit -d '1 15.1' -m commit-4
16 16 abort: invalid date: '1\t15.1'
17 17 [255]
18 18 $ hg commit -d 'foo bar' -m commit-5
19 19 abort: invalid date: 'foo bar'
20 20 [255]
21 21 $ hg commit -d ' 1 4444' -m commit-6
22 22 $ hg commit -d '111111111111 0' -m commit-7
23 23 abort: date exceeds 32 bits: 111111111111
24 24 [255]
25 25 $ hg commit -d '-7654321 3600' -m commit-7
26 26 abort: negative date value: -7654321
27 27 [255]
28 28
29 29 commit added file that has been deleted
30 30
31 31 $ echo bar > bar
32 32 $ hg add bar
33 33 $ rm bar
34 34 $ hg commit -m commit-8
35 35 nothing changed (1 missing files, see 'hg status')
36 36 [1]
37 37 $ hg commit -m commit-8-2 bar
38 38 abort: bar: file not found!
39 39 [255]
40 40
41 41 $ hg -q revert -a --no-backup
42 42
43 43 $ mkdir dir
44 44 $ echo boo > dir/file
45 45 $ hg add
46 46 adding dir/file
47 47 $ hg -v commit -m commit-9 dir
48 48 dir/file
49 49 committed changeset 2:d2a76177cb42
50 50
51 51 $ echo > dir.file
52 52 $ hg add
53 53 adding dir.file
54 54 $ hg commit -m commit-10 dir dir.file
55 55 abort: dir: no match under directory!
56 56 [255]
57 57
58 58 $ echo >> dir/file
59 59 $ mkdir bleh
60 60 $ mkdir dir2
61 61 $ cd bleh
62 62 $ hg commit -m commit-11 .
63 63 abort: bleh: no match under directory!
64 64 [255]
65 65 $ hg commit -m commit-12 ../dir ../dir2
66 66 abort: dir2: no match under directory!
67 67 [255]
68 68 $ hg -v commit -m commit-13 ../dir
69 69 dir/file
70 70 committed changeset 3:1cd62a2d8db5
71 71 $ cd ..
72 72
73 73 $ hg commit -m commit-14 does-not-exist
74 74 abort: does-not-exist: No such file or directory
75 75 [255]
76 76 $ ln -s foo baz
77 77 $ hg commit -m commit-15 baz
78 78 abort: baz: file not tracked!
79 79 [255]
80 80 $ touch quux
81 81 $ hg commit -m commit-16 quux
82 82 abort: quux: file not tracked!
83 83 [255]
84 84 $ echo >> dir/file
85 85 $ hg -v commit -m commit-17 dir/file
86 86 dir/file
87 87 committed changeset 4:49176991390e
88 88
89 89 An empty date was interpreted as epoch origin
90 90
91 91 $ echo foo >> foo
92 92 $ hg commit -d '' -m commit-no-date
93 93 $ hg tip --template '{date|isodate}\n' | grep '1970'
94 94 [1]
95 95
96 96 Make sure we do not obscure unknown requires file entries (issue2649)
97 97
98 98 $ echo foo >> foo
99 99 $ echo fake >> .hg/requires
100 100 $ hg commit -m bla
101 abort: unknown repository format: requires feature 'fake' (upgrade Mercurial)!
101 abort: unknown repository format: requires features 'fake' (upgrade Mercurial)!
102 102 [255]
103 103
104 104 $ cd ..
105 105
106 106
107 107 partial subdir commit test
108 108
109 109 $ hg init test2
110 110 $ cd test2
111 111 $ mkdir foo
112 112 $ echo foo > foo/foo
113 113 $ mkdir bar
114 114 $ echo bar > bar/bar
115 115 $ hg add
116 116 adding bar/bar
117 117 adding foo/foo
118 118 $ hg ci -m commit-subdir-1 foo
119 119 $ hg ci -m commit-subdir-2 bar
120 120
121 121 subdir log 1
122 122
123 123 $ hg log -v foo
124 124 changeset: 0:f97e73a25882
125 125 user: test
126 126 date: Thu Jan 01 00:00:00 1970 +0000
127 127 files: foo/foo
128 128 description:
129 129 commit-subdir-1
130 130
131 131
132 132
133 133 subdir log 2
134 134
135 135 $ hg log -v bar
136 136 changeset: 1:aa809156d50d
137 137 tag: tip
138 138 user: test
139 139 date: Thu Jan 01 00:00:00 1970 +0000
140 140 files: bar/bar
141 141 description:
142 142 commit-subdir-2
143 143
144 144
145 145
146 146 full log
147 147
148 148 $ hg log -v
149 149 changeset: 1:aa809156d50d
150 150 tag: tip
151 151 user: test
152 152 date: Thu Jan 01 00:00:00 1970 +0000
153 153 files: bar/bar
154 154 description:
155 155 commit-subdir-2
156 156
157 157
158 158 changeset: 0:f97e73a25882
159 159 user: test
160 160 date: Thu Jan 01 00:00:00 1970 +0000
161 161 files: foo/foo
162 162 description:
163 163 commit-subdir-1
164 164
165 165
166 166 $ cd ..
167 167
168 168
169 169 dot and subdir commit test
170 170
171 171 $ hg init test3
172 172 $ cd test3
173 173 $ mkdir foo
174 174 $ echo foo content > foo/plain-file
175 175 $ hg add foo/plain-file
176 176 $ hg ci -m commit-foo-subdir foo
177 177 $ echo modified foo content > foo/plain-file
178 178 $ hg ci -m commit-foo-dot .
179 179
180 180 full log
181 181
182 182 $ hg log -v
183 183 changeset: 1:95b38e3a5b2e
184 184 tag: tip
185 185 user: test
186 186 date: Thu Jan 01 00:00:00 1970 +0000
187 187 files: foo/plain-file
188 188 description:
189 189 commit-foo-dot
190 190
191 191
192 192 changeset: 0:65d4e9386227
193 193 user: test
194 194 date: Thu Jan 01 00:00:00 1970 +0000
195 195 files: foo/plain-file
196 196 description:
197 197 commit-foo-subdir
198 198
199 199
200 200
201 201 subdir log
202 202
203 203 $ cd foo
204 204 $ hg log .
205 205 changeset: 1:95b38e3a5b2e
206 206 tag: tip
207 207 user: test
208 208 date: Thu Jan 01 00:00:00 1970 +0000
209 209 summary: commit-foo-dot
210 210
211 211 changeset: 0:65d4e9386227
212 212 user: test
213 213 date: Thu Jan 01 00:00:00 1970 +0000
214 214 summary: commit-foo-subdir
215 215
216 216 $ cd ..
217 217 $ cd ..
218 218
219 219 Issue1049: Hg permits partial commit of merge without warning
220 220
221 221 $ cd ..
222 222 $ hg init issue1049
223 223 $ cd issue1049
224 224 $ echo a > a
225 225 $ hg ci -Ama
226 226 adding a
227 227 $ echo a >> a
228 228 $ hg ci -mb
229 229 $ hg up 0
230 230 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
231 231 $ echo b >> a
232 232 $ hg ci -mc
233 233 created new head
234 234 $ HGMERGE=true hg merge
235 235 merging a
236 236 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
237 237 (branch merge, don't forget to commit)
238 238
239 239 should fail because we are specifying a file name
240 240
241 241 $ hg ci -mmerge a
242 242 abort: cannot partially commit a merge (do not specify files or patterns)
243 243 [255]
244 244
245 245 should fail because we are specifying a pattern
246 246
247 247 $ hg ci -mmerge -I a
248 248 abort: cannot partially commit a merge (do not specify files or patterns)
249 249 [255]
250 250
251 251 should succeed
252 252
253 253 $ hg ci -mmerge
254 254 $ cd ..
255 255
256 256
257 257 test commit message content
258 258
259 259 $ hg init commitmsg
260 260 $ cd commitmsg
261 261 $ echo changed > changed
262 262 $ echo removed > removed
263 263 $ hg ci -qAm init
264 264
265 265 $ hg rm removed
266 266 $ echo changed >> changed
267 267 $ echo added > added
268 268 $ hg add added
269 269 $ HGEDITOR=cat hg ci -A
270 270
271 271
272 272 HG: Enter commit message. Lines beginning with 'HG:' are removed.
273 273 HG: Leave message empty to abort commit.
274 274 HG: --
275 275 HG: user: test
276 276 HG: branch 'default'
277 277 HG: added added
278 278 HG: changed changed
279 279 HG: removed removed
280 280 abort: empty commit message
281 281 [255]
@@ -1,117 +1,117 b''
1 1 $ "$TESTDIR/hghave" no-outer-repo || exit 80
2 2
3 3 no repo
4 4
5 5 $ hg id
6 6 abort: there is no Mercurial repository here (.hg not found)
7 7 [255]
8 8
9 9 create repo
10 10
11 11 $ hg init test
12 12 $ cd test
13 13 $ echo a > a
14 14 $ hg ci -Ama
15 15 adding a
16 16
17 17 basic id usage
18 18
19 19 $ hg id
20 20 cb9a9f314b8b tip
21 21 $ hg id --debug
22 22 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b tip
23 23 $ hg id -q
24 24 cb9a9f314b8b
25 25 $ hg id -v
26 26 cb9a9f314b8b tip
27 27
28 28 with options
29 29
30 30 $ hg id -r.
31 31 cb9a9f314b8b tip
32 32 $ hg id -n
33 33 0
34 34 $ hg id -t
35 35 tip
36 36 $ hg id -b
37 37 default
38 38 $ hg id -i
39 39 cb9a9f314b8b
40 40 $ hg id -n -t -b -i
41 41 cb9a9f314b8b 0 default tip
42 42
43 43 with modifications
44 44
45 45 $ echo b > a
46 46 $ hg id -n -t -b -i
47 47 cb9a9f314b8b+ 0+ default tip
48 48
49 49 other local repo
50 50
51 51 $ cd ..
52 52 $ hg -R test id
53 53 cb9a9f314b8b+ tip
54 54 $ hg id test
55 55 cb9a9f314b8b+ tip
56 56
57 57 with remote http repo
58 58
59 59 $ cd test
60 60 $ hg serve -p $HGPORT1 -d --pid-file=hg.pid
61 61 $ cat hg.pid >> $DAEMON_PIDS
62 62 $ hg id http://localhost:$HGPORT1/
63 63 cb9a9f314b8b
64 64
65 65 remote with rev number?
66 66
67 67 $ hg id -n http://localhost:$HGPORT1/
68 68 abort: can't query remote revision number, branch, or tags
69 69 [255]
70 70
71 71 remote with tags?
72 72
73 73 $ hg id -t http://localhost:$HGPORT1/
74 74 abort: can't query remote revision number, branch, or tags
75 75 [255]
76 76
77 77 remote with branch?
78 78
79 79 $ hg id -b http://localhost:$HGPORT1/
80 80 abort: can't query remote revision number, branch, or tags
81 81 [255]
82 82
83 83 test bookmark support
84 84
85 85 $ hg bookmark Y
86 86 $ hg bookmark Z
87 87 $ hg bookmarks
88 88 Y 0:cb9a9f314b8b
89 89 * Z 0:cb9a9f314b8b
90 90 $ hg id
91 91 cb9a9f314b8b+ tip Y/Z
92 92 $ hg id --bookmarks
93 93 Y Z
94 94
95 95 test remote identify with bookmarks
96 96
97 97 $ hg id http://localhost:$HGPORT1/
98 98 cb9a9f314b8b Y/Z
99 99 $ hg id --bookmarks http://localhost:$HGPORT1/
100 100 Y Z
101 101 $ hg id -r . http://localhost:$HGPORT1/
102 102 cb9a9f314b8b Y/Z
103 103 $ hg id --bookmarks -r . http://localhost:$HGPORT1/
104 104 Y Z
105 105
106 106 Make sure we do not obscure unknown requires file entries (issue2649)
107 107
108 108 $ echo fake >> .hg/requires
109 109 $ hg id
110 abort: unknown repository format: requires feature 'fake' (upgrade Mercurial)!
110 abort: unknown repository format: requires features 'fake' (upgrade Mercurial)!
111 111 [255]
112 112
113 113 $ cd ..
114 114 $ hg id test
115 abort: unknown repository format: requires feature 'fake' (upgrade Mercurial)!
115 abort: unknown repository format: requires features 'fake' (upgrade Mercurial)!
116 116 [255]
117 117
@@ -1,13 +1,17 b''
1 1 $ hg init t
2 2 $ cd t
3 3 $ echo a > a
4 4 $ hg add a
5 5 $ hg commit -m test
6 6 $ rm .hg/requires
7 7 $ hg tip
8 8 abort: index 00changelog.i unknown format 2!
9 9 [255]
10 10 $ echo indoor-pool > .hg/requires
11 11 $ hg tip
12 abort: unknown repository format: requires feature 'indoor-pool' (upgrade Mercurial)!
12 abort: unknown repository format: requires features 'indoor-pool' (upgrade Mercurial)!
13 13 [255]
14 $ echo outdoor-pool >> .hg/requires
15 $ hg tip
16 abort: unknown repository format: requires features 'indoor-pool', 'outdoor-pool' (upgrade Mercurial)!
17 [255]
General Comments 0
You need to be logged in to leave comments. Login now