Re: [PATCH] Support different branch layouts in git-p4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 1, 2011 at 11:59 PM, Ian Wienand <ianw@xxxxxxxxxx> wrote:
> Hi,
>
> I think the addition to the git-p4.txt in the diff explains the
> reasoning behind the patch best. ÂIn short, we have a repository
> layout
>
> //depot/foo/branch
> //depot/moo/branch
>
> where we require projects 'foo' and 'moo' to be alongside each other.
> We can do this with p4 views, but currently have to have 'foo' and
> 'moo' in separate git repos.
>
> This just munges the incoming paths to either put the branch as the
> top level directory, or just remove it entirely if you don't need it.

Hi, Ian! We haven't met, but thank you for the patch, and for trying
to help make git better.

Now, I have to say that I don't particularly like it, and here's why I
will vote against this patch:

For starters, I don't think that I like git-p4 being taught to solve
problems that seem to be caused by a poor/unfortunate perforce layout.
Especially since *your* type of poor perforce layout will probably be
poor in a very different way from the next guy with a poor layout :)
For instance, you have hard-coded that you replace the first and
second directory name... It is very easy to imagine people having
deeper trees than that...

But then I started thinking about it a bit more... It was me who added
the --use-client-spec option back in the day. The support for that
stuff really should be better than what I made at the time. The
client-spec format contains lines like

//depot/...   //local-root/...
-//depot/dontcare/...   //local-root/dontcare/...
//depot/foo/branch/...   //local-root/branch/foo/...
//depot/moo/branch/...   //local-root/branch/moo/...

Please observe that the two last lines look like what I think *your*
client-spec should look like. This would map the foo/branch and
moo/branch in the perforce depot to branch/foo and branch/moo on the
client side.

Of course, today this will not work with git-p4 clone. The
--use-client-spec option, as I implemented it, simply filters out all
that stuff that matches the pattern lines that starts with "-". So the
names of all files will match the patterns on the left-hand side in
the client-spec. A solution which I think would work well for
everyone, is if files would be placed according to the right-hand
patterns in the client-spec.

That should be a much more elegant and generic solution. Whatcha
think? If you want to take a whack at hacking that into place, I will
help guide the way if needed (if others are not opposed to such an
idea) :)

    -- Tor Arvid

