hgkw/keyword.py
branchstable
changeset 527 59cb740ebf83
parent 525 6028e8046c14
child 529 7197324dfa4d
equal deleted inserted replaced
525:6028e8046c14 527:59cb740ebf83
     9 #
     9 #
    10 # Keyword expansion hack against the grain of a DSCM
    10 # Keyword expansion hack against the grain of a DSCM
    11 #
    11 #
    12 # There are many good reasons why this is not needed in a distributed
    12 # There are many good reasons why this is not needed in a distributed
    13 # SCM, still it may be useful in very small projects based on single
    13 # SCM, still it may be useful in very small projects based on single
    14 # files (like LaTeX packages), that are mostly addressed to an audience
    14 # files (like LaTeX packages), that are mostly addressed to an
    15 # not running a version control system.
    15 # audience not running a version control system.
    16 #
    16 #
    17 # For in-depth discussion refer to
    17 # For in-depth discussion refer to
    18 # <http://www.selenic.com/mercurial/wiki/index.cgi/KeywordPlan>.
    18 # <http://www.selenic.com/mercurial/wiki/index.cgi/KeywordPlan>.
    19 #
    19 #
    20 # Keyword expansion is based on Mercurial's changeset template mappings.
    20 # Keyword expansion is based on Mercurial's changeset template mappings.
    34 #
    34 #
    35 # Run "hg help keyword" and "hg kwdemo" to get info on configuration.
    35 # Run "hg help keyword" and "hg kwdemo" to get info on configuration.
    36 
    36 
    37 '''keyword expansion in local repositories
    37 '''keyword expansion in local repositories
    38 
    38 
    39 This extension expands RCS/CVS-like or self-customized $Keywords$
    39 This extension expands RCS/CVS-like or self-customized $Keywords$ in
    40 in tracked text files selected by your configuration.
    40 tracked text files selected by your configuration.
    41 
    41 
    42 Keywords are only expanded in local repositories and not stored in
    42 Keywords are only expanded in local repositories and not stored in the
    43 the change history. The mechanism can be regarded as a convenience
    43 change history. The mechanism can be regarded as a convenience for the
    44 for the current user or for archive distribution.
    44 current user or for archive distribution.
    45 
    45 
    46 Configuration is done in the [keyword] and [keywordmaps] sections
    46 Configuration is done in the [keyword] and [keywordmaps] sections of
    47 of hgrc files.
    47 hgrc files.
    48 
    48 
    49 Example:
    49 Example:
    50 
    50 
    51     [keyword]
    51     [keyword]
    52     # expand keywords in every python file except those matching "x*"
    52     # expand keywords in every python file except those matching "x*"
    59 For [keywordmaps] template mapping and expansion demonstration and
    59 For [keywordmaps] template mapping and expansion demonstration and
    60 control run "hg kwdemo".
    60 control run "hg kwdemo".
    61 
    61 
    62 An additional date template filter {date|utcdate} is provided.
    62 An additional date template filter {date|utcdate} is provided.
    63 
    63 
    64 The default template mappings (view with "hg kwdemo -d") can be replaced
    64 The default template mappings (view with "hg kwdemo -d") can be
    65 with customized keywords and templates.
    65 replaced with customized keywords and templates. Again, run "hg
    66 Again, run "hg kwdemo" to control the results of your config changes.
    66 kwdemo" to control the results of your config changes.
    67 
    67 
    68 Before changing/disabling active keywords, run "hg kwshrink" to avoid
    68 Before changing/disabling active keywords, run "hg kwshrink" to avoid
    69 the risk of inadvertedly storing expanded keywords in the change history.
    69 the risk of inadvertedly storing expanded keywords in the change
       
    70 history.
    70 
    71 
    71 To force expansion after enabling it, or a configuration change, run
    72 To force expansion after enabling it, or a configuration change, run
    72 "hg kwexpand".
    73 "hg kwexpand".
    73 
    74 
    74 Also, when committing with the record extension or using mq's qrecord, be aware
    75 Also, when committing with the record extension or using mq's qrecord,
    75 that keywords cannot be updated. Again, run "hg kwexpand" on the files in
    76 be aware that keywords cannot be updated. Again, run "hg kwexpand" on
    76 question to update keyword expansions after all changes have been checked in.
    77 the files in question to update keyword expansions after all changes
       
    78 have been checked in.
    77 
    79 
    78 Expansions spanning more than one line and incremental expansions,
    80 Expansions spanning more than one line and incremental expansions,
    79 like CVS' $Log$, are not supported. A keyword template map
    81 like CVS' $Log$, are not supported. A keyword template map
    80 "Log = {desc}" expands to the first line of the changeset description.
    82 "Log = {desc}" expands to the first line of the changeset description.
    81 '''
    83 '''
   276 
   278 
   277 
   279 
   278 def demo(ui, repo, *args, **opts):
   280 def demo(ui, repo, *args, **opts):
   279     '''print [keywordmaps] configuration and an expansion example
   281     '''print [keywordmaps] configuration and an expansion example
   280 
   282 
   281     Show current, custom, or default keyword template maps
   283     Show current, custom, or default keyword template maps and their
   282     and their expansion.
   284     expansion.
   283 
   285 
   284     Extend current configuration by specifying maps as arguments
   286     Extend current configuration by specifying maps as arguments and
   285     and optionally by reading from an additional hgrc file.
   287     optionally by reading from an additional hgrc file.
   286 
   288 
   287     Override current keyword template maps with "default" option.
   289     Override current keyword template maps with "default" option.
   288     '''
   290     '''
   289     def demostatus(stat):
   291     def demostatus(stat):
   290         ui.status(_('\n\t%s\n') % stat)
   292         ui.status(_('\n\t%s\n') % stat)
   367     _kwfwrite(ui, repo, True, *pats, **opts)
   369     _kwfwrite(ui, repo, True, *pats, **opts)
   368 
   370 
   369 def files(ui, repo, *pats, **opts):
   371 def files(ui, repo, *pats, **opts):
   370     '''print files currently configured for keyword expansion
   372     '''print files currently configured for keyword expansion
   371 
   373 
   372     Crosscheck which files in working directory are potential targets for
   374     Crosscheck which files in working directory are potential targets
   373     keyword expansion.
   375     for keyword expansion. That is, files matched by [keyword] config
   374     That is, files matched by [keyword] config patterns but not symlinks.
   376     patterns but not symlinks.
   375     '''
   377     '''
   376     kwt = kwtools['templater']
   378     kwt = kwtools['templater']
   377     status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts)
   379     status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts)
   378     modified, added, removed, deleted, unknown, ignored, clean = status
   380     modified, added, removed, deleted, unknown, ignored, clean = status
   379     files = util.sort(modified + added + clean + unknown)
   381     files = util.sort(modified + added + clean + unknown)
   389             ui.write(fmt % repo.pathto(f, cwd))
   391             ui.write(fmt % repo.pathto(f, cwd))
   390 
   392 
   391 def shrink(ui, repo, *pats, **opts):
   393 def shrink(ui, repo, *pats, **opts):
   392     '''revert expanded keywords in working directory
   394     '''revert expanded keywords in working directory
   393 
   395 
   394     Run before changing/disabling active keywords
   396     Run before changing/disabling active keywords or if you experience
   395     or if you experience problems with "hg import" or "hg merge".
   397     problems with "hg import" or "hg merge".
   396 
   398 
   397     kwshrink refuses to run if given files contain local changes.
   399     kwshrink refuses to run if given files contain local changes.
   398     '''
   400     '''
   399     # 3rd argument sets expansion to False
   401     # 3rd argument sets expansion to False
   400     _kwfwrite(ui, repo, False, *pats, **opts)
   402     _kwfwrite(ui, repo, False, *pats, **opts)