##// END OF EJS Templates
keyword: copy: when copied source is a symlink, follow it...
Christian Ebert -
r13069:6aff4f14 1.7.2 stable
parent child Browse files
Show More
@@ -86,7 +86,7 b' from mercurial import commands, context,'
86 from mercurial import localrepo, match, patch, templatefilters, templater, util
86 from mercurial import localrepo, match, patch, templatefilters, templater, util
87 from mercurial.hgweb import webcommands
87 from mercurial.hgweb import webcommands
88 from mercurial.i18n import _
88 from mercurial.i18n import _
89 import re, shutil, tempfile
89 import os, re, shutil, tempfile
90
90
91 commands.optionalrepo += ' kwdemo'
91 commands.optionalrepo += ' kwdemo'
92
92
@@ -555,17 +555,31 b' def reposetup(ui, repo):'
555 def kw_copy(orig, ui, repo, pats, opts, rename=False):
555 def kw_copy(orig, ui, repo, pats, opts, rename=False):
556 '''Wraps cmdutil.copy so that copy/rename destinations do not
556 '''Wraps cmdutil.copy so that copy/rename destinations do not
557 contain expanded keywords.
557 contain expanded keywords.
558 Note that the source may also be a symlink as:
558 Note that the source of a regular file destination may also be a
559 symlink:
559 hg cp sym x -> x is symlink
560 hg cp sym x -> x is symlink
560 cp sym x; hg cp -A sym x -> x is file (maybe expanded keywords)
561 cp sym x; hg cp -A sym x -> x is file (maybe expanded keywords)
561 '''
562 For the latter we have to follow the symlink to find out whether its
563 target is configured for expansion and we therefore must unexpand the
564 keywords in the destination.'''
562 orig(ui, repo, pats, opts, rename)
565 orig(ui, repo, pats, opts, rename)
563 if opts.get('dry_run'):
566 if opts.get('dry_run'):
564 return
567 return
565 wctx = repo[None]
568 wctx = repo[None]
569 cwd = repo.getcwd()
570
571 def haskwsource(dest):
572 '''Returns true if dest is a regular file and configured for
573 expansion or a symlink which points to a file configured for
574 expansion. '''
575 source = repo.dirstate.copied(dest)
576 if 'l' in wctx.flags(source):
577 source = util.canonpath(repo.root, cwd,
578 os.path.realpath(source))
579 return kwt.match(source)
580
566 candidates = [f for f in repo.dirstate.copies() if
581 candidates = [f for f in repo.dirstate.copies() if
567 kwt.match(repo.dirstate.copied(f)) and
582 not 'l' in wctx.flags(f) and haskwsource(f)]
568 not 'l' in wctx.flags(f)]
569 kwt.overwrite(wctx, candidates, False, False)
583 kwt.overwrite(wctx, candidates, False, False)
570
584
571 def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
585 def kw_dorecord(orig, ui, repo, commitfunc, *pats, **opts):
@@ -553,7 +553,8 b' Copy ignored file to ignored file: no ov'
553 $ hg forget i
553 $ hg forget i
554 $ rm i
554 $ rm i
555
555
556 cp symlink (becomes regular file), and hg copy after
556 cp symlink file; hg cp -A symlink file (part1)
557 - copied symlink points to kwfile: overwrite
557
558
558 $ cp sym i
559 $ cp sym i
559 $ ls -l i
560 $ ls -l i
@@ -602,6 +603,26 b' Status after rollback:'
602 $ hg update --clean
603 $ hg update --clean
603 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
604 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
604
605
606 cp symlink file; hg cp -A symlink file (part2)
607 - copied symlink points to kw ignored file: do not overwrite
608
609 $ cat a > i
610 $ ln -s i symignored
611 $ hg commit -Am 'fake expansion in ignored and symlink' i symignored
612 $ cp symignored x
613 $ hg copy --after --verbose symignored x
614 copying symignored to x
615 $ head -n 1 x
616 expand $Id: a,v ef63ca68695b 1970/01/01 00:00:00 user $
617 $ hg forget x
618 $ rm x
619
620 $ hg rollback
621 rolling back to revision 1 (undo commit)
622 $ hg update --clean
623 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
624 $ rm i symignored
625
605 Custom keywordmaps as argument to kwdemo
626 Custom keywordmaps as argument to kwdemo
606
627
607 $ hg --quiet kwdemo "Xinfo = {author}: {desc}"
628 $ hg --quiet kwdemo "Xinfo = {author}: {desc}"
General Comments 0
You need to be logged in to leave comments. Login now