Test for binary updatehook
authorChristian Ebert <blacktrash@gmx.net>
Mon, 18 Dec 2006 01:42:06 +0100
branchupdatehook
changeset 30 bc3bdd329831
parent 29 bda83c13da42
child 31 28e8bd971c02
Test for binary
hgkw/kwexpander.py
--- a/hgkw/kwexpander.py	Sun Dec 17 15:32:34 2006 +0100
+++ b/hgkw/kwexpander.py	Mon Dec 18 01:42:06 2006 +0100
@@ -20,9 +20,7 @@
     def wwritekw(ui, repo, f, text):
         '''Writes text with kwupdates keywords to f in working directory.'''
         ui.note(_('expanding keywords in %s\n' % f))
-    #   # backup file in case of commit (?)
-    #   absfile = repo.wjoin(f)
-    #   util.copyfile(absfile, absfile+'.kwbak')
+        # backup file, at least when commiting (?)
         repo.wfile(f, 'w').write(text)
 
     # only check files that have hgkwencode assigned as encode filter
@@ -51,18 +49,20 @@
     for f in files:
 
         text = repo.wfile(f).read()
-        kw = '%sHg: %s,v %s %s %s $' % ('$', f, cid, date, user)
+        if not util.binary(text):
+
+            kw = '%sHg: %s,v %s %s %s $' % ('$', f, cid, date, user)
 
-        if update and text.find(kwstr) > -1:
-            text = text.replace(kwstr, kw)
-            wwritekw(ui, repo, f, text)
-            kwupdates.append(f)
-        
-        elif not update:
-            re_kw = re.compile(kwpat % f)
-            text, kwct = re_kw.subn(kw, text)
-            if kwct:
+            if update and text.find(kwstr) > -1:
+                text = text.replace(kwstr, kw)
                 wwritekw(ui, repo, f, text)
+                kwupdates.append(f)
+            
+            elif not update:
+                re_kw = re.compile(kwpat % f)
+                text, kwct = re_kw.subn(kw, text)
+                if kwct:
+                    wwritekw(ui, repo, f, text)
 
     if kwupdates:
         # cheat hg to believe that updated files were not modified