git-p4: support excluding paths on sync

The clone subcommand has long had support for excluding subdirectories, but sync has not. This is a nuisance, since as soon as you do a sync, any changed files that were initially excluded start showing up. Move the "exclude" command-line option into the parent class; the actual behavior was already present there so it simply had to be exposed. Signed-off-by: Luke Diamand <luke@diamand.org> Reviewed-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Luke Diamand committed Jan 17, 2015 at 20:56 UTC 51334bb094e085728ffe2b603fa3fe41dd80c075
3 files changed +84 -13
Documentation/git-p4.txt
+3 -3
@@ -241,6 +241,9 @@ Git repository:
241 Use a client spec to find the list of interesting files in p4.
242 See the "CLIENT SPEC" section below.
243
244 +-/ <path>::
245 + Exclude selected depot paths when cloning or syncing.
246 +
247 Clone options
248 ~~~~~~~~~~~~~
249 These options can be used in an initial 'clone', along with the 'sync'
@@ -254,9 +257,6 @@ options described above.
257 --bare::
258 Perform a bare clone. See linkgit:git-clone[1].
259
257 --/ <path>::
258 - Exclude selected depot paths when cloning.
259 -
260 Submit options
261 ~~~~~~~~~~~~~~
262 These options can be used to modify 'git p4 submit' behavior.
git-p4.py
+10 -10
@@ -1915,7 +1915,10 @@ class P4Sync(Command, P4UserMap):
1915 optparse.make_option("--keep-path", dest="keepRepoPath", action='store_true',
1916 help="Keep entire BRANCH/DIR/SUBDIR prefix during import"),
1917 optparse.make_option("--use-client-spec", dest="useClientSpec", action='store_true',
1918 - help="Only sync files that are included in the Perforce Client Spec")
1918 + help="Only sync files that are included in the Perforce Client Spec"),
1919 + optparse.make_option("-/", dest="cloneExclude",
1920 + action="append", type="string",
1921 + help="exclude depot path"),
1922 ]
1923 self.description = """Imports from Perforce into a git repository.\n
1924 example:
@@ -1950,6 +1953,12 @@ class P4Sync(Command, P4UserMap):
1953 if gitConfig("git-p4.syncFromOrigin") == "false":
1954 self.syncWithOrigin = False
1955
1956 + # This is required for the "append" cloneExclude action
1957 + def ensure_value(self, attr, value):
1958 + if not hasattr(self, attr) or getattr(self, attr) is None:
1959 + setattr(self, attr, value)
1960 + return getattr(self, attr)
1961 +
1962 # Force a checkpoint in fast-import and wait for it to finish
1963 def checkpoint(self):
1964 self.gitStream.write("checkpoint\n\n")
@@ -3101,9 +3110,6 @@ class P4Clone(P4Sync):
3110 optparse.make_option("--destination", dest="cloneDestination",
3111 action='store', default=None,
3112 help="where to leave result of the clone"),
3104 - optparse.make_option("-/", dest="cloneExclude",
3105 - action="append", type="string",
3106 - help="exclude depot path"),
3113 optparse.make_option("--bare", dest="cloneBare",
3114 action="store_true", default=False),
3115 ]
@@ -3111,12 +3117,6 @@ class P4Clone(P4Sync):
3117 self.needsGit = False
3118 self.cloneBare = False
3119
3114 - # This is required for the "append" cloneExclude action
3115 - def ensure_value(self, attr, value):
3116 - if not hasattr(self, attr) or getattr(self, attr) is None:
3117 - setattr(self, attr, value)
3118 - return getattr(self, attr)
3119 -
3120 def defaultDestination(self, args):
3121 ## TODO: use common prefix of args?
3122 depotPath = args[0]
t/t9817-git-p4-exclude.sh new
+71
@@ -0,0 +1,71 @@
1 +#!/bin/sh
2 +
3 +test_description='git p4 tests for excluded paths during clone and sync'
4 +
5 +. ./lib-git-p4.sh
6 +
7 +test_expect_success 'start p4d' '
8 + start_p4d
9 +'
10 +
11 +# Create a repo with the structure:
12 +#
13 +# //depot/wanted/foo
14 +# //depot/discard/foo
15 +#
16 +# Check that we can exclude a subdirectory with both
17 +# clone and sync operations.
18 +
19 +test_expect_success 'create exclude repo' '
20 + (
21 + cd "$cli" &&
22 + mkdir -p wanted discard &&
23 + echo wanted >wanted/foo &&
24 + echo discard >discard/foo &&
25 + p4 add wanted/foo discard/foo &&
26 + p4 submit -d "initial revision"
27 + )
28 +'
29 +
30 +test_expect_success 'check the repo was created correctly' '
31 + test_when_finished cleanup_git &&
32 + git p4 clone --dest="$git" //depot/...@all &&
33 + (
34 + cd "$git" &&
35 + test_path_is_file wanted/foo &&
36 + test_path_is_file discard/foo
37 + )
38 +'
39 +
40 +test_expect_success 'clone, excluding part of repo' '
41 + test_when_finished cleanup_git &&
42 + git p4 clone -//depot/discard/... --dest="$git" //depot/...@all &&
43 + (
44 + cd "$git" &&
45 + test_path_is_file wanted/foo &&
46 + test_path_is_missing discard/foo
47 + )
48 +'
49 +
50 +test_expect_success 'clone, then sync with exclude' '
51 + test_when_finished cleanup_git &&
52 + git p4 clone -//depot/discard/... --dest="$git" //depot/...@all &&
53 + (
54 + cd "$cli" &&
55 + p4 edit wanted/foo discard/foo &&
56 + date >>wanted/foo &&
57 + date >>discard/foo &&
58 + p4 submit -d "updating" &&
59 +
60 + cd "$git" &&
61 + git p4 sync -//depot/discard/... &&
62 + test_path_is_file wanted/foo &&
63 + test_path_is_missing discard/foo
64 + )
65 +'
66 +
67 +test_expect_success 'kill p4d' '
68 + kill_p4d
69 +'
70 +
71 +test_done