hgkw/kwexpander.py
branchupdatehook
changeset 30 bc3bdd329831
parent 29 bda83c13da42
child 31 28e8bd971c02
equal deleted inserted replaced
29:bda83c13da42 30:bc3bdd329831
    18     kwpat = r'[$]Hg(: %s,v [a-z0-9]{12} [^$]+? )?\$'
    18     kwpat = r'[$]Hg(: %s,v [a-z0-9]{12} [^$]+? )?\$'
    19 
    19 
    20     def wwritekw(ui, repo, f, text):
    20     def wwritekw(ui, repo, f, text):
    21         '''Writes text with kwupdates keywords to f in working directory.'''
    21         '''Writes text with kwupdates keywords to f in working directory.'''
    22         ui.note(_('expanding keywords in %s\n' % f))
    22         ui.note(_('expanding keywords in %s\n' % f))
    23     #   # backup file in case of commit (?)
    23         # backup file, at least when commiting (?)
    24     #   absfile = repo.wjoin(f)
       
    25     #   util.copyfile(absfile, absfile+'.kwbak')
       
    26         repo.wfile(f, 'w').write(text)
    24         repo.wfile(f, 'w').write(text)
    27 
    25 
    28     # only check files that have hgkwencode assigned as encode filter
    26     # only check files that have hgkwencode assigned as encode filter
    29     files = []
    27     files = []
    30     # python2.4: files = set()
    28     # python2.4: files = set()
    49     kwupdates = []
    47     kwupdates = []
    50 
    48 
    51     for f in files:
    49     for f in files:
    52 
    50 
    53         text = repo.wfile(f).read()
    51         text = repo.wfile(f).read()
    54         kw = '%sHg: %s,v %s %s %s $' % ('$', f, cid, date, user)
    52         if not util.binary(text):
    55 
    53 
    56         if update and text.find(kwstr) > -1:
    54             kw = '%sHg: %s,v %s %s %s $' % ('$', f, cid, date, user)
    57             text = text.replace(kwstr, kw)
    55 
    58             wwritekw(ui, repo, f, text)
    56             if update and text.find(kwstr) > -1:
    59             kwupdates.append(f)
    57                 text = text.replace(kwstr, kw)
    60         
       
    61         elif not update:
       
    62             re_kw = re.compile(kwpat % f)
       
    63             text, kwct = re_kw.subn(kw, text)
       
    64             if kwct:
       
    65                 wwritekw(ui, repo, f, text)
    58                 wwritekw(ui, repo, f, text)
       
    59                 kwupdates.append(f)
       
    60             
       
    61             elif not update:
       
    62                 re_kw = re.compile(kwpat % f)
       
    63                 text, kwct = re_kw.subn(kw, text)
       
    64                 if kwct:
       
    65                     wwritekw(ui, repo, f, text)
    66 
    66 
    67     if kwupdates:
    67     if kwupdates:
    68         # cheat hg to believe that updated files were not modified
    68         # cheat hg to believe that updated files were not modified
    69         repo.dirstate.update(kwupdates, 'n')
    69         repo.dirstate.update(kwupdates, 'n')