hgkw/keyword.py
changeset 280 2088e409d360
parent 278 232df68a0bcc
child 282 2386cdd2ef2e
equal deleted inserted replaced
279:1f00dce8de12 280:2088e409d360
    95     try:
    95     try:
    96         # commands.parse moves to cmdutil.parse in 0c61124ad877
    96         # commands.parse moves to cmdutil.parse in 0c61124ad877
    97         _parse = cmdutil.parse
    97         _parse = cmdutil.parse
    98     except AttributeError:
    98     except AttributeError:
    99         _parse = commands.parse
    99         _parse = commands.parse
   100 
       
   101 try:
       
   102     # bail_if_changed moves from commands to cmdutil in 0c61124ad877
       
   103     bail_if_changed = cmdutil.bail_if_changed
       
   104 except AttributeError:
       
   105     bail_if_changed = commands.bail_if_changed
       
   106 
   100 
   107 def _pathto(repo, f, cwd=None):
   101 def _pathto(repo, f, cwd=None):
   108     '''kwfiles behaves similar to status, using pathto since 78b6add1f966.'''
   102     '''kwfiles behaves similar to status, using pathto since 78b6add1f966.'''
   109     try:
   103     try:
   110         if cwd is None:
   104         if cwd is None:
   308         if self.renamed(node):
   302         if self.renamed(node):
   309             t2 = super(kwfilelog, self).read(node)
   303             t2 = super(kwfilelog, self).read(node)
   310             return t2 != text
   304             return t2 != text
   311         return revlog.revlog.cmp(self, node, text)
   305         return revlog.revlog.cmp(self, node, text)
   312 
   306 
   313 def _bail_if_nokwconf(ui):
   307 def _status(ui, repo, *pats, **opts):
   314     if hasattr(ui, 'kwfmatcher'):
   308     if hasattr(ui, 'kwfmatcher'):
   315         return
   309         files, match, anypats = cmdutil.matchpats(repo, pats, opts)
       
   310         return repo.status(files=files, match=match, list_clean=True)
   316     if ui.configitems('keyword'):
   311     if ui.configitems('keyword'):
   317         raise util.Abort(_('[keyword] patterns cannot match'))
   312         raise util.Abort(_('[keyword] patterns cannot match'))
   318     raise util.Abort(_('no [keyword] patterns configured'))
   313     raise util.Abort(_('no [keyword] patterns configured'))
   319 
   314 
   320 def _iskwfile(ui, man, f):
   315 def _iskwfile(ui, man, f):
   327         kwt = kwtemplater(ui, repo, expand, node=node)
   322         kwt = kwtemplater(ui, repo, expand, node=node)
   328         kwt.overwrite(files, man, commit)
   323         kwt.overwrite(files, man, commit)
   329 
   324 
   330 def _kwfwrite(ui, repo, expand, *pats, **opts):
   325 def _kwfwrite(ui, repo, expand, *pats, **opts):
   331     '''Selects files and passes them to _overwrite.'''
   326     '''Selects files and passes them to _overwrite.'''
   332     _bail_if_nokwconf(ui)
   327     status = _status(ui, repo, *pats, **opts)
   333     bail_if_changed(repo)
   328     modified, added, removed, deleted, unknown, ignored, clean = status
       
   329     if modified or added or removed or deleted:
       
   330         raise util.Abort(_('outstanding uncommitted changes in given files'))
   334     wlock = lock = None
   331     wlock = lock = None
   335     try:
   332     try:
   336         wlock = repo.wlock()
   333         wlock = repo.wlock()
   337         lock = repo.lock()
   334         lock = repo.lock()
   338         files, match, anypats = cmdutil.matchpats(repo, pats, opts)
       
   339         fdict = dict.fromkeys(files)
       
   340         fdict.pop('.', None)
       
   341         ctx = repo.changectx()
   335         ctx = repo.changectx()
   342         man = ctx.manifest()
   336         man = ctx.manifest()
   343         mfiles = man.keys()
   337         candidates = [f for f in clean if _iskwfile(ui, man, f)]
   344         mfiles.sort()
       
   345         files = []
       
   346         for f in mfiles:
       
   347             for ff in fdict:
       
   348                 if ff == f or ff.startswith('%s/' % f):
       
   349                     if _iskwfile(ui, man, ff):
       
   350                         files.append(ff)
       
   351                     del fdict[ff]
       
   352                     break
       
   353             if not f in files and match(f) and _iskwfile(ui, man, f):
       
   354                 files.append(f)
       
   355         ffiles = fdict.keys()
       
   356         ffiles.sort()
       
   357         for f in ffiles:
       
   358             ui.warn(_('%s: No such file in working copy\n') % _pathto(repo, f))
       
   359         # 7th argument sets commit to False
   338         # 7th argument sets commit to False
   360         _overwrite(ui, repo, files, ctx.node(), man, expand, False)
   339         _overwrite(ui, repo, candidates, ctx.node(), man, expand, False)
   361     finally:
   340     finally:
   362         del wlock, lock
   341         del wlock, lock
   363 
   342 
   364 
   343 
   365 def shrink(ui, repo, *pats, **opts):
   344 def shrink(ui, repo, *pats, **opts):
   384 
   363 
   385     Crosscheck which files in working directory are potential targets for
   364     Crosscheck which files in working directory are potential targets for
   386     keyword expansion.
   365     keyword expansion.
   387     That is, files matched by [keyword] config patterns but not symlinks.
   366     That is, files matched by [keyword] config patterns but not symlinks.
   388     '''
   367     '''
   389     _bail_if_nokwconf(ui)
   368     status = _status(ui, repo, *pats, **opts)
   390     files, match, anypats = cmdutil.matchpats(repo, pats, opts)
       
   391     status = repo.status(files=files, match=match, list_clean=True)
       
   392     modified, added, removed, deleted, unknown, ignored, clean = status
   369     modified, added, removed, deleted, unknown, ignored, clean = status
   393     if opts['untracked']:
   370     if opts['untracked']:
   394         files = modified + added + unknown + clean
   371         files = modified + added + unknown + clean
   395     else:
   372     else:
   396         files = modified + added + clean
   373         files = modified + added + clean