All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Obey p4 views when using client spec
@ 2011-02-12  0:33 Ian Wienand
  2011-02-12 21:51 ` Pete Wyckoff
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Wienand @ 2011-02-12  0:33 UTC (permalink / raw)
  To: git, gitster; +Cc: Tor Arvid Lund, Pete Wyckoff

When using the p4 client spec, this attempts to obey the client's
output preferences.

For example, a view like

//depot/foo/branch/... //client/branch/foo/...
//depot/bar/branch/... //client/branch/bar/...

will result in a directory layout in the git tree of

branch/
branch/foo
branch/bar

p4 can do various other reordering that this change doesn't support,
but we should detect it and at least fail nicely.

Signed-off-by: Ian Wienand <ianw@vmware.com>
---
 contrib/fast-import/git-p4     |   50 ++++++++++++++++++++++++++++++++++++---
 contrib/fast-import/git-p4.txt |    5 ++++
 2 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 04ce7e3..a92beb6 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -910,6 +910,22 @@ class P4Sync(Command):
         return files
 
     def stripRepoPath(self, path, prefixes):
+        if self.useClientSpec:
+
+            # if using the client spec, we use the output directory
+            # specified in the client.  For example, a view
+            #   //depot/foo/branch/... //client/branch/foo/...
+            # will end up putting all foo/branch files into
+            #  branch/foo/
+            for val in self.clientSpecDirs:
+                if path.startswith(val[0]):
+                    # replace the depot path with the client path
+                    path = path.replace(val[0], val[1][1])
+                    # now strip out the client (//client/...)
+                    path = re.sub("^(//[^/]+/)", '', path)
+                    # the rest is all path
+                    return path
+
         if self.keepRepoPath:
             prefixes = [re.sub("^(//[^/]+/).*", r'\1', prefixes[0])]
 
@@ -1032,7 +1048,7 @@ class P4Sync(Command):
             includeFile = True
             for val in self.clientSpecDirs:
                 if f['path'].startswith(val[0]):
-                    if val[1] <= 0:
+                    if val[1][0] <= 0:
                         includeFile = False
                     break
 
@@ -1475,19 +1491,45 @@ class P4Sync(Command):
         for entry in specList:
             for k,v in entry.iteritems():
                 if k.startswith("View"):
+
+                    # p4 has these %%1 to %%9 arguments in specs to
+                    # reorder paths; which we can't handle (yet :)
+                    if re.match('%%\d', v) != None:
+                        print "Sorry, can't handle %%n arguments in client specs"
+                        sys.exit(1)
+
                     if v.startswith('"'):
                         start = 1
                     else:
                         start = 0
                     index = v.find("...")
+
+                    # save the "client view"; i.e the RHS of the view
+                    # line that tells the client where to put the
+                    # files for this view.
+                    cv = v[index+3:].strip() # +3 to remove previous '...'
+
+                    # if the client view doesn't end with a
+                    # ... wildcard, then we're going to mess up the
+                    # output directory, so fail gracefully.
+                    if not cv.endswith('...'):
+                        print 'Sorry, client view in "%s" needs to end with wildcard' % (k)
+                        sys.exit(1)
+                    cv=cv[:-3]
+
+                    # now save the view; +index means included, -index
+                    # means it should be filtered out.
                     v = v[start:index]
                     if v.startswith("-"):
                         v = v[1:]
-                        temp[v] = -len(v)
+                        include = -len(v)
                     else:
-                        temp[v] = len(v)
+                        include = len(v)
+
+                    temp[v] = (include, cv)
+
         self.clientSpecDirs = temp.items()
-        self.clientSpecDirs.sort( lambda x, y: abs( y[1] ) - abs( x[1] ) )
+        self.clientSpecDirs.sort( lambda x, y: abs( y[1][0] ) - abs( x[1][0] ) )
 
     def run(self, args):
         self.depotPaths = []
diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt
index 49b3359..e09da44 100644
--- a/contrib/fast-import/git-p4.txt
+++ b/contrib/fast-import/git-p4.txt
@@ -191,6 +191,11 @@ git-p4.useclientspec
 
   git config [--global] git-p4.useclientspec false
 
+The P4CLIENT environment variable should be correctly set for p4 to be
+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).
+
 Implementation Details...
 =========================
 
-- 
1.7.3.2

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

* Re: [PATCH] Obey p4 views when using client spec
  2011-02-12  0:33 [PATCH] Obey p4 views when using client spec Ian Wienand
@ 2011-02-12 21:51 ` Pete Wyckoff
  2011-02-14  9:16   ` Tor Arvid Lund
  0 siblings, 1 reply; 4+ messages in thread
From: Pete Wyckoff @ 2011-02-12 21:51 UTC (permalink / raw)
  To: Ian Wienand; +Cc: git, gitster, Tor Arvid Lund

ianw@vmware.com wrote on Fri, 11 Feb 2011 16:33 -0800:
> When using the p4 client spec, this attempts to obey the client's
> output preferences.
> 
> For example, a view like
> 
> //depot/foo/branch/... //client/branch/foo/...
> //depot/bar/branch/... //client/branch/bar/...
> 
> will result in a directory layout in the git tree of
> 
> branch/
> branch/foo
> branch/bar
> 
> p4 can do various other reordering that this change doesn't support,
> but we should detect it and at least fail nicely.
> 
> Signed-off-by: Ian Wienand <ianw@vmware.com>

Nice, thanks for making the changes.

Acked-by: Pete Wyckoff <pw@padd.com>

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

* Re: [PATCH] Obey p4 views when using client spec
  2011-02-12 21:51 ` Pete Wyckoff
