308 Caveat: localrepository._link fails on Windows.''' |
308 Caveat: localrepository._link fails on Windows.''' |
309 return self.matcher(path) and not islink(path) |
309 return self.matcher(path) and not islink(path) |
310 |
310 |
311 def overwrite(self, node, expand, files): |
311 def overwrite(self, node, expand, files): |
312 '''Overwrites selected files expanding/shrinking keywords.''' |
312 '''Overwrites selected files expanding/shrinking keywords.''' |
313 ctx = self.repo.changectx(node) |
313 # repo[changeid] introduced in f6c00b17387c |
314 mf = ctx.manifest() |
|
315 if node is not None: # commit |
314 if node is not None: # commit |
|
315 try: |
|
316 ctx = self.repo[node] |
|
317 except TypeError: |
|
318 ctx = self.repo.changectx(node) |
|
319 mf = ctx.manifest() |
316 files = [f for f in ctx.files() if f in mf] |
320 files = [f for f in ctx.files() if f in mf] |
317 notify = self.ui.debug |
321 notify = self.ui.debug |
318 else: # kwexpand/kwshrink |
322 else: # kwexpand/kwshrink |
|
323 try: |
|
324 ctx = self.repo['.'] |
|
325 except TypeError: |
|
326 ctx = self.repo.changectx() |
|
327 mf = ctx.manifest() |
319 notify = self.ui.note |
328 notify = self.ui.note |
320 candidates = [f for f in files if self.iskwfile(f, mf.linkf)] |
329 if hasattr(ctx, 'flags'): |
|
330 # 51b0e799352f |
|
331 islink = lambda p: 'l' in ctx.flags(p) |
|
332 else: |
|
333 islink = mf.linkf |
|
334 candidates = [f for f in files if self.iskwfile(f, islink)] |
321 if candidates: |
335 if candidates: |
322 self.restrict = True # do not expand when reading |
336 self.restrict = True # do not expand when reading |
323 candidates.sort() |
337 candidates.sort() |
324 action = expand and 'expanding' or 'shrinking' |
338 action = expand and 'expanding' or 'shrinking' |
325 overwritten = [] |
339 overwritten = [] |
390 if self.renamed(node): |
404 if self.renamed(node): |
391 t2 = super(kwfilelog, self).read(node) |
405 t2 = super(kwfilelog, self).read(node) |
392 return t2 != text |
406 return t2 != text |
393 return revlog.revlog.cmp(self, node, text) |
407 return revlog.revlog.cmp(self, node, text) |
394 |
408 |
395 def _status(ui, repo, kwt, *pats, **opts): |
409 def _status(ui, repo, kwt, unknown, *pats, **opts): |
396 '''Bails out if [keyword] configuration is not active. |
410 '''Bails out if [keyword] configuration is not active. |
397 Returns status of working directory.''' |
411 Returns status of working directory.''' |
398 if kwt: |
412 if kwt: |
399 try: |
413 try: |
400 # 0159b7a36184 ff. |
414 # 0159b7a36184 ff. |
401 matcher = cmdutil.match(repo, pats, opts) |
415 matcher = cmdutil.match(repo, pats, opts) |
402 return repo.status(match=matcher, list_clean=True) |
416 try: |
|
417 # 4faaa0535ea7 |
|
418 return repo.status(match=matcher, unknown=unknown, clean=True) |
|
419 except TypeError: |
|
420 return repo.status(match=matcher, list_clean=True) |
403 except AttributeError: |
421 except AttributeError: |
404 files, match, anypats = cmdutil.matchpats(repo, pats, opts) |
422 files, match, anypats = cmdutil.matchpats(repo, pats, opts) |
405 return repo.status(files=files, match=match, list_clean=True) |
423 return repo.status(files=files, match=match, list_clean=True) |
406 if ui.configitems('keyword'): |
424 if ui.configitems('keyword'): |
407 raise util.Abort(_('[keyword] patterns cannot match')) |
425 raise util.Abort(_('[keyword] patterns cannot match')) |
410 def _kwfwrite(ui, repo, expand, *pats, **opts): |
428 def _kwfwrite(ui, repo, expand, *pats, **opts): |
411 '''Selects files and passes them to kwtemplater.overwrite.''' |
429 '''Selects files and passes them to kwtemplater.overwrite.''' |
412 if repo.dirstate.parents()[1] != nullid: |
430 if repo.dirstate.parents()[1] != nullid: |
413 raise util.Abort(_('outstanding uncommitted merge')) |
431 raise util.Abort(_('outstanding uncommitted merge')) |
414 kwt = kwtools['templater'] |
432 kwt = kwtools['templater'] |
415 status = _status(ui, repo, kwt, *pats, **opts) |
433 status = _status(ui, repo, kwt, False, *pats, **opts) |
416 modified, added, removed, deleted, unknown, ignored, clean = status |
434 modified, added, removed, deleted = status[:4] |
417 if modified or added or removed or deleted: |
435 if modified or added or removed or deleted: |
418 raise util.Abort(_('outstanding uncommitted changes')) |
436 raise util.Abort(_('outstanding uncommitted changes')) |
419 wlock = lock = None |
437 wlock = lock = None |
420 try: |
438 try: |
421 wlock = repo.wlock() |
439 wlock = repo.wlock() |
422 lock = repo.lock() |
440 lock = repo.lock() |
423 kwt.overwrite(None, expand, clean) |
441 kwt.overwrite(None, expand, status[6]) |
424 finally: |
442 finally: |
425 del wlock, lock |
443 del wlock, lock |
426 |
444 |
427 |
445 |
428 def demo(ui, repo, *args, **opts): |
446 def demo(ui, repo, *args, **opts): |
521 Crosscheck which files in working directory are potential targets for |
539 Crosscheck which files in working directory are potential targets for |
522 keyword expansion. |
540 keyword expansion. |
523 That is, files matched by [keyword] config patterns but not symlinks. |
541 That is, files matched by [keyword] config patterns but not symlinks. |
524 ''' |
542 ''' |
525 kwt = kwtools['templater'] |
543 kwt = kwtools['templater'] |
526 status = _status(ui, repo, kwt, *pats, **opts) |
544 status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts) |
527 modified, added, removed, deleted, unknown, ignored, clean = status |
545 modified, added, removed, deleted, unknown, ignored, clean = status |
528 files = modified + added + clean |
546 try: |
529 if opts.get('untracked'): |
547 # f67d1468ac50 |
530 files += unknown |
548 files = util.sort(modified + added + clean + unknown) |
531 files.sort() |
549 except AttributeError: |
532 wctx = repo.workingctx() |
550 files = modified + added + clean |
533 if hasattr(wctx, 'fileflags'): |
551 if opts.get('untracked'): |
|
552 files += unknown |
|
553 files.sort() |
|
554 try: |
|
555 # f6c00b17387c |
|
556 wctx = repo[None] |
|
557 except TypeError: |
|
558 wctx = repo.workingctx() |
|
559 if hasattr(wctx, 'flags'): |
|
560 islink = lambda p: 'l' in wctx.flags(p) |
|
561 elif hasattr(wctx, 'fileflags'): |
534 islink = lambda p: 'l' in wctx.fileflags(p) |
562 islink = lambda p: 'l' in wctx.fileflags(p) |
535 else: |
563 else: |
536 mf = wctx.manifest() |
564 mf = wctx.manifest() |
537 islink = mf.linkf |
565 islink = mf.linkf |
538 kwfiles = [f for f in files if kwt.iskwfile(f, islink)] |
566 kwfiles = [f for f in files if kwt.iskwfile(f, islink)] |