306 if self.renamed(node): |
306 if self.renamed(node): |
307 t2 = super(kwfilelog, self).read(node) |
307 t2 = super(kwfilelog, self).read(node) |
308 return t2 != text |
308 return t2 != text |
309 return revlog.revlog.cmp(self, node, text) |
309 return revlog.revlog.cmp(self, node, text) |
310 |
310 |
311 def _weedfiles(ui, repo, files): |
311 def _kwbailout(ui): |
312 '''Selects files that match [keyword] patterns and are not links.''' |
312 if ui.configitems('keyword'): |
313 try: |
313 raise util.Abort(_('[keyword] patterns cannot match')) |
314 # use the full definition of repo._link for backwards compatibility |
314 raise util.Abort(_('no [keyword] patterns configured')) |
315 return [f for f in files if ui.kwfmatcher(f) |
|
316 and not os.path.islink(repo.wjoin(f))] |
|
317 except AttributeError: |
|
318 if ui.configitems('keyword'): |
|
319 raise util.Abort(_('[keyword] patterns cannot match')) |
|
320 raise util.Abort(_('no [keyword] patterns configured')) |
|
321 |
315 |
322 def _overwrite(ui, repo, expand, *pats, **opts): |
316 def _overwrite(ui, repo, expand, *pats, **opts): |
323 '''Expands/shrinks keywords in working directory.''' |
317 '''Expands/shrinks keywords in working directory.''' |
324 bail_if_changed(repo) |
318 bail_if_changed(repo) |
325 wlock = lock = None |
319 wlock = lock = None |
326 try: |
320 try: |
327 wlock = repo.wlock() |
321 wlock = repo.wlock() |
328 lock = repo.lock() |
322 lock = repo.lock() |
329 files, match, anypats = cmdutil.matchpats(repo, pats, opts) |
323 files, match, anypats = cmdutil.matchpats(repo, pats, opts) |
330 clean = repo.status(files=files, match=match, list_clean=True)[6] |
324 ctx = repo.changectx() |
331 candidates = _weedfiles(ui, repo, clean) |
325 node = ctx.node() |
332 if candidates: |
326 man = ctx.manifest() |
333 ctx = repo.changectx() |
327 try: |
334 kwt = kwtemplater(ui, repo, expand, node=ctx.node()) |
328 files = [f for src, f |
|
329 in repo.walk(node=node, files=files, match=match) |
|
330 if ui.kwfmatcher(f) and not man.linkf(f)] |
|
331 except AttributeError: |
|
332 _kwbailout(ui) |
|
333 if files: |
|
334 kwt = kwtemplater(ui, repo, expand, node=node) |
335 # 3rd argument sets commit to False |
335 # 3rd argument sets commit to False |
336 kwt.overwrite(candidates, ctx.manifest(), False) |
336 kwt.overwrite(files, man, False) |
337 finally: |
337 finally: |
338 del wlock, lock |
338 del wlock, lock |
339 |
339 |
340 |
340 |
341 def shrink(ui, repo, *pats, **opts): |
341 def shrink(ui, repo, *pats, **opts): |
368 if opts['untracked']: |
368 if opts['untracked']: |
369 files = modified + added + unknown + clean |
369 files = modified + added + unknown + clean |
370 else: |
370 else: |
371 files = modified + added + clean |
371 files = modified + added + clean |
372 files.sort() |
372 files.sort() |
373 kwfiles = _weedfiles(ui, repo, files) |
373 try: |
|
374 # use the full definition of repo._link for backwards compatibility |
|
375 kwfiles = [f for f in files if ui.kwfmatcher(f) |
|
376 and not os.path.islink(repo.wjoin(f))] |
|
377 except AttributeError: |
|
378 _kwbailout(ui) |
374 cwd = pats and repo.getcwd() or '' |
379 cwd = pats and repo.getcwd() or '' |
375 allf = opts['all'] |
380 allf = opts['all'] |
376 ignore = opts['ignore'] |
381 ignore = opts['ignore'] |
377 flag = (allf or ui.verbose) and 1 or 0 |
382 flag = (allf or ui.verbose) and 1 or 0 |
378 if not ignore: |
383 if not ignore: |