git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: kazuki saitoh <ksaitoh560@gmail.com>
To: Pete Wyckoff <pw@padd.com>, git@vger.kernel.org
Subject: [PATCH v2] git-p4: Ask "p4" to interpret View setting
Date: Tue, 6 Aug 2013 15:45:29 +0900	[thread overview]
Message-ID: <CACGba4zdA=3tBE9UR=i9P9kNAL1HUc3UwSHbYeq4s9fwaN4=Mw@mail.gmail.com> (raw)

In Perforce, View setting of p4 client can describe
  -//depot/project/files/*.xls //client/project/files/*.xls
to exclude Excel files.
But "git p4 --use-client-spec" cannot support '*'.

In git-p4.py, "map_in_client" method analyzes View setting and return
client file path.
So I modify the method to just ask p4.


> Let me play with this for a bit.  I wonder about the performance
> aspects of doing a "p4 fstat" for every file.  Would it be
> possible to do one or a few batch queries higher up somewhere?
To reduce p4 access, it cache result of asking "client path".
And addition, "fstat" depends on sync status, so modify to use "p4
where" instead of "fstat".



Signed-off-by: KazukiSaitoh <ksaitoh560@gmail.com>
---
 git-p4.py                     | 53 ++++++-----------------------------
 t/lib-git-p4.sh               |  1 +
 t/t9807-git-p4-submit.sh      |  2 +-
 t/t9809-git-p4-client-view.sh | 65 +++++++++++++++++++++++++++++++++++--------
 4 files changed, 64 insertions(+), 57 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index 31e71ff..8ec8eb4 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1819,15 +1819,6 @@ class View(object):
                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:
@@ -1903,6 +1894,7 @@ class View(object):
     #
     def __init__(self):
         self.mappings = []
+        self.client_spec_path_cache = {}  # Caching result of p4
query, use for "--use-client-spec".

     def append(self, view_line):
         """Parse a view line, splitting it into depot and client
@@ -1965,44 +1957,17 @@ class View(object):
            depot file should live.  Returns "" if the file should
            not be mapped in the client."""

-        paths_filled = []
-        client_path = ""
-
-        # look at later entries first
-        for m in self.mappings[::-1]:
-
-            # see where will this path end up in the client
-            p = m.map_depot_to_client(depot_path)
-
-            if p == "":
-                # Depot path does not belong in client.  Must remember
-                # this, as previous items should not cause files to
-                # exist in this path either.  Remember that the list is
-                # being walked from the end, which has higher precedence.
-                # Overlap mappings do not exclude previous mappings.
-                if not m.overlay:
-                    paths_filled.append(m.client_side)
+        if self.client_spec_path_cache.has_key(depot_path):
+            return self.client_spec_path_cache[depot_path]

-            else:
-                # This mapping matched; no need to search any further.
-                # But, the mapping could be rejected if the client path
-                # has already been claimed by an earlier mapping (i.e.
-                # one later in the list, which we are walking backwards).
-                already_mapped_in_client = False
-                for f in paths_filled:
-                    # this is View.Path.match
-                    if f.match(p):
-                        already_mapped_in_client = True
-                        break
-                if not already_mapped_in_client:
-                    # Include this file, unless it is from a line that
-                    # explicitly said to exclude it.
-                    if not m.exclude:
-                        client_path = p
-
-                # a match, even if rejected, always stops the search
+        client_path = ""
+        where_result = p4CmdList(['where', depot_path])
+        for res in where_result:
+            if res["code"] != "error" and not res.has_key("unmap"):
+                client_path = res["path"].replace(getClientRoot()+"/", "")
                 break

+        self.client_spec_path_cache[depot_path] = client_path
         return client_path

 class P4Sync(Command, P4UserMap):
diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh
index 2098b9b..0d631dc 100644
--- a/t/lib-git-p4.sh
+++ b/t/lib-git-p4.sh
@@ -48,6 +48,7 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
 P4PORT=localhost:$P4DPORT
 P4CLIENT=client
 P4EDITOR=:
+P4CHARSET=""
 export P4PORT P4CLIENT P4EDITOR

 db="$TRASH_DIRECTORY/db"
diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh
index 1fb7bc7..4caf36e 100755
--- a/t/t9807-git-p4-submit.sh
+++ b/t/t9807-git-p4-submit.sh
@@ -17,7 +17,7 @@ test_expect_success 'init depot' '
  )
 '