> I've tested it locally, but I don't really have a wide variety of p4
> environments to expose it too.
>
> -i
>
> Signed-off-by: Ian Wienand <ianw@xxxxxxxxxx>
> ---
> Âcontrib/fast-import/git-p4 Â Â | Â 35 +++++++++++++++++++++++-
> Âcontrib/fast-import/git-p4.txt | Â 58 ++++++++++++++++++++++++++++++++++++++++
> Â2 files changed, 92 insertions(+), 1 deletions(-)
>
> diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
> index 04ce7e3..4bd40f8 100755
> --- a/contrib/fast-import/git-p4
> +++ b/contrib/fast-import/git-p4
> @@ -848,6 +848,10 @@ class P4Sync(Command):
> Â Â Â Â Â Â Â Â optparse.make_option("--max-changes", dest="maxChanges"),
> Â Â Â Â Â Â Â Â optparse.make_option("--keep-path", dest="keepRepoPath", action='store_true',
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âhelp="Keep entire BRANCH/DIR/SUBDIR prefix during import"),
> + Â Â Â Â Â Â Â Âoptparse.make_option("--branch-path", dest="branchPath", type='choice',
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â choices=('none', 'first'),
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â default=None,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â help="Remove the branch dir (none) or move it above project dir (first)"),
> Â Â Â Â Â Â Â Â optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true',
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âhelp="Only sync files that are included in the Perforce Client Spec")
> Â Â Â Â ]
> @@ -917,6 +921,20 @@ class P4Sync(Command):
> Â Â Â Â Â Â if path.startswith(p):
> Â Â Â Â Â Â Â Â path = path[len(p):]
>
> + Â Â Â Â# reorg to move/remove branch from the output filename -- kind
> + Â Â Â Â# of like how you can set your view in your p4 client
> + Â Â Â Âif self.keepRepoPath and self.branchPath == 'first':
> + Â Â Â Â Â Â# move the second element first, so what was was
> + Â Â Â Â Â Â# "//depot/proj/branch/file" becomes "branch/proj/file".
> + Â Â Â Â Â Âpath = re.sub("^([^/]+/)([^/]+/)", r'\2\1', path)
> + Â Â Â Âelif self.keepRepoPath and self.branchPath == 'none':
> + Â Â Â Â Â Â# remove the second element, so what was
> + Â Â Â Â Â Â# "//depot/proj/branch/file" becomes "proj/file"
> + Â Â Â Â Â Âpath = re.sub("^([^/]+/)([^/]+/)", r'\2', path)
> + Â Â Â Âelif self.branchPath:
> + Â Â Â Â Â Âsys.stderr.write("branchPath without keepRepoPath?")
> + Â Â Â Â Â Âsys.exit(1)
> +
> Â Â Â Â return path
>
> Â Â def splitFilesIntoBranches(self, commit):
> @@ -940,7 +958,6 @@ class P4Sync(Command):
> Â Â Â Â Â Â relPath = self.stripRepoPath(path, self.depotPaths)
>
> Â Â Â Â Â Â for branch in self.knownBranches.keys():
> -
> Â Â Â Â Â Â Â Â # add a trailing slash so that a commit into qt/4.2foo doesn't end up in qt/4.2
> Â Â Â Â Â Â Â Â if relPath.startswith(branch + "/"):
> Â Â Â Â Â Â Â Â Â Â if branch not in branches:
> @@ -1283,12 +1300,24 @@ class P4Sync(Command):
> Â Â Â Â if self.keepRepoPath:
> Â Â Â Â Â Â option_keys['keepRepoPath'] = 1
>
> + Â Â Â Â# since we're just saving the dict keys, append the branchPath
> + Â Â Â Â# option to the key
> + Â Â Â Âif self.branchPath:
> + Â Â Â Â Â Âoption_keys['branchPath_%s' % self.branchPath] = 1
> +
> Â Â Â Â d["options"] = ' '.join(sorted(option_keys.keys()))
>
> Â Â def readOptions(self, d):
> Â Â Â Â self.keepRepoPath = (d.has_key('options')
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âand ('keepRepoPath' in d['options']))
>
> + Â Â Â Â# restore the branchpath option; is one of "none" and "first"
> + Â Â Â Âif (d.has_key('options')):
> + Â Â Â Â Â Âif ('branchPath_none' in d['options']):
> + Â Â Â Â Â Â Â Âself.branchPath = 'none'
> + Â Â Â Â Â Âelif ('branchPath_first' in d['options']):
> + Â Â Â Â Â Â Â Âself.branchPath = 'first'
> +
> Â Â def gitRefForBranch(self, branch):
> Â Â Â Â if branch == "main":
> Â Â Â Â Â Â return self.refPrefix + "master"
> @@ -1775,6 +1804,10 @@ class P4Clone(P4Sync):
> Â Â Â Â Â Â sys.stderr.write("Must specify destination for --keep-path\n")
> Â Â Â Â Â Â sys.exit(1)
>
> + Â Â Â Âif self.branchPath and not self.keepRepoPath:
> + Â Â Â Â Â Âsys.stderr.write("Must specify --keep-path for --branch-path\n")
> + Â Â Â Â Â Âsys.exit(1)
> +
> Â Â Â Â depotPaths = args
>
> Â Â Â Â if not self.cloneDestination and len(depotPaths) > 1:
> diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
> index 49b3359..669c63c 100644
> --- a/contrib/fast-import/git-p4.txt
> +++ b/contrib/fast-import/git-p4.txt
> @@ -191,6 +191,64 @@ git-p4.useclientspec
>
> Â git config [--global] git-p4.useclientspec false
>
> +Dealing with different repository layouts
> +=========================================
> +
> +Perforce clients can map views of projects and branches in different
> +ways which your build system may rely on. ÂSay your code is organised
> +as two projects "foo" and "moo" which have a common branch
> +
> +//depot/foo/branch/...
> +//depot/moo/branch/...
> +
> +and you require both "foo" and "moo" projects in your git repository,
> +there are several options.
> +
> +Firstly, you could simply clone each project as a completely separate
> +git tree. ÂHowever, if the two projects are dependent on each other
> +this can be annoying for both sync -- you must remember to sync both
> +"foo" and "moo" to keep everything consistent -- and submit -- a
> +change that should logically be a single changeset across "foo" and
> +"moo" will have to be broken up (breaking bisection too).
> +
> +Another option is to simply specify multiple depots
> +
> + git p4 sync //depot/foo/branch //depot/moo/branch
> +
> +which will import "foo" and "moo" into the same directory.
> +
> +To keep the projects separate, the --keep-path option used as
> +
> + git p4 sync --keep-path --destination /tmp/boo/ //depot/foo/branch //depot/moo/branch
> +
> +will create a layout of
> +
> + /tmp/boo/foo/branch/...
> + /tmp/boo/moo/branch/...
> +
> +However, some build systems may rely on p4's ability to specify
> +destinations for views in your client. ÂThe --branch-path flag, which
> +requires the --keep-path flag, allows two additional layout options.
> +
> + git p4 sync --keep-path --destination /tmp/boo --branch-path=none //depot/foo/branch //depot/moo/branch
> +
> +will remove the branch name entirely, leaving you with a directory
> +that looks like
> +
> + /tmp/boo/foo/...
> + /tmp/boo/moo/...
> +
> +and
> +
> + git p4 sync --keep-path --destination /tmp/boo --branch-path=first //depot/foo/branch //depot/moo/branch
> +
> +will give you each of the projects under a directory named for their
> +common branch
> +
> + /tmp/boo/branch/foo/...
> + /tmp/boo/branch/moo/...
> +
> +
> ÂImplementation Details...
> Â=========================
>
> --
> 1.7.2.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]