--- perforce.py_org	2005-11-21 08:35:42.000000000 -0800
+++ perforce.py	2005-11-21 09:48:02.000000000 -0800
@@ -49,24 +49,33 @@
     """
     Repository implementation for perforce
     """
+    p4c = p4.P4()
+    p4init = 0
 
     def __init__(self, name, authz, log, port, user, client, passwd, maxItems):
         Repository.__init__(self, name, authz, log)
-        self.p4c = p4.P4()
-        self.p4c.port = port
-        self.p4c.user = user
-        self.p4c.client = client
-        self.p4c.password = passwd
-        self.p4c.parse_forms()
+        if(self.__class__.p4init == 0):
+            self.__class__.p4init = 1
+            self.__class__.p4c = p4.P4()
+            self.__class__.p4c.port = port
+            self.__class__.p4c.user = user
+            self.__class__.p4c.client = client
+            self.__class__.p4c.password = passwd
+            self.__class__.p4c.parse_forms()
         try:
-            self.p4c.connect()
+                self.__class__.p4c.connect()
+            except self.__class__.p4c.P4Error:
+                for e in p4.errors:
+                    self.log.debug(e)
+                self.__class__.p4init = 0
             # cache the first few changes
+        try:
             self.history = []
-            changes = self.p4c.run("changes", "-m", maxItems, "-s", "submitted")
+            changes = self.__class__.p4c.run("changes", "-m", maxItems, "-s", "submitted")
             for change in changes:
                 self.history.append(change['change'])
 
-        except self.p4c.P4Error:
+        except self.__class__.p4c.P4Error:
             for e in p4.errors:
                 self.log.debug(e)
 
@@ -86,14 +95,14 @@
         change = { }
         try:
             if rev != None:
-                change = self.p4c.run_describe(rev)[0]
+                change = self.__class__.p4c.run_describe(rev)[0]
             else:
                 young = self.get_youngest_rev()
-                change = self.p4c.run_describe(young)[0]
-        except self.p4c.P4Error:
+                change = self.__class__.p4c.run_describe(young)[0]
+        except self.__class__.p4c.P4Error:
             for e in p4.errors:
                 self.log.debug(e)
-        return PerforceChangeset(self.p4c, rev, change, self.log)
+        return PerforceChangeset(self.__class__.p4c, rev, change, self.log)
 
 
     def has_node(self, path, rev):
@@ -123,9 +132,9 @@
 
             if path.endswith("...") == True:
                 path2 = path.rstrip('...')
-                dir = self.p4c.run("dirs", path2)
+                dir = self.__class__.p4c.run("dirs", path2)
             else:
-                dir = self.p4c.run("dirs", path)
+                dir = self.__class__.p4c.run("dirs", path)
 
             if len(dir) != 0:
                 kind = Node.DIRECTORY
@@ -133,7 +142,7 @@
                 kind = Node.FILE
         else:
             kind = Node.DIRECTORY
-        return PerforceNode(path, rev, self.p4c, self.log, kind)
+        return PerforceNode(path, rev, self.__class__.p4c, self.log, kind)
 
 
     def get_oldest_rev(self):
@@ -145,12 +154,12 @@
         """
         Return the youngest revision in the repository.
         """
-        rev = self.p4c.run("changes", "-m", "1", "-s", "submitted")[0]['change']
+        rev = self.__class__.p4c.run("changes", "-m", "1", "-s", "submitted")[0]['change']
         #self.log.debug("*** get_youngest_rev rev = %s" % (rev))
 
         if rev != self.history[0]:
             count = int(rev) - int(self.history[0])
-            changes = self.p4c.run("changes", "-m", count, "-s", "submitted")
+            changes = self.__class__.p4c.run("changes", "-m", count, "-s", "submitted")
             idx = 0
             for change in changes:
                 num = change['change']
@@ -212,7 +221,7 @@
             if path.startswith("//") == False:
                 path = path.rstrip('/')
                 path = '/' + path
-            dir = self.p4c.run("dirs", path)
+            dir = self.__class__.p4c.run("dirs", path)
             if len(dir) != 0:
                 kind = Node.DIRECTORY
             else:
@@ -391,7 +400,7 @@
     def get_content_length(self):
         if self.isdir:
             return None
-        type = self.p4c.run("fstat", "-Ol", self.path)
+        type = self.p4c.run("fstat", "-l", self.path)
         if type[0]['headAction'].startswith('delete') == True:
             return 0
         #self.log.debug("*** get_content_length = %s" % type)

