All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/4] git-p4: Improve branch support
@ 2011-08-28 21:58 Vitor Antunes
  2011-08-28 21:58 ` [PATCH v4 1/4] git-p4: Correct branch base depot path detection Vitor Antunes
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Vitor Antunes @ 2011-08-28 21:58 UTC (permalink / raw)
  To: git; +Cc: Pete Wyckoff, Tor Arvid Lund, Vitor Antunes

Include test case patches from Pete Wyckoff.

Vitor Antunes (4):
  git-p4: Correct branch base depot path detection
  git-p4: Allow filtering Perforce branches by user
  git-p4: Allow branch definition with git config
  git-p4: Add simple test case for branch import

 contrib/fast-import/git-p4     |   40 +++++++++++++++++++++++--
 contrib/fast-import/git-p4.txt |   13 ++++++++
 t/t9800-git-p4.sh              |   61 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 4 deletions(-)

-- 
1.7.5.4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4 1/4] git-p4: Correct branch base depot path detection
  2011-08-28 21:58 [PATCH v4 0/4] git-p4: Improve branch support Vitor Antunes
@ 2011-08-28 21:58 ` Vitor Antunes
  2011-08-28 21:58 ` [PATCH v4 2/4] git-p4: Allow filtering Perforce branches by user Vitor Antunes
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Vitor Antunes @ 2011-08-28 21:58 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 0db3e72..72a5b6c 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1829,12 +1829,14 @@ class P4Sync(Command, P4UserMap):
                     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.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 2/4] git-p4: Allow filtering Perforce branches by user
  2011-08-28 21:58 [PATCH v4 0/4] git-p4: Improve branch support Vitor Antunes
  2011-08-28 21:58 ` [PATCH v4 1/4] git-p4: Correct branch base depot path detection Vitor Antunes
@ 2011-08-28 21:58 ` Vitor Antunes
  2011-08-28 21:58 ` [PATCH v4 3/4] git-p4: Allow branch definition with git config Vitor Antunes
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Vitor Antunes @ 2011-08-28 21:58 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 72a5b6c..6314c20 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -1455,7 +1455,13 @@ class P4Sync(Command, P4UserMap):
     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 2ffbccc..97b66b9 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -257,6 +257,12 @@ Perforce server. Will enable --find-copies-harder git argument.
 
   git config [--global] git-p4.detectCopies true
 
+git-p4.branchUser
+
+Only use branch specifications defined by the selected username.
+
+  git config [--global] git-p4.branchUser username
+
 Implementation Details...
 =========================
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 3/4] git-p4: Allow branch definition with git config
  2011-08-28 21:58 [PATCH v4 0/4] git-p4: Improve branch support Vitor Antunes
  2011-08-28 21:58 ` [PATCH v4 1/4] git-p4: Correct branch base depot path detection Vitor Antunes
  2011-08-28 21:58 ` [PATCH v4 2/4] git-p4: Allow filtering Perforce branches by user Vitor Antunes
