Re: [PATCH v2] git p4: implement view spec wildcards with "p4 where"

2013-09-05 Thread kazuki saitoh
2013/9/4 Junio C Hamano :
> kazuki saitoh  writes:
>
>> Currently, git p4 does not support many of the view wildcards,
>> such as * and %%n.  It only knows the common ... mapping, and
>> exclusions.
>>
>> Redo the entire wildcard code around the idea of
>> directly querying the p4 server for the mapping.  For each
>> commit, invoke "p4 where" with committed file paths as args and use
>> the client mapping to decide where the file goes in git.
>>
>> This simplifies a lot of code, and adds support for all
>> wildcards supported by p4.
>> Downside is that there is probably a 20%-ish slowdown with this approach.
>>
>> [pw: redo code and tests]
>>
>> Signed-off-by: Kazuki Saitoh 
>> Signed-off-by: Pete Wyckoff 
>
> This was whitespace-damaged in the message I received, so what is
> queued is after manual fix-up.  Please double check what will be
> queued on 'pu' later and Ack, and then I'll move it to 'next' and
> 'master'.
Indeed, some line is broken by line wrapping.
I use Gmail web interface and didn't read "git format-patch --help".
Sorry for the inconvenience.

I checked 'pu' branch and it looks correct.

Acked-by: Kazuki Saitoh 

>
> Thanks.
>
>> ---
>>  git-p4.py | 223 
>> +-
>>  1 file changed, 59 insertions(+), 164 deletions(-)
>>
>> diff --git a/git-p4.py b/git-p4.py
>> index 31e71ff..1793e86 100755
>> --- a/git-p4.py
>> +++ b/git-p4.py
>> @@ -780,11 +780,14 @@ def getClientSpec():
>>  # dictionary of all client parameters
>>  entry = specList[0]
>>
>> +# the //client/ name
>> +client_name = entry["Client"]
>> +
>>  # just the keys that start with "View"
>>  view_keys = [ k for k in entry.keys() if k.startswith("View") ]
>>
>>  # hold this new View
>> -view = View()
>> +view = View(client_name)
>>
>>  # append the lines, in order, to the view
>>  for view_num in range(len(view_keys)):
>> @@ -1555,8 +1558,8 @@ class P4Submit(Command, P4UserMap):
>>  for b in body:
>>  labelTemplate += "\t" + b + "\n"
>>  labelTemplate += "View:\n"
>> -for mapping in clientSpec.mappings:
>> -labelTemplate += "\t%s\n" % mapping.depot_side.path
>> +for depot_side in clientSpec.mappings:
>> +labelTemplate += "\t%s\n" % depot_side
>>
>>  if self.dry_run:
>>  print "Would create p4 label %s for tag" % name
>> @@ -1568,7 +1571,7 @@ class P4Submit(Command, P4UserMap):
>>
>>  # Use the label
>>  p4_system(["tag", "-l", name] +
>> -  ["%s@%s" % (mapping.depot_side.path,
>> changelist) for mapping in clientSpec.mappings])
>> +  ["%s@%s" % (depot_side, changelist) for
>> depot_side in clientSpec.mappings])
>>
>>  if verbose:
>>  print "created p4 label for tag %s" % name
>> @@ -1796,117 +1799,16 @@ class View(object):
>>  """Represent a p4 view ("p4 help views"), and map files in a
>> repo according to the view."""
>>
>> -class Path(object):
>> -"""A depot or client path, possibly containing wildcards.
>> -   The only one supported is ... at the end, currently.
>> -   Initialize with the full path, with //depot or //client."""
>> -
>> -def __init__(self, path, is_depot):
>> -self.path = path
>> -self.is_depot = is_depot
>> -self.find_wildcards()
>> -# remember the prefix bit, useful for relative mappings
>> -m = re.match("(//[^/]+/)", self.path)
>> -if not m:
>> -die("Path %s does not start with //prefix/" % self.path)
>> -prefix = m.group(1)
>> -if not self.is_depot:
>> -# strip //client/ on client paths
>> -self.path = self.path[len(prefix):]
>> -
>> -def find_wildcards(self):
>> -"""Make sure wildcards are valid, and set up internal
>> -   variables."""
>> -
>> -self.ends_triple_dot = False
>> -# There are three wildcards allowed in p4 views
>> -# (see "p4 help views").  This code knows how to
>> -# handle "..." (only at the end), but cannot deal with
>> -# "%%n" or "*".  Only check the depot_side, as p4 should
>> -# validate that the client_side matches too.
>> -if re.search(r'%%[1-9]', self.path):
>> -die("Can't handle %%n wildcards in view: %s" % self.path)
>> -if self.path.find("*") >= 0:
>> -die("Can't handle * wildcards in view: %s" % self.path)
>> -triple_dot_index = self.path.find("...")
>> -if triple_dot_index >= 0:
>> -if triple_dot_index != len(self.path) - 3:
>> -die("Can handle only single ... wildcard, at end: %s" %
>> -self.path)
>> -  