@ 2011-02-14  9:16   ` Tor Arvid Lund
  2011-02-14 18:33     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Tor Arvid Lund @ 2011-02-14  9:16 UTC (permalink / raw)
  To: Pete Wyckoff; +Cc: Ian Wienand, git, gitster

On Sat, Feb 12, 2011 at 10:51 PM, Pete Wyckoff <pw@padd.com> wrote:
> ianw@vmware.com wrote on Fri, 11 Feb 2011 16:33 -0800:
>> When using the p4 client spec, this attempts to obey the client's
>> output preferences.
>>
>> For example, a view like
>>
>> //depot/foo/branch/... //client/branch/foo/...
>> //depot/bar/branch/... //client/branch/bar/...
>>
>> will result in a directory layout in the git tree of
>>
>> branch/
>> branch/foo
>> branch/bar
>>
>> p4 can do various other reordering that this change doesn't support,
>> but we should detect it and at least fail nicely.
>>
>> Signed-off-by: Ian Wienand <ianw@vmware.com>
>
> Nice, thanks for making the changes.
>
> Acked-by: Pete Wyckoff <pw@padd.com>

Good work, Ian! Thanks.

Acked-by: Tor Arvid Lund <torarvid@gmail.com>

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

* Re: [PATCH] Obey p4 views when using client spec
  2011-02-14  9:16   ` Tor Arvid Lund
@ 2011-02-14 18:33     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2011-02-14 18:33 UTC (permalink / raw)
  To: Tor Arvid Lund; +Cc: Pete Wyckoff, Ian Wienand, git

Tor Arvid Lund <torarvid@gmail.com> writes:

>>> ...
>>> p4 can do various other reordering that this change doesn't support,
>>> but we should detect it and at least fail nicely.
>>>
>>> Signed-off-by: Ian Wienand <ianw@vmware.com>
>>
>> Nice, thanks for making the changes.
>>
>> Acked-by: Pete Wyckoff <pw@padd.com>
>
> Good work, Ian! Thanks.
>
> Acked-by: Tor Arvid Lund <torarvid@gmail.com>

Will apply; thanks.

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

end of thread, other threads:[~2011-02-14 18:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-12  0:33 [PATCH] Obey p4 views when using client spec Ian Wienand
2011-02-12 21:51 ` Pete Wyckoff
2011-02-14  9:16   ` Tor Arvid Lund
2011-02-14 18:33     ` Junio C Hamano

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.