hgkw/pretxnkw.py
branchdecodefilter
changeset 13 d6c0f391a662
parent 11 56a61a5c696d
equal deleted inserted replaced
12:d9c4fc735963 13:d6c0f391a662
    32     re_kw = kwutil.rekw()
    32     re_kw = kwutil.rekw()
    33     kword = kwutil.mkkw(repo, tip=True, node=node)
    33     kword = kwutil.mkkw(repo, tip=True, node=node)
    34 
    34 
    35     re_kwcheck = re.compile(r'[$]Hg: (.*?),v.*?\$')
    35     re_kwcheck = re.compile(r'[$]Hg: (.*?),v.*?\$')
    36 
    36 
    37     for filename in files:
    37     for f in files:
    38 
    38 
    39         data = repo.wfile(filename).read()
    39         data = repo.wfile(f).read()
    40 
    40 
    41         # check for keywords with incorrect filename
    41         # check for keywords with incorrect filename
    42         # eg. if you forgot to update filename manually after "hg mv"
    42         # eg. if you forgot to update filename manually after "hg mv"
    43         invalids = [m for m in map(str, re_kwcheck.findall(data))
    43         invalids = [m for m in map(str, re_kwcheck.findall(data))
    44                 if m != filename]
    44                 if m != f]
    45         if invalids:
    45         if invalids:
    46             invalids = ['%sHg: %s,v$' % ('$', i) for i in invalids]
    46             invalids = ['%sHg: %s,v$' % ('$', i) for i in invalids]
    47             ui.warn(_('%d invalid keyword filenames in file %s:\n'
    47             ui.warn(_('%d invalid keyword filenames in file %s:\n'
    48                 '%s\nplease correct to %sHg: %s,v$\n'
    48                 '%s\nplease correct to %sHg: %s,v$\n'
    49                 % (len(invalids), filename, ', '.join(invalids), '$', filename)
    49                 % (len(invalids), f, ', '.join(invalids), '$', f)))
    50                 ))
       
    51             return True
    50             return True
    52 
    51 
    53         # substitute <Dollar>(Hg|Id): <basename>,v.*<Dollar>
    52         # substitute <Dollar>(Hg|Id): <basename>,v.*<Dollar>
    54         data, kwct = re_kw.subn(kword, data)
    53         data, kwct = re_kw.subn(kword, data)
    55 
    54 
    56         if kwct:
    55         if kwct:
    57             # backup file and write with expanded keyword
    56             # backup file and write with expanded keyword
    58             ui.note(_('expanding keywords in %s\n' % filename))
    57             ui.note(_('expanding keywords in %s\n' % f))
    59             absname = repo.wjoin(filename)
    58             absname = repo.wjoin(f)
    60             util.copyfile(absname, absname+'~')
    59             util.copyfile(absname, absname+'~')
    61             repo.wfile(filename, 'w').write(data)
    60             repo.wfile(f, 'w').write(data)
    62 
    61 
    63     return False
    62     return False