Re: [PATCH v2] git p4: implement view spec wildcards with "p4 where"

2013-09-03 Thread Junio C Hamano
kazuki saitoh  writes:

> Currently, git p4 does not support many of the view wildcards,
> such as * and %%n.  It only knows the common ... mapping, and
> exclusions.
>
> Redo the entire wildcard code around the idea of
> directly querying the p4 server for the mapping.  For each
> commit, invoke "p4 where" with committed file paths as args and use
> the client mapping to decide where the file goes in git.
>
> This simplifies a lot of code, and adds support for all
> wildcards supported by p4.
> Downside is that there is probably a 20%-ish slowdown with this approach.
>
> [pw: redo code and tests]
>
> Signed-off-by: Kazuki Saitoh 
> Signed-off-by: Pete Wyckoff 

This was whitespace-damaged in the message I received, so what is
queued is after manual fix-up.  Please double check what will be
queued on 'pu' later and Ack, and then I'll move it to 'next' and
'master'.

Thanks.

> ---
>  git-p4.py | 223 
> +-
>  1 file changed, 59 insertions(+), 164 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 31e71ff..1793e86 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -780,11 +780,14 @@ def getClientSpec():
>  # dictionary of all client parameters
>  entry = specList[0]
>
> +# the //client/ name
> +client_name = entry["Client"]
> +
>  # just the keys that start with "View"
>  view_keys = [ k for k in entry.keys() if k.startswith("View") ]
>
>  # hold this new View
> -view = View()
> +view = View(client_name)
>
>  # append the lines, in order, to the view
>  for view_num in range(len(view_keys)):
> @@ -1555,8 +1558,8 @@ class P4Submit(Command, P4UserMap):
>  for b in body:
>  labelTemplate += "\t" + b + "\n"
>  labelTemplate += "View:\n"
> -for mapping in clientSpec.mappings:
> -labelTemplate += "\t%s\n" % mapping.depot_side.path
> +for depot_side in clientSpec.mappings:
> +labelTemplate += "\t%s\n" % depot_side
>
>  if self.dry_run:
>  print "Would create p4 label %s for tag" % name
> @@ -1568,7 +1571,7 @@ class P4Submit(Command, P4UserMap):
>
>  # Use the label
>  p4_system(["tag", "-l", name] +
> -  ["%s@%s" % (mapping.depot_side.path,
> changelist) for mapping in clientSpec.mappings])
> +  ["%s@%s" % (depot_side, changelist) for
> depot_side in clientSpec.mappings])
>
>  if verbose:
>  print "created p4 label for tag %s" % name
> @@ -1796,117 +1799,16 @@ class View(object):
>  """Represent a p4 view ("p4 help views"), and map files in a
> repo according to the view."""
>
> -class Path(object):
> -"""A depot or client path, possibly containing wildcards.
> -   The only one supported is ... at the end, currently.
> -   Initialize with the full path, with //depot or //client."""
> -
> -def __init__(self, path, is_depot):
> -self.path = path
> -self.is_depot = is_depot
> -self.find_wildcards()
> -# remember the prefix bit, useful for relative mappings
> -m = re.match("(//[^/]+/)", self.path)
> -if not m:
> -die("Path %s does not start with //prefix/" % self.path)
> -prefix = m.group(1)
> -if not self.is_depot:
> -# strip //client/ on client paths
> -self.path = self.path[len(prefix):]
> -
> -def find_wildcards(self):
> -"""Make sure wildcards are valid, and set up internal
> -   variables."""
> -
> -self.ends_triple_dot = False
> -# There are three wildcards allowed in p4 views
> -# (see "p4 help views").  This code knows how to
> -# handle "..." (only at the end), but cannot deal with
> -# "%%n" or "*".  Only check the depot_side, as p4 should
> -# validate that the client_side matches too.
> -if re.search(r'%%[1-9]', self.path):
> -die("Can't handle %%n wildcards in view: %s" % self.path)
> -if self.path.find("*") >= 0:
> -die("Can't handle * wildcards in view: %s" % self.path)
> -triple_dot_index = self.path.find("...")
> -if triple_dot_index >= 0:
> -if triple_dot_index != len(self.path) - 3:
> -die("Can handle only single ... wildcard, at end: %s" %
> -self.path)
> -self.ends_triple_dot = True
> -
> -def ensure_compatible(self, other_path):
> -"""Make sure the wildcards agree."""
> -if self.ends_triple_dot != other_path.ends_triple_dot:
> - die("Both paths must end with ... if either does;\n" +
> - "paths: %s %s" % (self.path, other_path.path))
> -
> -