* [PATCH v2 1/3] git-p4: Correct branch base depot path detection
2011-02-26 23:46 [PATCH v2 0/3] git-p4: Improve branch support Vitor Antunes
@ 2011-02-26 23:46 ` Vitor Antunes
2011-02-26 23:46 ` [PATCH v2 2/3] git-p4: Allow filtering Perforce branches by user Vitor Antunes
2011-02-26 23:46 ` [PATCH v2 3/3] git-p4: Allow branch definition with git config Vitor Antunes
2 siblings, 0 replies; 4+ messages in thread
From: Vitor Antunes @ 2011-02-26 23:46 UTC (permalink / raw)
To: git; +Cc: Pete Wyckoff, Tor Arvid Lund, Vitor Antunes
When branch detection is enabled each branch is named in git after their
relative depot path in Perforce. To do this the depot paths are compared against
each other to find their common base path. The current algorithm makes this
comparison on a character by character basis.
Assuming we have the following branches:
//depot/branches/featureA
//depot/branches/featureB
Then the base depot path would be //depot/branches/feature, which is an invalid
depot path.
The current patch fixes this by splitting the path into a list and comparing the
list entries, making it choose correctly //depot/branches as the base path.
Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
contrib/fast-import/git-p4 | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index a92beb6..fad3371 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1599,12 +1599,14 @@ class P4Sync(Command):
else:
paths = []
for (prev, cur) in zip(self.previousDepotPaths, depotPaths):
- for i in range(0, min(len(cur), len(prev))):
- if cur[i] <> prev[i]:
+ prev_list = prev.split("/")
+ cur_list = cur.split("/")
+ for i in range(0, min(len(cur_list), len(prev_list))):
+ if cur_list[i] <> prev_list[i]:
i = i - 1
break
- paths.append (cur[:i + 1])
+ paths.append ("/".join(cur_list[:i + 1]))
self.previousDepotPaths = paths
--
1.7.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] git-p4: Allow filtering Perforce branches by user
2011-02-26 23:46 [PATCH v2 0/3] git-p4: Improve branch support Vitor Antunes
2011-02-26 23:46 ` [PATCH v2 1/3] git-p4: Correct branch base depot path detection Vitor Antunes
@ 2011-02-26 23:46 ` Vitor Antunes
2011-02-26 23:46 ` [PATCH v2 3/3] git-p4: Allow branch definition with git config Vitor Antunes
2 siblings, 0 replies; 4+ messages in thread
From: Vitor Antunes @ 2011-02-26 23:46 UTC (permalink / raw)
To: git; +Cc: Pete Wyckoff, Tor Arvid Lund, Vitor Antunes
All branches in the Perforce server are downloaded to allow branch detection. If
you have a centralized server on a remote location and there is a big number of
branches this operation can take some time.
This patch adds the configuration option git-p4.branchUser to allow filtering
the branch list by user. Although this limits the branch maintenance in Perforce
to be done by a single user, it might be an advantage when the number of
branches being used in a specific depot is very small when compared with the
branches available in the server.
Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
contrib/fast-import/git-p4 | 8 +++++++-
contrib/fast-import/git-p4.txt | 6 ++++++
2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index fad3371..646afc1 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1245,7 +1245,13 @@ class P4Sync(Command):
def getBranchMapping(self):
lostAndFoundBranches = set()
- for info in p4CmdList("branches"):
+ user = gitConfig("git-p4.branchUser")
+ if len(user) > 0:
+ command = "branches -u %s" % user
+ else:
+ command = "branches"
+
+ for info in p4CmdList(command):
details = p4Cmd("branch -o %s" % info["branch"])
viewIdx = 0
while details.has_key("View%s" % viewIdx):
diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
index e09da44..5b85081 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -196,6 +196,12 @@ able to find the relevant client. This client spec will be used to
both filter the files cloned by git and set the directory layout as
specified in the client (this implies --keep-path style semantics).
+git-p4.branchUser
+
+Only use branch specifications defined by the selected username.
+
+ git config [--global] git-p4.branchUser username
+
Implementation Details...
=========================
--
1.7.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] git-p4: Allow branch definition with git config
2011-02-26 23:46 [PATCH v2 0/3] git-p4: Improve branch support Vitor Antunes
2011-02-26 23:46 ` [PATCH v2 1/3] git-p4: Correct branch base depot path detection Vitor Antunes
2011-02-26 23:46 ` [PATCH v2 2/3] git-p4: Allow filtering Perforce branches by user Vitor Antunes
@ 2011-02-26 23:46 ` Vitor Antunes
2 siblings, 0 replies; 4+ messages in thread
From: Vitor Antunes @ 2011-02-26 23:46 UTC (permalink / raw)
To: git; +Cc: Pete Wyckoff, Tor Arvid Lund, Vitor Antunes
Perforce does not strictly require the usage of branch specifications to create
branches. In these cases the branch detection code of git-p4 will not be able to
import them.
This patch adds support for git-p4.branchList configuration option, allowing
branches to be defined in git config.
Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
---
contrib/fast-import/git-p4 | 24 ++++++++++++++++++++++++
contrib/fast-import/git-p4.txt | 7 +++++++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 646afc1..3ad9600 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -338,6 +338,11 @@ def gitConfig(key):
_gitConfig[key] = read_pipe("git config %s" % key, ignore_error=True).strip()
return _gitConfig[key]
+def gitConfigList(key):
+ if not _gitConfig.has_key(key):
+ _gitConfig[key] = read_pipe("git config --get-all %s" % key, ignore_error=True).strip().split(os.linesep)
+ return _gitConfig[key]
+
def p4BranchesInGit(branchesAreInRemotes = True):
branches = {}
@@ -1280,6 +1285,25 @@ class P4Sync(Command):
if source not in self.knownBranches:
lostAndFoundBranches.add(source)
+ # Perforce does not strictly require branches to be defined, so we also
+ # check git config for a branch list.
+ #
+ # Example of branch definition in git config file:
+ # [git-p4]
+ # branchList=main:branchA
+ # branchList=main:branchB
+ # branchList=branchA:branchC
+ configBranches = gitConfigList("git-p4.branchList")
+ for branch in configBranches:
+ if branch:
+ (source, destination) = branch.split(":")
+ self.knownBranches[destination] = source
+
+ lostAndFoundBranches.discard(destination)
+
+ if source not in self.knownBranches:
+ lostAndFoundBranches.add(source)
+
for branch in lostAndFoundBranches:
self.knownBranches[branch] = branch
diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
index 5b85081..3cc2309 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -202,6 +202,13 @@ Only use branch specifications defined by the selected username.
git config [--global] git-p4.branchUser username
+git-p4.branchList
+
+List of branches to be imported when branch detection is enabled.
+
+ git config [--global] git-p4.branchList main:branchA
+ git config [--global] --add git-p4.branchList main:branchB
+
Implementation Details...
=========================
--
1.7.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread