316 raise util.Abort(_('no [keyword] patterns configured')) |
316 raise util.Abort(_('no [keyword] patterns configured')) |
317 |
317 |
318 def _iskwfile(ui, man, f): |
318 def _iskwfile(ui, man, f): |
319 return not man.linkf(f) and ui.kwfmatcher(f) |
319 return not man.linkf(f) and ui.kwfmatcher(f) |
320 |
320 |
321 def _overwrite(ui, repo, expand, *pats, **opts): |
321 def _overwrite(ui, repo, files, node, man, expand, commit): |
322 '''Expands/shrinks keywords in working directory.''' |
322 '''Passes given files to kwtemplater for overwriting.''' |
|
323 if files: |
|
324 files.sort() |
|
325 kwt = kwtemplater(ui, repo, expand, node=node) |
|
326 kwt.overwrite(files, man, commit) |
|
327 |
|
328 def _kwfwrite(ui, repo, expand, *pats, **opts): |
|
329 '''Selects files and passes them to _overwrite.''' |
323 _bail_if_nokwconf(ui) |
330 _bail_if_nokwconf(ui) |
324 bail_if_changed(repo) |
331 bail_if_changed(repo) |
325 wlock = lock = None |
332 wlock = lock = None |
326 try: |
333 try: |
327 wlock = repo.wlock() |
334 wlock = repo.wlock() |
341 files.append(ff) |
348 files.append(ff) |
342 del fdict[ff] |
349 del fdict[ff] |
343 break |
350 break |
344 if not f in files and match(f) and _iskwfile(ui, man, f): |
351 if not f in files and match(f) and _iskwfile(ui, man, f): |
345 files.append(f) |
352 files.append(f) |
346 if files: |
353 # 7th argument sets commit to False |
347 files.sort() |
354 _overwrite(ui, repo, files, ctx.node(), man, expand, False) |
348 kwt = kwtemplater(ui, repo, expand, node=ctx.node()) |
|
349 # 3rd argument sets commit to False |
|
350 kwt.overwrite(files, man, False) |
|
351 finally: |
355 finally: |
352 del wlock, lock |
356 del wlock, lock |
353 |
357 |
354 |
358 |
355 def shrink(ui, repo, *pats, **opts): |
359 def shrink(ui, repo, *pats, **opts): |
357 |
361 |
358 Run before changing/disabling active keywords |
362 Run before changing/disabling active keywords |
359 or if you experience problems with "hg import" or "hg merge". |
363 or if you experience problems with "hg import" or "hg merge". |
360 ''' |
364 ''' |
361 # 3rd argument sets expansion to False |
365 # 3rd argument sets expansion to False |
362 _overwrite(ui, repo, False, *pats, **opts) |
366 _kwfwrite(ui, repo, False, *pats, **opts) |
363 |
367 |
364 def expand(ui, repo, *pats, **opts): |
368 def expand(ui, repo, *pats, **opts): |
365 '''expand keywords in working directory |
369 '''expand keywords in working directory |
366 |
370 |
367 Run after (re)enabling keyword expansion. |
371 Run after (re)enabling keyword expansion. |
368 ''' |
372 ''' |
369 # 3rd argument sets expansion to True |
373 # 3rd argument sets expansion to True |
370 _overwrite(ui, repo, True, *pats, **opts) |
374 _kwfwrite(ui, repo, True, *pats, **opts) |
371 |
375 |
372 def files(ui, repo, *pats, **opts): |
376 def files(ui, repo, *pats, **opts): |
373 '''print files currently configured for keyword expansion |
377 '''print files currently configured for keyword expansion |
374 |
378 |
375 Crosscheck which files in working directory are potential targets for |
379 Crosscheck which files in working directory are potential targets for |
551 if node is not None: |
555 if node is not None: |
552 cl = self.changelog.read(node) |
556 cl = self.changelog.read(node) |
553 mn = self.manifest.read(cl[0]) |
557 mn = self.manifest.read(cl[0]) |
554 candidates = [f for f in cl[3] if mn.has_key(f) |
558 candidates = [f for f in cl[3] if mn.has_key(f) |
555 and _iskwfile(ui, mn, f)] |
559 and _iskwfile(ui, mn, f)] |
556 if candidates: |
560 # 6th, 7th arguments set expansion, commit to True |
557 candidates.sort() |
561 _overwrite(ui, self, candidates, node, mn, True, True) |
558 # 3rd argument sets expansion to True |
|
559 kwt = kwtemplater(ui, self, True, node=node) |
|
560 # 3rd argument sets commit to True |
|
561 kwt.overwrite(candidates, mn, True) |
|
562 return node |
562 return node |
563 finally: |
563 finally: |
564 del _wlock, _lock |
564 del _wlock, _lock |
565 |
565 |
566 repo.__class__ = kwrepo |
566 repo.__class__ = kwrepo |