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 _kwbailout(ui): |
311 def _bail_if_nokwconf(ui): |
|
312 if hasattr(ui, 'kwfmatcher'): |
|
313 return |
312 if ui.configitems('keyword'): |
314 if ui.configitems('keyword'): |
313 raise util.Abort(_('[keyword] patterns cannot match')) |
315 raise util.Abort(_('[keyword] patterns cannot match')) |
314 raise util.Abort(_('no [keyword] patterns configured')) |
316 raise util.Abort(_('no [keyword] patterns configured')) |
315 |
317 |
|
318 def _iskwfile(ui, man, f): |
|
319 return not man.linkf(f) and ui.kwfmatcher(f) |
|
320 |
316 def _overwrite(ui, repo, expand, *pats, **opts): |
321 def _overwrite(ui, repo, expand, *pats, **opts): |
317 '''Expands/shrinks keywords in working directory.''' |
322 '''Expands/shrinks keywords in working directory.''' |
|
323 _bail_if_nokwconf(ui) |
318 bail_if_changed(repo) |
324 bail_if_changed(repo) |
319 wlock = lock = None |
325 wlock = lock = None |
320 try: |
326 try: |
321 wlock = repo.wlock() |
327 wlock = repo.wlock() |
322 lock = repo.lock() |
328 lock = repo.lock() |
326 ctx = repo.changectx() |
332 ctx = repo.changectx() |
327 man = ctx.manifest() |
333 man = ctx.manifest() |
328 mfiles = man.keys() |
334 mfiles = man.keys() |
329 mfiles.sort() |
335 mfiles.sort() |
330 files = [] |
336 files = [] |
331 |
|
332 def iskwfile(f): |
|
333 try: |
|
334 return ui.kwfmatcher(f) and not man.linkf(f) |
|
335 except AttributeError: |
|
336 _kwbailout(ui) |
|
337 |
|
338 for f in mfiles: |
337 for f in mfiles: |
339 for ff in fdict: |
338 for ff in fdict: |
340 if ff == f or ff.startswith('%s/' % f): |
339 if ff == f or ff.startswith('%s/' % f): |
341 if iskwfile(ff): |
340 if _iskwfile(ui, man, ff): |
342 files.append(ff) |
341 files.append(ff) |
343 del fdict[ff] |
342 del fdict[ff] |
344 break |
343 break |
345 if not f in files and match(f) and iskwfile(f): |
344 if not f in files and match(f) and _iskwfile(ui, man, f): |
346 files.append(f) |
345 files.append(f) |
347 if files: |
346 if files: |
348 kwt = kwtemplater(ui, repo, expand, node=ctx.node()) |
347 kwt = kwtemplater(ui, repo, expand, node=ctx.node()) |
349 # 3rd argument sets commit to False |
348 # 3rd argument sets commit to False |
350 kwt.overwrite(files, man, False) |
349 kwt.overwrite(files, man, False) |
374 |
373 |
375 Crosscheck which files in working directory are potential targets for |
374 Crosscheck which files in working directory are potential targets for |
376 keyword expansion. |
375 keyword expansion. |
377 That is, files matched by [keyword] config patterns but not symlinks. |
376 That is, files matched by [keyword] config patterns but not symlinks. |
378 ''' |
377 ''' |
|
378 _bail_if_nokwconf(ui) |
379 files, match, anypats = cmdutil.matchpats(repo, pats, opts) |
379 files, match, anypats = cmdutil.matchpats(repo, pats, opts) |
380 status = repo.status(files=files, match=match, list_clean=True) |
380 status = repo.status(files=files, match=match, list_clean=True) |
381 modified, added, removed, deleted, unknown, ignored, clean = status |
381 modified, added, removed, deleted, unknown, ignored, clean = status |
382 if opts['untracked']: |
382 if opts['untracked']: |
383 files = modified + added + unknown + clean |
383 files = modified + added + unknown + clean |
384 else: |
384 else: |
385 files = modified + added + clean |
385 files = modified + added + clean |
386 files.sort() |
386 files.sort() |
387 try: |
387 # use the full definition of repo._link for backwards compatibility |
388 # use the full definition of repo._link for backwards compatibility |
388 kwfiles = [f for f in files if ui.kwfmatcher(f) |
389 kwfiles = [f for f in files if ui.kwfmatcher(f) |
389 and not os.path.islink(repo.wjoin(f))] |
390 and not os.path.islink(repo.wjoin(f))] |
|
391 except AttributeError: |
|
392 _kwbailout(ui) |
|
393 cwd = pats and repo.getcwd() or '' |
390 cwd = pats and repo.getcwd() or '' |
394 allf = opts['all'] |
391 allf = opts['all'] |
395 ignore = opts['ignore'] |
392 ignore = opts['ignore'] |
396 flag = (allf or ui.verbose) and 1 or 0 |
393 flag = (allf or ui.verbose) and 1 or 0 |
397 if not ignore: |
394 if not ignore: |
551 node = self._commit(files, text, user, date, match, force, |
548 node = self._commit(files, text, user, date, match, force, |
552 _lock, _wlock, force_editor, p1, p2, extra) |
549 _lock, _wlock, force_editor, p1, p2, extra) |
553 if node is not None: |
550 if node is not None: |
554 cl = self.changelog.read(node) |
551 cl = self.changelog.read(node) |
555 mn = self.manifest.read(cl[0]) |
552 mn = self.manifest.read(cl[0]) |
556 candidates = [f for f in cl[3] if ui.kwfmatcher(f) |
553 candidates = [f for f in cl[3] if mn.has_key(f) |
557 and mn.has_key(f) and not mn.linkf(f)] |
554 and _iskwfile(ui, mn, f)] |
558 if candidates: |
555 if candidates: |
559 # 3rd argument sets expansion to True |
556 # 3rd argument sets expansion to True |
560 kwt = kwtemplater(ui, self, True, node=node) |
557 kwt = kwtemplater(ui, self, True, node=node) |
561 # 3rd argument sets commit to True |
558 # 3rd argument sets commit to True |
562 kwt.overwrite(candidates, mn, True) |
559 kwt.overwrite(candidates, mn, True) |