Edgewall Software

Ticket #257: perforce.patch

File perforce.patch, 4.4 KB (added by kenjin@…, 3 years ago)

Make p4 class attributes to address p4d process spawning.

  • perforce.

    old new  
    4949    """ 
    5050    Repository implementation for perforce 
    5151    """ 
     52    p4c = p4.P4() 
     53    p4init = 0 
    5254 
    5355    def __init__(self, name, authz, log, port, user, client, passwd, maxItems): 
    5456        Repository.__init__(self, name, authz, log) 
    55         self.p4c = p4.P4() 
    56         self.p4c.port = port 
    57         self.p4c.user = user 
    58         self.p4c.client = client 
    59         self.p4c.password = passwd 
    60         self.p4c.parse_forms() 
     57        if(self.__class__.p4init == 0): 
     58            self.__class__.p4init = 1 
     59            self.__class__.p4c = p4.P4() 
     60            self.__class__.p4c.port = port 
     61            self.__class__.p4c.user = user 
     62            self.__class__.p4c.client = client 
     63            self.__class__.p4c.password = passwd 
     64            self.__class__.p4c.parse_forms() 
    6165        try: 
    62             self.p4c.connect() 
     66                self.__class__.p4c.connect() 
     67            except self.__class__.p4c.P4Error: 
     68                for e in p4.errors: 
     69                    self.log.debug(e) 
     70                self.__class__.p4init = 0 
    6371            # cache the first few changes 
     72        try: 
    6473            self.history = [] 
    65             changes = self.p4c.run("changes", "-m", maxItems, "-s", "submitted") 
     74            changes = self.__class__.p4c.run("changes", "-m", maxItems, "-s", "submitted") 
    6675            for change in changes: 
    6776                self.history.append(change['change']) 
    6877 
    69         except self.p4c.P4Error: 
     78        except self.__class__.p4c.P4Error: 
    7079            for e in p4.errors: 
    7180                self.log.debug(e) 
    7281 
     
    8695        change = { } 
    8796        try: 
    8897            if rev != None: 
    89                 change = self.p4c.run_describe(rev)[0] 
     98                change = self.__class__.p4c.run_describe(rev)[0] 
    9099            else: 
    91100                young = self.get_youngest_rev() 
    92                 change = self.p4c.run_describe(young)[0] 
    93         except self.p4c.P4Error: 
     101                change = self.__class__.p4c.run_describe(young)[0] 
     102        except self.__class__.p4c.P4Error: 
    94103            for e in p4.errors: 
    95104                self.log.debug(e) 
    96         return PerforceChangeset(self.p4c, rev, change, self.log) 
     105        return PerforceChangeset(self.__class__.p4c, rev, change, self.log) 
    97106 
    98107 
    99108    def has_node(self, path, rev): 
     
    123132 
    124133            if path.endswith("...") == True: 
    125134                path2 = path.rstrip('...') 
    126                 dir = self.p4c.run("dirs", path2) 
     135                dir = self.__class__.p4c.run("dirs", path2) 
    127136            else: 
    128                 dir = self.p4c.run("dirs", path) 
     137                dir = self.__class__.p4c.run("dirs", path) 
    129138 
    130139            if len(dir) != 0: 
    131140                kind = Node.DIRECTORY 
     
    133142                kind = Node.FILE 
    134143        else: 
    135144            kind = Node.DIRECTORY 
    136         return PerforceNode(path, rev, self.p4c, self.log, kind) 
     145        return PerforceNode(path, rev, self.__class__.p4c, self.log, kind) 
    137146 
    138147 
    139148    def get_oldest_rev(self): 
     
    145154        """ 
    146155        Return the youngest revision in the repository. 
    147156        """ 
    148         rev = self.p4c.run("changes", "-m", "1", "-s", "submitted")[0]['change'] 
     157        rev = self.__class__.p4c.run("changes", "-m", "1", "-s", "submitted")[0]['change'] 
    149158        #self.log.debug("*** get_youngest_rev rev = %s" % (rev)) 
    150159 
    151160        if rev != self.history[0]: 
    152161            count = int(rev) - int(self.history[0]) 
    153             changes = self.p4c.run("changes", "-m", count, "-s", "submitted") 
     162            changes = self.__class__.p4c.run("changes", "-m", count, "-s", "submitted") 
    154163            idx = 0 
    155164            for change in changes: 
    156165                num = change['change'] 
     
    212221            if path.startswith("//") == False: 
    213222                path = path.rstrip('/') 
    214223                path = '/' + path 
    215             dir = self.p4c.run("dirs", path) 
     224            dir = self.__class__.p4c.run("dirs", path) 
    216225            if len(dir) != 0: 
    217226                kind = Node.DIRECTORY 
    218227            else: 
     
    391400    def get_content_length(self): 
    392401        if self.isdir: 
    393402            return None 
    394         type = self.p4c.run("fstat", "-Ol", self.path) 
     403        type = self.p4c.run("fstat", "-l", self.path) 
    395404        if type[0]['headAction'].startswith('delete') == True: 
    396405            return 0 
    397406        #self.log.debug("*** get_content_length = %s" % type)