@matheusbsbs / matheus-bagliano / commits / 354081d5a0
Fork 0

git-p4: support exclude paths

Teach git-p4 about the -/ option which adds depot paths to the exclude list, used when cloning. The option is chosen such that the natural Perforce syntax works, eg: git p4 clone //branch/path/... -//branch/path/{large,old}/... Trailing ... on exclude paths are optional. This is a generalization of a change by Dmitry Kakurin (thanks). Signed-off-by: Tommy Thorn <tommy-git@thorn.ws> Signed-off-by: Simon Hausmann <simon@lst.de>

Tommy Thorn committed Feb 3, 2008 at 10:38 UTC 354081d5a0392a015731a637f026dc885a4ddb0f
1 file changed +22 -4
contrib/fast-import/git-p4
+22 -4
@@ -843,18 +843,25 @@ class P4Sync(Command):
843 self.keepRepoPath = False
844 self.depotPaths = None
845 self.p4BranchesInGit = []
846 + self.cloneExclude = []
847
848 if gitConfig("git-p4.syncFromOrigin") == "false":
849 self.syncWithOrigin = False
850
851 def extractFilesFromCommit(self, commit):
852 + self.cloneExclude = [re.sub(r"\.\.\.$", "", path)
853 + for path in self.cloneExclude]
854 files = []
855 fnum = 0
856 while commit.has_key("depotFile%s" % fnum):
857 path = commit["depotFile%s" % fnum]
858
856 - found = [p for p in self.depotPaths
857 - if path.startswith (p)]
859 + if [p for p in self.cloneExclude
860 + if path.startswith (p)]:
861 + found = False
862 + else:
863 + found = [p for p in self.depotPaths
864 + if path.startswith (p)]
865 if not found:
866 fnum = fnum + 1
867 continue
@@ -1634,13 +1641,23 @@ class P4Clone(P4Sync):
1641 P4Sync.__init__(self)
1642 self.description = "Creates a new git repository and imports from Perforce into it"
1643 self.usage = "usage: %prog [options] //depot/path[@revRange]"
1637 - self.options.append(
1644 + self.options += [
1645 optparse.make_option("--destination", dest="cloneDestination",
1646 action='store', default=None,
1640 - help="where to leave result of the clone"))
1647 + help="where to leave result of the clone"),
1648 + optparse.make_option("-/", dest="cloneExclude",
1649 + action="append", type="string",
1650 + help="exclude depot path")
1651 + ]
1652 self.cloneDestination = None
1653 self.needsGit = False
1654
1655 + # This is required for the "append" cloneExclude action
1656 + def ensure_value(self, attr, value):
1657 + if not hasattr(self, attr) or getattr(self, attr) is None:
1658 + setattr(self, attr, value)
1659 + return getattr(self, attr)
1660 +
1661 def defaultDestination(self, args):
1662 ## TODO: use common prefix of args?
1663 depotPath = args[0]
@@ -1664,6 +1681,7 @@ class P4Clone(P4Sync):
1681 self.cloneDestination = depotPaths[-1]
1682 depotPaths = depotPaths[:-1]
1683
1684 + self.cloneExclude = ["/"+p for p in self.cloneExclude]
1685 for p in depotPaths:
1686 if not p.startswith("//"):
1687 return False