-test_expect_failure 'is_cli_file_writeable function' '
+test_expect_success 'is_cli_file_writeable function' '
  (
  cd "$cli" &&
  echo a >a &&
diff --git a/t/t9809-git-p4-client-view.sh b/t/t9809-git-p4-client-view.sh
index 77f6349..160fd9a 100755
--- a/t/t9809-git-p4-client-view.sh
+++ b/t/t9809-git-p4-client-view.sh
@@ -75,18 +75,6 @@ test_expect_success 'init depot' '
  )
 '

-# double % for printf
-test_expect_success 'unsupported view wildcard %%n' '
- client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." &&
- test_when_finished cleanup_git &&
- test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
-'
-
-test_expect_success 'unsupported view wildcard *' '
- client_view "//depot/*/bar/... //client/*/bar/..." &&
- test_when_finished cleanup_git &&
- test_must_fail git p4 clone --use-client-spec --dest="$git" //depot
-'

 test_expect_success 'wildcard ... only supported at end of spec 1' '
  client_view "//depot/.../file11 //client/.../file11" &&
@@ -836,6 +824,59 @@ test_expect_success 'quotes on both sides' '
  git_verify "cdir 1/file11" "cdir 1/file12"
 '

+#
+# //depot
+#   - dir1
+#     - file11
+#     - file12
+#     - noneed_file11.junk
+#     - noneed_file12.junk
+#   - dir2
+#     - file21
+#     - file22
+#     - noneed_file21.junk
+#     - noneed_file22.junk
+#
+test_expect_success 'wildcard * setup' '
+ client_view "//depot/... //client/..." &&
+ (
+ p4 sync &&
+ cd "$cli" &&
+ rm files &&
+ p4 delete "//depot/..." &&
+ p4 submit -d "delete all files" &&
+ init_depot &&
+
+ cd "$cli" &&
+ p4 sync &&
+
+ echo dir1/noneed_file11.junk >dir1/noneed_file11.junk &&
+ p4 add dir1/noneed_file11.junk &&
+ p4 submit -d "dir1/noneed_file11.junk" &&
+
+ echo dir1/noneed_file12.junk >dir1/noneed_file12.junk &&
+ p4 add dir1/noneed_file12.junk &&
+ p4 submit -d "dir1/noneed_file12.junk" &&
+
+ echo dir2/noneed_file21.junk >dir2/noneed_file21.junk &&
+ p4 add dir2/noneed_file21.junk &&
+ p4 submit -d "dir2/noneed_file21.junk" &&
+
+ echo dir2/noneed_file22.junk >dir2/noneed_file22.junk &&
+ p4 add dir2/noneed_file22.junk &&
+ p4 submit -d "dir2/noneed_file22.junk"
+ )
+'
+test_expect_success 'view wildcard *' '
+ client_view "//depot/... //client/..." \
+ "-//depot/dir1/*.junk //client/dir1/*.junk" \
+ "-//depot/dir2/*.junk //client/dir2/*.junk" &&
+ files="dir1/file11 dir1/file12 dir2/file21 dir2/file22" &&
+ client_verify $files &&
+ git p4 clone --use-client-spec --dest="$git" //depot &&
+ git_verify $files
+'
+
 test_expect_success 'kill p4d' '
  kill_p4d
 '
-- 
1.8.4-rc1

             reply	other threads:[~2013-08-06  6:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-06  6:45 kazuki saitoh [this message]
2013-08-10 20:11 ` [PATCH v2] git-p4: Ask "p4" to interpret View setting Pete Wyckoff
2013-08-10 20:15   ` [PATCH 1/2] git p4 test: sanitize P4CHARSET Pete Wyckoff
2013-08-10 20:15   ` [PATCH 2/2] git p4: implement view spec wildcards with "p4 where" Pete Wyckoff
2013-08-14  0:59   ` [PATCH v2] git-p4: Ask "p4" to interpret View setting kazuki saitoh
2013-08-16  1:24     ` Pete Wyckoff
2013-08-25  2:29       ` Pete Wyckoff
2013-08-27  2:43         ` kazuki saitoh
2013-08-29 22:40           ` Pete Wyckoff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACGba4zdA=3tBE9UR=i9P9kNAL1HUc3UwSHbYeq4s9fwaN4=Mw@mail.gmail.com' \
    --to=ksaitoh560@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pw@padd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).