hgext/keyword.py
changeset 7993 b83a11536fc6
parent 7853 af062a9fea9b
child 8027 9c7ca86fc658
equal deleted inserted replaced
7992:0e7f02eaa63b 7993:b83a11536fc6
     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.
    32 #
    32 #
    33 # Run "hg help keyword" and "hg kwdemo" to get info on configuration.
    33 # Run "hg help keyword" and "hg kwdemo" to get info on configuration.
    34 
    34 
    35 '''keyword expansion in local repositories
    35 '''keyword expansion in local repositories
    36 
    36 
    37 This extension expands RCS/CVS-like or self-customized $Keywords$
    37 This extension expands RCS/CVS-like or self-customized $Keywords$ in
    38 in tracked text files selected by your configuration.
    38 tracked text files selected by your configuration.
    39 
    39 
    40 Keywords are only expanded in local repositories and not stored in
    40 Keywords are only expanded in local repositories and not stored in the
    41 the change history. The mechanism can be regarded as a convenience
    41 change history. The mechanism can be regarded as a convenience for the
    42 for the current user or for archive distribution.
    42 current user or for archive distribution.
    43 
    43 
    44 Configuration is done in the [keyword] and [keywordmaps] sections
    44 Configuration is done in the [keyword] and [keywordmaps] sections of
    45 of hgrc files.
    45 hgrc files.
    46 
    46 
    47 Example:
    47 Example:
    48 
    48 
    49     [keyword]
    49     [keyword]
    50     # expand keywords in every python file except those matching "x*"
    50     # expand keywords in every python file except those matching "x*"
    57 For [keywordmaps] template mapping and expansion demonstration and
    57 For [keywordmaps] template mapping and expansion demonstration and
    58 control run "hg kwdemo".
    58 control run "hg kwdemo".
    59 
    59 
    60 An additional date template filter {date|utcdate} is provided.
    60 An additional date template filter {date|utcdate} is provided.
    61 
    61 
    62 The default template mappings (view with "hg kwdemo -d") can be replaced
    62 The default template mappings (view with "hg kwdemo -d") can be
    63 with customized keywords and templates.
    63 replaced with customized keywords and templates. Again, run "hg
    64 Again, run "hg kwdemo" to control the results of your config changes.
    64 kwdemo" to control the results of your config changes.
    65 
    65 
    66 Before changing/disabling active keywords, run "hg kwshrink" to avoid
    66 Before changing/disabling active keywords, run "hg kwshrink" to avoid
    67 the risk of inadvertedly storing expanded keywords in the change history.
    67 the risk of inadvertedly storing expanded keywords in the change
       
    68 history.
    68 
    69 
    69 To force expansion after enabling it, or a configuration change, run
    70 To force expansion after enabling it, or a configuration change, run
    70 "hg kwexpand".
    71 "hg kwexpand".
    71 
    72 
    72 Also, when committing with the record extension or using mq's qrecord, be aware
    73 Also, when committing with the record extension or using mq's qrecord,
    73 that keywords cannot be updated. Again, run "hg kwexpand" on the files in
    74 be aware that keywords cannot be updated. Again, run "hg kwexpand" on
    74 question to update keyword expansions after all changes have been checked in.
    75 the files in question to update keyword expansions after all changes
       
    76 have been checked in.
    75 
    77 
    76 Expansions spanning more than one line and incremental expansions,
    78 Expansions spanning more than one line and incremental expansions,
    77 like CVS' $Log$, are not supported. A keyword template map
    79 like CVS' $Log$, are not supported. A keyword template map
    78 "Log = {desc}" expands to the first line of the changeset description.
    80 "Log = {desc}" expands to the first line of the changeset description.
    79 '''
    81 '''
   274 
   276 
   275 
   277 
   276 def demo(ui, repo, *args, **opts):
   278 def demo(ui, repo, *args, **opts):
   277     '''print [keywordmaps] configuration and an expansion example
   279     '''print [keywordmaps] configuration and an expansion example
   278 
   280 
   279     Show current, custom, or default keyword template maps
   281     Show current, custom, or default keyword template maps and their
   280     and their expansion.
   282     expansion.
   281 
   283 
   282     Extend current configuration by specifying maps as arguments
   284     Extend current configuration by specifying maps as arguments and
   283     and optionally by reading from an additional hgrc file.
   285     optionally by reading from an additional hgrc file.
   284 
   286 
   285     Override current keyword template maps with "default" option.
   287     Override current keyword template maps with "default" option.
   286     '''
   288     '''
   287     def demostatus(stat):
   289     def demostatus(stat):
   288         ui.status(_('\n\t%s\n') % stat)
   290         ui.status(_('\n\t%s\n') % stat)
   365     _kwfwrite(ui, repo, True, *pats, **opts)
   367     _kwfwrite(ui, repo, True, *pats, **opts)
   366 
   368 
   367 def files(ui, repo, *pats, **opts):
   369 def files(ui, repo, *pats, **opts):
   368     '''print files currently configured for keyword expansion
   370     '''print files currently configured for keyword expansion
   369 
   371 
   370     Crosscheck which files in working directory are potential targets for
   372     Crosscheck which files in working directory are potential targets
   371     keyword expansion.
   373     for keyword expansion. That is, files matched by [keyword] config
   372     That is, files matched by [keyword] config patterns but not symlinks.
   374     patterns but not symlinks.
   373     '''
   375     '''
   374     kwt = kwtools['templater']
   376     kwt = kwtools['templater']
   375     status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts)
   377     status = _status(ui, repo, kwt, opts.get('untracked'), *pats, **opts)
   376     modified, added, removed, deleted, unknown, ignored, clean = status
   378     modified, added, removed, deleted, unknown, ignored, clean = status
   377     files = util.sort(modified + added + clean + unknown)
   379     files = util.sort(modified + added + clean + unknown)
   387             ui.write(fmt % repo.pathto(f, cwd))
   389             ui.write(fmt % repo.pathto(f, cwd))
   388 
   390 
   389 def shrink(ui, repo, *pats, **opts):
   391 def shrink(ui, repo, *pats, **opts):
   390     '''revert expanded keywords in working directory
   392     '''revert expanded keywords in working directory
   391 
   393 
   392     Run before changing/disabling active keywords
   394     Run before changing/disabling active keywords or if you experience
   393     or if you experience problems with "hg import" or "hg merge".
   395     problems with "hg import" or "hg merge".
   394 
   396 
   395     kwshrink refuses to run if given files contain local changes.
   397     kwshrink refuses to run if given files contain local changes.
   396     '''
   398     '''
   397     # 3rd argument sets expansion to False
   399     # 3rd argument sets expansion to False
   398     _kwfwrite(ui, repo, False, *pats, **opts)
   400     _kwfwrite(ui, repo, False, *pats, **opts)