@ 2011-08-28 21:58 ` Vitor Antunes
  2011-08-28 21:58 ` [PATCH v4 4/4] git-p4: Add simple test case for branch import Vitor Antunes
  2011-08-29  6:07 ` [PATCH v4 0/4] git-p4: Improve branch support Junio C Hamano
  4 siblings, 0 replies; 7+ messages in thread
From: Vitor Antunes @ 2011-08-28 21:58 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 6314c20..2f7b270 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -342,6 +342,11 @@ def gitConfig(key, args = None): # set args to "--bool", for instance
         _gitConfig[key] = read_pipe(cmd, 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 = {}
 
@@ -1490,6 +1495,25 @@ class P4Sync(Command, P4UserMap):
                     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 97b66b9..52003ae 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -263,6 +263,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.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 4/4] git-p4: Add simple test case for branch import
  2011-08-28 21:58 [PATCH v4 0/4] git-p4: Improve branch support Vitor Antunes
                   ` (2 preceding siblings ...)
  2011-08-28 21:58 ` [PATCH v4 3/4] git-p4: Allow branch definition with git config Vitor Antunes
@ 2011-08-28 21:58 ` Vitor Antunes
  2011-08-29  6:07 ` [PATCH v4 0/4] git-p4: Improve branch support Junio C Hamano
  4 siblings, 0 replies; 7+ messages in thread
From: Vitor Antunes @ 2011-08-28 21:58 UTC (permalink / raw)
  To: git; +Cc: Pete Wyckoff, Tor Arvid Lund, Vitor Antunes

Create a basic branch structure in P4 and clone it with git-p4.
Also, make an update on P4 side and check if git-p4 imports it correctly.
The branch structure is created in such a way that git-p4 will fail to import
updates if patch "git-p4: Correct branch base depot path detection" is not
applied.

Signed-off-by: Vitor Antunes <vitor.hda@gmail.com>
Signed-off-by: Pete Wyckoff <pw@padd.com>
---
 t/t9800-git-p4.sh |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh
index 9d4d4bf..01ba041 100755
--- a/t/t9800-git-p4.sh
+++ b/t/t9800-git-p4.sh
@@ -405,6 +405,67 @@ test_expect_success 'detect copies' '
 	p4 filelog //depot/file13 | grep -q "branch from //depot/file"
 '
 
+# Create a simple branch structure in P4 depot to check if it is correctly
+# cloned.
+test_expect_success 'add simple p4 branches' '
+	cd "$cli" &&
+	mkdir branch1 &&
+	cd branch1 &&
+	echo file1 >file1 &&
+	echo file2 >file2 &&
+	p4 add file1 file2 &&
+	p4 submit -d "branch1" &&
+	p4 integrate //depot/branch1/... //depot/branch2/... &&
+	p4 submit -d "branch2" &&
+	echo file3 >file3 &&
+	p4 add file3 &&
+	p4 submit -d "add file3 in branch1" &&
+	p4 open file2 &&
+	echo update >>file2 &&
+	p4 submit -d "update file2 in branch1" &&
+	p4 integrate //depot/branch1/... //depot/branch3/... &&
+	p4 submit -d "branch3" &&
+	cd "$TRASH_DIRECTORY"
+'
+
+# Configure branches through git-config and clone them.
+# All files are tested to make sure branches were cloned correctly.
+# Finally, make an update to branch1 on P4 side to check if it is imported
+# correctly by git-p4.
+test_expect_success 'git-p4 clone simple branches' '
+	test_when_finished cleanup_git &&
+	test_create_repo "$git" &&
+	cd "$git" &&
+	git config git-p4.branchList branch1:branch2 &&
+	git config --add git-p4.branchList branch1:branch3 &&
+	"$GITP4" clone --dest=. --detect-branches //depot@all &&
+	git log --all --graph --decorate --stat &&
+	git reset --hard p4/depot/branch1 &&
+	test -f file1 &&
+	test -f file2 &&
+	test -f file3 &&
+	grep -q update file2 &&
+	git reset --hard p4/depot/branch2 &&
+	test -f file1 &&
+	test -f file2 &&
+	test ! -f file3 &&
+	! grep -q update file2 &&
+	git reset --hard p4/depot/branch3 &&
+	test -f file1 &&
+	test -f file2 &&
+	test -f file3 &&
+	grep -q update file2 &&
+	cd "$cli" &&
+	cd branch1 &&
+	p4 edit file2 &&
+	echo file2_ >>file2 &&
+	p4 submit -d "update file2 in branch1" &&
+	cd "$git" &&
+	git reset --hard p4/depot/branch1 &&
+	"$GITP4" rebase &&
+	grep -q file2_ file2
+'
+
 test_expect_success 'shutdown' '
 	pid=`pgrep -f p4d` &&
 	test -n "$pid" &&
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 0/4] git-p4: Improve branch support
  2011-08-28 21:58 [PATCH v4 0/4] git-p4: Improve branch support Vitor Antunes
                   ` (3 preceding siblings ...)
  2011-08-28 21:58 ` [PATCH v4 4/4] git-p4: Add simple test case for branch import Vitor Antunes
@ 2011-08-29  6:07 ` Junio C Hamano
  2011-08-29  9:33   ` Vitor Antunes
  4 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2011-08-29  6:07 UTC (permalink / raw)
  To: Vitor Antunes; +Cc: git, Pete Wyckoff, Tor Arvid Lund

Could you make this an incremental patch relative to what is already in
next?


	

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 0/4] git-p4: Improve branch support
  2011-08-29  6:07 ` [PATCH v4 0/4] git-p4: Improve branch support Junio C Hamano
@ 2011-08-29  9:33   ` Vitor Antunes
  0 siblings, 0 replies; 7+ messages in thread
From: Vitor Antunes @ 2011-08-29  9:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Pete Wyckoff, Tor Arvid Lund

On Sun, 28 Aug 2011 23:07:17 -0700
Junio C Hamano <gitster@pobox.com> wrote:

> Could you make this an incremental patch relative to what is already in
> next?

Done.
-- 
Vitor Antunes

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-29  9:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-28 21:58 [PATCH v4 0/4] git-p4: Improve branch support Vitor Antunes
2011-08-28 21:58 ` [PATCH v4 1/4] git-p4: Correct branch base depot path detection Vitor Antunes
2011-08-28 21:58 ` [PATCH v4 2/4] git-p4: Allow filtering Perforce branches by user Vitor Antunes
2011-08-28 21:58 ` [PATCH v4 3/4] git-p4: Allow branch definition with git config Vitor Antunes
2011-08-28 21:58 ` [PATCH v4 4/4] git-p4: Add simple test case for branch import Vitor Antunes
2011-08-29  6:07 ` [PATCH v4 0/4] git-p4: Improve branch support Junio C Hamano
2011-08-29  9:33   ` Vitor Antunes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.