@matheusbsbs / matheus-bagliano / commits / b607e71efd
Fork 0

Cache the output of "p4 users" for faster syncs on high latency links.

Signed-off-by: Simon Hausmann <simon@lst.de>

Simon Hausmann committed May 20, 2007 at 10:55 UTC b607e71efdd23cd676645b5d7bf49d985834fab8
1 file changed +21 -2
contrib/fast-import/git-p4
+21 -2
@@ -501,6 +501,8 @@ class P4Sync(Command):
501 # gitStream.write("mark :%s\n" % details["change"])
502 self.committedChanges.add(int(details["change"]))
503 committer = ""
504 + if author not in self.users:
505 + self.getUserMapFromPerforceServer()
506 if author in self.users:
507 committer = "%s %s %s" % (self.users[author], epoch, self.tz)
508 else:
@@ -591,7 +593,7 @@ class P4Sync(Command):
593 if not self.silent:
594 print "Tag %s does not match with change %s: file count is different." % (labelDetails["label"], change)
595
594 - def getUserMap(self):
596 + def getUserMapFromPerforceServer(self):
597 self.users = {}
598
599 for output in p4CmdList("users"):
@@ -599,6 +601,23 @@ class P4Sync(Command):
601 continue
602 self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
603
604 + cache = open(gitdir + "/p4-usercache.txt", "wb")
605 + for user in self.users.keys():
606 + cache.write("%s\t%s\n" % (user, self.users[user]))
607 + cache.close();
608 +
609 + def loadUserMapFromCache(self):
610 + self.users = {}
611 + try:
612 + cache = open(gitdir + "/p4-usercache.txt", "rb")
613 + lines = cache.readlines()
614 + cache.close()
615 + for line in lines:
616 + entry = line[:-1].split("\t")
617 + self.users[entry[0]] = entry[1]
618 + except IOError:
619 + self.getUserMapFromPerforceServer()
620 +
621 def getLabels(self):
622 self.labels = {}
623
@@ -772,7 +791,7 @@ class P4Sync(Command):
791 if not self.depotPath.endswith("/"):
792 self.depotPath += "/"
793
775 - self.getUserMap()
794 + self.loadUserMapFromCache()
795 self.labels = {}
796 if self.detectLabels:
797 self.getLabels();