hgkw/keyword.py
branchself_initializing_hook
changeset 90 2e930f842242
parent 89 16f1a5ed70ce
child 92 3c7c187e4001
equal deleted inserted replaced
89:16f1a5ed70ce 90:2e930f842242
    11 files (like LaTeX packages), that are mostly addressed to an audience
    11 files (like LaTeX packages), that are mostly addressed to an audience
    12 not running a version control system.
    12 not running a version control system.
    13 
    13 
    14 Supported $keywords$ and their $keyword: substition $ are:
    14 Supported $keywords$ and their $keyword: substition $ are:
    15     Revision: changeset id
    15     Revision: changeset id
    16     Author:   full username
    16     Author:   short username
    17     Date:     %a %b %d %H:%M:%S %Y %z $
    17     Date:     %Y/%m/%d %H:%M:%S [UTC]
    18     RCSFile:  basename,v
    18     RCSFile:  basename,v
    19     Source:   /path/to/basename,v
    19     Source:   /path/to/basename,v
    20     Id:       basename,v csetid %Y-%m-%d %H:%M:%S %z shortname
    20     Id:       basename,v csetid %Y/%m/%d %H:%M:%S shortname
    21     Header:   /path/to/basename,v csetid %Y-%m-%d %H:%M:%S %z shortname
    21     Header:   /path/to/basename,v csetid %Y/%m/%d %H:%M:%S shortname
    22 
    22 
    23 Simple setup in hgrc:
    23 Simple setup in hgrc:
    24 
    24 
    25     # enable extension
    25     # enable extension
    26     hgext.keyword =
    26     hgext.keyword =
    32     **.py = expand
    32     **.py = expand
    33     ...
    33     ...
    34 '''
    34 '''
    35 
    35 
    36 from mercurial import context, util
    36 from mercurial import context, util
    37 import os.path, re, sys
    37 import os.path, re, sys, time
    38 
    38 
    39 
    39 
    40 re_kw = re.compile(
    40 re_kw = re.compile(
    41         r'\$(Id|Header|Author|Date|Revision|RCSFile|Source)[^$]*?\$')
    41         r'\$(Id|Header|Author|Date|Revision|RCSFile|Source)[^$]*?\$')
    42 
    42 
    46     Sets supported keywords as local variables and evaluates them to
    46     Sets supported keywords as local variables and evaluates them to
    47     their expansion if matchobj is equal to string representation.'''
    47     their expansion if matchobj is equal to string representation.'''
    48     c = context.filectx(repo, path,
    48     c = context.filectx(repo, path,
    49             changeid=changeid, fileid=fileid, filelog=filelog)
    49             changeid=changeid, fileid=fileid, filelog=filelog)
    50     def Revision():
    50     def Revision():
    51         return c.changectx()
    51         return str(c.changectx())
    52     def Author():
    52     def Author():
    53         return c.user()
    53         return util.shortuser(c.user())
    54     def Date():
    54     def Date():
    55         return util.datestr(date=c.date())
    55         return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(c.date()[0]))
    56     def RCSFile():
    56     def RCSFile():
    57         return os.path.basename(path)+',v'
    57         return os.path.basename(path)+',v'
    58     def Source():
    58     def Source():
    59         return repo.wjoin(path)+',v'
    59         return repo.wjoin(path)+',v'
    60     def revdateauth():
       
    61         return '%s %s %s' % (c.changectx(),
       
    62             util.datestr(date=c.date(), format=util.defaultdateformats[0]),
       
    63             util.shortuser(c.user()))
       
    64     def Header():
    60     def Header():
    65         return '%s %s' % (Source(), revdateauth())
    61         return ' '.join([Source(), Revision(), Date(), Author()])
    66     def Id():
    62     def Id():
    67         return '%s %s' % (RCSFile(), revdateauth())
    63         return ' '.join([RCSFile(), Revision(), Date(), Author()])
    68     return '$%s: %s $' % (matchobj.group(1), eval('%s()' % matchobj.group(1)))
    64     return '$%s: %s $' % (matchobj.group(1), eval('%s()' % matchobj.group(1)))
    69 
    65 
    70 def kwfmatches(ui, repo, files):
    66 def kwfmatches(ui, repo, files):
    71     '''Selects candidates for keyword substitution
    67     '''Selects candidates for keyword substitution
    72     configured in keyword section in hgrc.'''
    68     configured in keyword section in hgrc.'''