try for dirstate.update instead of hasattr
authorChristian Ebert <blacktrash@gmx.net>
Fri, 27 Jul 2007 10:34:48 +0200
changeset 217 e55e3f6c6608
parent 216 f35a0c382168
child 218 d7ddb4e378f3
try for dirstate.update instead of hasattr
hgkw/keyword.py
--- a/hgkw/keyword.py	Thu Jul 26 18:24:35 2007 +0200
+++ b/hgkw/keyword.py	Fri Jul 27 10:34:48 2007 +0200
@@ -186,9 +186,7 @@
         expand = self.t is not None
         action = ('shrinking', 'expanding')[expand]
         notify = (self.ui.note, self.ui.debug)[commit]
-        # backwards compatibility: older versions have dirstate.update
-        nodirstateupdate = not hasattr(self.repo.dirstate, 'update')
-        files = []
+        overwritten = []
         for f in candidates:
             fp = self.repo.file(f, kwexp=expand, kwcnt=True)
             data, kwfound = fp.read(man[f])
@@ -199,12 +197,14 @@
                 except AttributeError:
                     # older versions want file descriptor as 3. optional arg
                     self.repo.wwrite(f, data)
-                if nodirstateupdate:
+                overwritten.append(f)
+        if overwritten:
+            try:
+                for f in overwritten:
                     self.repo.dirstate.normal(f)
-                else:
-                    files.append(f)
-        if files:
-            self.repo.dirstate.update(files, 'n')
+            except AttributeError:
+                # older versions don't know about dirstate.normal
+                self.repo.dirstate.update(overwritten, 'n')
 
 class kwfilelog(filelog.filelog):
     '''