Skip to content

Commit b9d34db

Browse files
luked99gitster
authored andcommitted
git-p4: add option to disable syncing of p4/master with p4
Add an option to the git-p4 submit command to disable syncing with Perforce. This is useful for the case where a git-p4 mirror has been setup on a server somewhere, running from (e.g.) cron, and developers then clone from this. Having the local cloned copy also sync from Perforce just isn't useful. Signed-off-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b3477e commit b9d34db

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

Documentation/git-p4.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ These options can be used to modify 'git p4 submit' behavior.
344344
Disable the automatic rebase after all commits have been successfully
345345
submitted. Can also be set with git-p4.disableRebase.
346346

347+
--disable-p4sync::
348+
Disable the automatic sync of p4/master from Perforce after commits have
349+
been submitted. Implies --disable-rebase. Can also be set with
350+
git-p4.disableP4Sync. Sync with origin/master still goes ahead if possible.
351+
347352
Rebase options
348353
~~~~~~~~~~~~~~
349354
These options can be used to modify 'git p4 rebase' behavior.
@@ -661,6 +666,9 @@ git-p4.conflict::
661666
git-p4.disableRebase::
662667
Do not rebase the tree against p4/master following a submit.
663668

669+
git-p4.disableP4Sync::
670+
Do not sync p4/master with Perforce following a submit. Implies git-p4.disableRebase.
671+
664672
IMPLEMENTATION DETAILS
665673
----------------------
666674
* Changesets from p4 are imported using Git fast-import.

git-p4.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,9 @@ def __init__(self):
13571357
help="submit only the specified commit(s), one commit or xxx..xxx"),
13581358
optparse.make_option("--disable-rebase", dest="disable_rebase", action="store_true",
13591359
help="Disable rebase after submit is completed. Can be useful if you "
1360-
"work from a local git branch that is not master")
1360+
"work from a local git branch that is not master"),
1361+
optparse.make_option("--disable-p4sync", dest="disable_p4sync", action="store_true",
1362+
help="Skip Perforce sync of p4/master after submit or shelve"),
13611363
]
13621364
self.description = "Submit changes from git to the perforce depot."
13631365
self.usage += " [name of git branch to submit into perforce depot]"
@@ -1369,6 +1371,7 @@ def __init__(self):
13691371
self.update_shelve = list()
13701372
self.commit = ""
13711373
self.disable_rebase = gitConfigBool("git-p4.disableRebase")
1374+
self.disable_p4sync = gitConfigBool("git-p4.disableP4Sync")
13721375
self.prepare_p4_only = False
13731376
self.conflict_behavior = None
13741377
self.isWindows = (platform.system() == "Windows")
@@ -2229,11 +2232,14 @@ def run(self, args):
22292232
sync = P4Sync()
22302233
if self.branch:
22312234
sync.branch = self.branch
2232-
sync.run([])
2235+
if self.disable_p4sync:
2236+
sync.sync_origin_only()
2237+
else:
2238+
sync.run([])
22332239

2234-
if self.disable_rebase is False:
2235-
rebase = P4Rebase()
2236-
rebase.rebase()
2240+
if not self.disable_rebase:
2241+
rebase = P4Rebase()
2242+
rebase.rebase()
22372243

22382244
else:
22392245
if len(applied) == 0:
@@ -3261,6 +3267,14 @@ def importChanges(self, changes):
32613267
print self.gitError.read()
32623268
sys.exit(1)
32633269

3270+
def sync_origin_only(self):
3271+
if self.syncWithOrigin:
3272+
self.hasOrigin = originP4BranchesExist()
3273+
if self.hasOrigin:
3274+
if not self.silent:
3275+
print 'Syncing with origin first, using "git fetch origin"'
3276+
system("git fetch origin")
3277+
32643278
def importHeadRevision(self, revision):
32653279
print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
32663280

@@ -3333,12 +3347,7 @@ def run(self, args):
33333347
else:
33343348
self.refPrefix = "refs/heads/p4/"
33353349

3336-
if self.syncWithOrigin:
3337-
self.hasOrigin = originP4BranchesExist()
3338-
if self.hasOrigin:
3339-
if not self.silent:
3340-
print 'Syncing with origin first, using "git fetch origin"'
3341-
system("git fetch origin")
3350+
self.sync_origin_only()
33423351

33433352
branch_arg_given = bool(self.branch)
33443353
if len(self.branch) == 0:

0 commit comments

Comments
 (0)