From 2318121babea786390f51796bfce17088c3420ee Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:24 +0100 Subject: Create a specific version of the read_pipe_lines command for p4 invocations This will make it easier to isolate changes to how 'p4' is invoked (whether with parameters or not, etc.). Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 6ae0429c2d..fc2a60dfee 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -57,6 +57,13 @@ def read_pipe_lines(c): return val +def p4_read_pipe_lines(c): + """Specifically invoke p4 on the command supplied. """ + real_cmd = "%s %s" % ("p4", c) + if verbose: + print real_cmd + return read_pipe_lines(real_cmd) + def system(cmd): if verbose: sys.stderr.write("executing %s\n" % cmd) -- cgit v1.2.1 From b340fa43017437988e233ed4fd8dc00042614071 Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:25 +0100 Subject: Utilise the new 'p4_read_pipe_lines' command Now that we have the new command, we can utilise it and then eventually, isolate any changes required to the one place. Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index fc2a60dfee..3deaa42559 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -371,7 +371,7 @@ def originP4BranchesExist(): def p4ChangesForPaths(depotPaths, changeRange): assert depotPaths - output = read_pipe_lines("p4 changes " + ' '.join (["%s...%s" % (p, changeRange) + output = p4_read_pipe_lines("changes " + ' '.join (["%s...%s" % (p, changeRange) for p in depotPaths])) changes = [] @@ -519,7 +519,7 @@ class P4Submit(Command): # remove lines in the Files section that show changes to files outside the depot path we're committing into template = "" inFilesSection = False - for line in read_pipe_lines("p4 change -o"): + for line in p4_read_pipe_lines("change -o"): if line.endswith("\r\n"): line = line[:-2] + "\n" if inFilesSection: -- cgit v1.2.1 From bf9320f1512d7ad4a17a64cfe5a593bba5037b3e Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:26 +0100 Subject: Have a command that specifically invokes 'p4' (via system) Similiar to our 'p4_read_pipe_lines' command, we can isolate specific changes to the invocation method in the one location with this change. Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 3deaa42559..08acd517ba 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -70,6 +70,13 @@ def system(cmd): if os.system(cmd) != 0: die("command failed: %s" % cmd) +def p4_system(cmd): + """Specifically invoke p4 as the system command. """ + real_cmd = "%s %s" % ("p4", cmd) + if verbose: + print real_cmd + return system(real_cmd) + def isP4Exec(kind): """Determine if a Perforce 'kind' should have execute permission -- cgit v1.2.1 From 87b611d5fd518e4754e599bc2f348f83db410c56 Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:27 +0100 Subject: Utilise the new 'p4_system' function. Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 08acd517ba..2ed36ecd6b 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -98,7 +98,7 @@ def setP4ExecBit(file, mode): if p4Type[-1] == "+": p4Type = p4Type[0:-1] - system("p4 reopen -t %s %s" % (p4Type, file)) + p4_system("reopen -t %s %s" % (p4Type, file)) def getP4OpenedType(file): # Returns the perforce file type for the given file. @@ -561,7 +561,7 @@ class P4Submit(Command): modifier = diff['status'] path = diff['src'] if modifier == "M": - system("p4 edit \"%s\"" % path) + p4_system("edit \"%s\"" % path) if isModeExecChanged(diff['src_mode'], diff['dst_mode']): filesToChangeExecBit[path] = diff['dst_mode'] editedFiles.add(path) @@ -576,8 +576,8 @@ class P4Submit(Command): filesToAdd.remove(path) elif modifier == "R": src, dest = diff['src'], diff['dst'] - system("p4 integrate -Dt \"%s\" \"%s\"" % (src, dest)) - system("p4 edit \"%s\"" % (dest)) + p4_system("integrate -Dt \"%s\" \"%s\"" % (src, dest)) + p4_system("edit \"%s\"" % (dest)) if isModeExecChanged(diff['src_mode'], diff['dst_mode']): filesToChangeExecBit[dest] = diff['dst_mode'] os.unlink(dest) @@ -601,7 +601,7 @@ class P4Submit(Command): if response == "s": print "Skipping! Good luck with the next patches..." for f in editedFiles: - system("p4 revert \"%s\"" % f); + p4_system("revert \"%s\"" % f); for f in filesToAdd: system("rm %s" %f) return @@ -624,10 +624,10 @@ class P4Submit(Command): system(applyPatchCmd) for f in filesToAdd: - system("p4 add \"%s\"" % f) + p4_system("add \"%s\"" % f) for f in filesToDelete: - system("p4 revert \"%s\"" % f) - system("p4 delete \"%s\"" % f) + p4_system("revert \"%s\"" % f) + p4_system("delete \"%s\"" % f) # Set/clear executable bits for f in filesToChangeExecBit.keys(): @@ -728,7 +728,7 @@ class P4Submit(Command): os.chdir(self.clientPath) print "Syncronizing p4 checkout..." - system("p4 sync ...") + p4_system("sync ...") self.check() -- cgit v1.2.1 From 21a50753852cb51b120ec9933416daa6cea6d184 Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:28 +0100 Subject: Add a single command that will be used to construct the 'p4' command Rather than having three locations where the 'p4' command is built up, refactor this into the one place. This will, eventually, allow us to have one place where we modify the evironment or pass extra command-line options to the 'p4' binary. Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 2ed36ecd6b..b4acf7689d 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -16,6 +16,17 @@ from sets import Set; verbose = False + +def p4_build_cmd(cmd): + """Build a suitable p4 command line. + + This consolidates building and returning a p4 command line into one + location. It means that hooking into the environment, or other configuration + can be done more easily. + """ + real_cmd = "%s %s" % ("p4", cmd) + return real_cmd + def die(msg): if verbose: raise Exception(msg) -- cgit v1.2.1 From ee06427aa6d975c35b63c3cd103ace43fbde062b Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:29 +0100 Subject: If we are in verbose mode, output what we are about to run (or return) Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 2 ++ 1 file changed, 2 insertions(+) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index b4acf7689d..d36b0c6bec 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -25,6 +25,8 @@ def p4_build_cmd(cmd): can be done more easily. """ real_cmd = "%s %s" % ("p4", cmd) + if verbose: + print real_cmd return real_cmd def die(msg): -- cgit v1.2.1 From 155af83491b26d958b147c93620816846343b019 Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:30 +0100 Subject: Switch to using 'p4_build_cmd' Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index d36b0c6bec..2b6ea74d1c 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -72,9 +72,7 @@ def read_pipe_lines(c): def p4_read_pipe_lines(c): """Specifically invoke p4 on the command supplied. """ - real_cmd = "%s %s" % ("p4", c) - if verbose: - print real_cmd + real_cmd = p4_build_cmd(c) return read_pipe_lines(real_cmd) def system(cmd): @@ -85,9 +83,7 @@ def system(cmd): def p4_system(cmd): """Specifically invoke p4 as the system command. """ - real_cmd = "%s %s" % ("p4", cmd) - if verbose: - print real_cmd + real_cmd = p4_build_cmd(cmd) return system(real_cmd) def isP4Exec(kind): @@ -172,7 +168,7 @@ def isModeExecChanged(src_mode, dst_mode): return isModeExec(src_mode) != isModeExec(dst_mode) def p4CmdList(cmd, stdin=None, stdin_mode='w+b'): - cmd = "p4 -G %s" % cmd + cmd = p4_build_cmd("-G %s" % (cmd)) if verbose: sys.stderr.write("Opening pipe: %s\n" % cmd) -- cgit v1.2.1 From abcaf07360357cf2e9ce4b34e44adc09bb5587f0 Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:31 +0100 Subject: If the user has configured various parameters, use them. Some repositories require authentication and access to certain hosts. Allow git-p4 to pull this information from the configuration Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 2b6ea74d1c..a927e50b25 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -24,7 +24,29 @@ def p4_build_cmd(cmd): location. It means that hooking into the environment, or other configuration can be done more easily. """ - real_cmd = "%s %s" % ("p4", cmd) + real_cmd = "%s " % "p4" + + user = gitConfig("git-p4.user") + if len(user) > 0: + real_cmd += "-u %s " % user + + password = gitConfig("git-p4.password") + if len(password) > 0: + real_cmd += "-P %s " % password + + port = gitConfig("git-p4.port") + if len(port) > 0: + real_cmd += "-p %s " % port + + host = gitConfig("git-p4.host") + if len(host) > 0: + real_cmd += "-h %s " % host + + client = gitConfig("git-p4.client") + if len(client) > 0: + real_cmd += "-c %s " % client + + real_cmd += "%s" % (cmd) if verbose: print real_cmd return real_cmd -- cgit v1.2.1 From 3cafb7d8ce63effe6bf477182d431ecb4470eded Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:32 +0100 Subject: Consistently use 'git-p4' for the configuration entries Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index a927e50b25..6c64224b77 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1444,7 +1444,7 @@ class P4Sync(Command): if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes and gitBranchExists(self.branch): system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch)) - if self.useClientSpec or gitConfig("p4.useclientspec") == "true": + if self.useClientSpec or gitConfig("git-p4.useclientspec") == "true": self.getClientSpec() # TODO: should always look at previous commits, -- cgit v1.2.1 From bc02acfc769a1ae19772feaa7f03acfaea18a36f Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:33 +0100 Subject: Move git-p4.syncFromOrigin into a configuration parameters section Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4.txt | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt index b16a8384bc..0896abb933 100644 --- a/contrib/fast-import/git-p4.txt +++ b/contrib/fast-import/git-p4.txt @@ -63,18 +63,6 @@ It is recommended to run 'git repack -a -d -f' from time to time when using incremental imports to optimally combine the individual git packs that each incremental import creates through the use of git-fast-import. - -A useful setup may be that you have a periodically updated git repository -somewhere that contains a complete import of a Perforce project. That git -repository can be used to clone the working repository from and one would -import from Perforce directly after cloning using git-p4. If the connection to -the Perforce server is slow and the working repository hasn't been synced for a -while it may be desirable to fetch changes from the origin git repository using -the efficient git protocol. git-p4 supports this setup by calling "git fetch origin" -by default if there is an origin branch. You can disable this using - - git config git-p4.syncFromOrigin false - Updating ======== @@ -140,6 +128,22 @@ Example git-p4 rebase +Configuration parameters +======================== + +git-p4.syncFromOrigin + +A useful setup may be that you have a periodically updated git repository +somewhere that contains a complete import of a Perforce project. That git +repository can be used to clone the working repository from and one would +import from Perforce directly after cloning using git-p4. If the connection to +the Perforce server is slow and the working repository hasn't been synced for a +while it may be desirable to fetch changes from the origin git repository using +the efficient git protocol. git-p4 supports this setup by calling "git fetch origin" +by default if there is an origin branch. You can disable this using: + + git config [--global] git-p4.syncFromOrigin false + Implementation Details... ========================= -- cgit v1.2.1 From b87a659635f40b5301c6b18fa5e22c72ca79b830 Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:34 +0100 Subject: Put some documentation in about the parameters that have been added Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4.txt | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt index 0896abb933..79a22e9c10 100644 --- a/contrib/fast-import/git-p4.txt +++ b/contrib/fast-import/git-p4.txt @@ -131,6 +131,38 @@ Example Configuration parameters ======================== +git-p4.user ($P4USER) + +Allows you to specify the username to use to connect to the Perforce repository. + + git config [--global] git-p4.user public + +git-p4.password ($P4PASS) + +Allows you to specify the password to use to connect to the Perforce repository. +Warning this password will be visible on the command-line invocation of the p4 binary. + + git config [--global] git-p4.password public1234 + +git-p4.port ($P4PORT) + +Specify the port to be used to contact the Perforce server. As this will be passed +directly to the p4 binary, it may be in the format host:port as well. + + git config [--global] git-p4.port codes.zimbra.com:2666 + +git-p4.host ($P4HOST) + +Specify the host to contact for a Perforce repository. + + git config [--global] git-p4.host perforce.example.com + +git-p4.client ($P4CLIENT) + +Specify the client name to use + + git config [--global] git-p4.client public-view + git-p4.syncFromOrigin A useful setup may be that you have a periodically updated git repository -- cgit v1.2.1 From 5b5aa22f00c315021ff58450f18134b20dfd5abd Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Sun, 10 Aug 2008 19:26:35 +0100 Subject: Put in the two other configuration elements found in the source I am not entirely clear what these parameters do but felt it useful to call them out in the documentation. Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4.txt | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4.txt b/contrib/fast-import/git-p4.txt index 79a22e9c10..ac551d45f1 100644 --- a/contrib/fast-import/git-p4.txt +++ b/contrib/fast-import/git-p4.txt @@ -163,6 +163,10 @@ Specify the client name to use git config [--global] git-p4.client public-view +git-p4.allowSubmit + + git config [--global] git-p4.allowSubmit false + git-p4.syncFromOrigin A useful setup may be that you have a periodically updated git repository @@ -176,6 +180,10 @@ by default if there is an origin branch. You can disable this using: git config [--global] git-p4.syncFromOrigin false +git-p4.useclientspec + + git config [--global] git-p4.useclientspec false + Implementation Details... ========================= -- cgit v1.2.1 From d9429194f6e30e1f6f46a286217cd88972e1c83b Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Thu, 14 Aug 2008 23:40:38 +0100 Subject: Add p4 read_pipe and write_pipe wrappers Two additional wrappers to cover 3 places where we utilise p4 in piped form. Found by Tor Arvid Lund. Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 6c64224b77..3e9df70f29 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -69,6 +69,10 @@ def write_pipe(c, str): return val +def p4_write_pipe(c, str): + real_cmd = p4_build_cmd(c) + return write_pipe(c, str) + def read_pipe(c, ignore_error=False): if verbose: sys.stderr.write('Reading pipe: %s\n' % c) @@ -80,6 +84,9 @@ def read_pipe(c, ignore_error=False): return val +def p4_read_pipe(c, ignore_error=False): + real_cmd = p4_build_cmd(c) + return read_pipe(real_cmd, ignore_error) def read_pipe_lines(c): if verbose: -- cgit v1.2.1 From a7d3ef9d099ab00a19595bc3ca8abdc1fc6ff35d Mon Sep 17 00:00:00 2001 From: Anand Kumria Date: Thu, 14 Aug 2008 23:40:39 +0100 Subject: Utilise our new p4_read_pipe and p4_write_pipe wrappers Signed-off-by: Anand Kumria Signed-off-by: Junio C Hamano --- contrib/fast-import/git-p4 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'contrib/fast-import') diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 3e9df70f29..12fa9d3fd8 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -141,7 +141,7 @@ def setP4ExecBit(file, mode): def getP4OpenedType(file): # Returns the perforce file type for the given file. - result = read_pipe("p4 opened %s" % file) + result = p4_read_pipe("opened %s" % file) match = re.match(".*\((.+)\)\r?$", result) if match: return match.group(1) @@ -681,7 +681,7 @@ class P4Submit(Command): submitTemplate = self.prepareLogMessage(template, logMessage) if os.environ.has_key("P4DIFF"): del(os.environ["P4DIFF"]) - diff = read_pipe("p4 diff -du ...") + diff = p4_read_pipe("diff -du ...") newdiff = "" for newFile in filesToAdd: @@ -719,7 +719,7 @@ class P4Submit(Command): if self.isWindows: submitTemplate = submitTemplate.replace("\r\n", "\n") - write_pipe("p4 submit -i", submitTemplate) + p4_write_pipe("submit -i", submitTemplate) else: fileName = "submit.txt" file = open(fileName, "w+") -- cgit v1.2.1