From 112348dba475ce15ffc57d6192632d4d8e1331d0 Mon Sep 17 00:00:00 2001 From: Matt York Date: Wed, 9 May 2012 15:07:47 -0700 Subject: [PATCH 1/3] Adding p4v integration for History, Time Lapse, and Revision Graph views --- Context.sublime-menu | 17 ++++++++++++++- Default.sublime-commands | 15 +++++++++++++ Main.sublime-menu | 15 +++++++++++++ Perforce.py | 47 ++++++++++++++++++++++++++++++++++++++++ messages/1.0.14.txt | 6 +++++ package-metadata.json | 2 +- 6 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 messages/1.0.14.txt diff --git a/Context.sublime-menu b/Context.sublime-menu index 0832e41..6366185 100644 --- a/Context.sublime-menu +++ b/Context.sublime-menu @@ -50,7 +50,22 @@ "caption": "Select Diff Application" } ] - }, + }, + { + "command": "perforce_visual", + "args": {"cmd": "history"}, + "caption": "History" + }, + { + "command": "perforce_visual", + "args": {"cmd": "annotate"}, + "caption": "Time Lapse" + }, + { + "command": "perforce_visual", + "args": {"cmd": "tree"}, + "caption": "Revision Graph" + }, { "command": "perforce_list_checked_out_files", "caption": "List Checked Out Files" diff --git a/Default.sublime-commands b/Default.sublime-commands index a66090f..04f5f70 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -27,6 +27,21 @@ "caption": "Perforce: Diff", "command": "perforce_diff" }, + { + "caption": "Perforce: History", + "command": "perforce_visual", + "args": {"cmd": "history"} + }, + { + "caption": "Perforce: Time Lapse", + "command": "perforce_visual", + "args": {"cmd": "annotate"} + }, + { + "caption": "Perforce: Revision Graph", + "command": "perforce_visual", + "args": {"cmd": "tree"} + }, { "caption": "Perforce: Graphical Diff with Depot", "command": "perforce_graphical_diff_with_depot" diff --git a/Main.sublime-menu b/Main.sublime-menu index a2db347..d21eebe 100644 --- a/Main.sublime-menu +++ b/Main.sublime-menu @@ -53,6 +53,21 @@ } ] }, + { + "command": "perforce_visual", + "args": {"cmd": "history"}, + "caption": "History" + }, + { + "command": "perforce_visual", + "args": {"cmd": "annotate"}, + "caption": "Time Lapse" + }, + { + "command": "perforce_visual", + "args": {"cmd": "tree"}, + "caption": "Revision Graph" + }, { "command": "perforce_list_checked_out_files", "caption": "List Checked Out Files" diff --git a/Perforce.py b/Perforce.py index 8812d02..a459e29 100644 --- a/Perforce.py +++ b/Perforce.py @@ -18,6 +18,7 @@ # Eric Martel - first implementation of submit # Eric Martel - Better handling of P4CONFIG files # Andrew Butt & Eric Martel - threading of the diff task and selector for the graphical diff application +# Matt York - p4v commands to load history, time lapse view, and revision graph import sublime import sublime_plugin @@ -57,6 +58,18 @@ def ConstructCommand(in_command): command += in_command return command +def GetPerforceInfo(): + command = ConstructCommand('p4 info') + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True) + result, err = p.communicate() + + if(err): + WarnUser("usererr " + err.strip()) + return err + + settings = dict([entry.split(': ',1) for entry in result.splitlines()]) + return settings + def getPerforceConfigFromPreferences(command): perforce_settings = sublime.load_settings('Perforce.sublime-settings') @@ -1025,3 +1038,37 @@ def MakeChangelistsList(self): resultchangelists.insert(0, "Changelist " + changelistlinesplit[1] + " - " + ' '.join(changelistlinesplit[7:])) return resultchangelists + +class PerforceVisualCommandThread(threading.Thread): + def __init__(self, command, filename): + self.command = command + self.filename = filename + threading.Thread.__init__(self) + + def run(self): + p = GetPerforceInfo() + command = ConstructCommand('p4v -p %s -u %s -c %s -cmd "%s %s"' % + (p['Server license-ip'], p['User name'], p['Client name'], + self.command, self.filename)) + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True) + result, err = p.communicate() + +def PerforceVisualCommandOnFile(command, full_path): + if(full_path): + folder_name, filename = os.path.split(full_path) + if(IsFileInDepot(folder_name, filename)): + PerforceVisualCommandThread(command, full_path).start() + LogResults(1, "Launching thread for Visual Command") + else: + LogResults(0, "File is not under the client root.") + else: + WarnUser("View does not contain a file") + +class PerforceVisualCommand(sublime_plugin.TextCommand): + def run(self, edit, cmd): + if(cmd): + PerforceVisualCommandOnFile(cmd, self.view.file_name()) + else: + sublime.error_message("no cmd type given for p4v") + + \ No newline at end of file diff --git a/messages/1.0.14.txt b/messages/1.0.14.txt new file mode 100644 index 0000000..ce20d78 --- /dev/null +++ b/messages/1.0.14.txt @@ -0,0 +1,6 @@ +Perforce integration 1.0.14 Changelog: + +Add +- Added function to extract all info in `p4 info` into a dictionary +- Added a command to launch any p4v window. Window specified in args. Launches in separate thread. +- Added context, main, and command menu items for p4v History, Time Lapse, and Revision Graph windows \ No newline at end of file diff --git a/package-metadata.json b/package-metadata.json index 51613bd..f417ac1 100644 --- a/package-metadata.json +++ b/package-metadata.json @@ -1 +1 @@ -{"url": "https://github.com/ericmartel/Sublime-Text-2-Perforce-Plugin", "version": "2012.01.12.01.58.03", "description": "Supports auto add and checkout with commands to add, diff, checkout, revert, diff using p4diff and lists all checked out files with quick access to them"} \ No newline at end of file +{"url": "http://www.ericmartel.com/sublime-text-2-perforce-plugin/", "version": "2012.05.08.08.14.02", "description": "Supports auto add and checkout with commands to add, checkout, delete, diff, rename, revert, diff using p4diff and lists all checked out files with quick access to them with simple changelist management"} \ No newline at end of file From 6fdbeaad13cdc6163f9f34151762aac2c1f4b902 Mon Sep 17 00:00:00 2001 From: Pranav Tekchand Date: Fri, 20 Jun 2014 09:17:02 +0200 Subject: [PATCH 2/3] Fix for p4v context commands This change should get the p4v commands to work in more perforce deployment scenarios. Server license-ip might be a separate host:port depending on your perforce infrastructure. --- Perforce.py | 11 +++++++++-- messages/1.0.15.txt | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Perforce.py b/Perforce.py index 796ca19..16f2006 100644 --- a/Perforce.py +++ b/Perforce.py @@ -1110,12 +1110,19 @@ def __init__(self, command, filename): def run(self): p = GetPerforceInfo() + p4_port = 1667 + if 'P4PORT' in os.environ: + p4_port = os.environ['P4PORT'] + elif 'Broker address' in p: + p4_port = p['Broker address'] + elif 'Server license-ip' in p: + p4_port = p['Server license-ip'] command = ConstructCommand('p4v -p %s -u %s -c %s -cmd "%s %s"' % - (p['Server license-ip'], p['User name'], p['Client name'], + (p4_port, p['User name'], p['Client name'], self.command, self.filename)) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True) result, err = p.communicate() - + def PerforceVisualCommandOnFile(command, full_path): if(full_path): folder_name, filename = os.path.split(full_path) diff --git a/messages/1.0.15.txt b/messages/1.0.15.txt index 83a46fd..3de625d 100644 --- a/messages/1.0.15.txt +++ b/messages/1.0.15.txt @@ -1,4 +1,5 @@ Perforce integration 1.0.15 Changelog: Bugfix -- Reverted a change that broke the Mac version \ No newline at end of file +- Reverted a change that broke the Mac version +- Fix p4v commands to work in more perforce deployment scenarios \ No newline at end of file From 7ca9056fc37816c98bb455ef1ab804754d23b3e1 Mon Sep 17 00:00:00 2001 From: Pranav Tekchand Date: Thu, 10 Jul 2014 21:27:19 +0200 Subject: [PATCH 3/3] p4v command helper: Added a call to 'p4 set' and the read P4PORT out of it, if it is set, instead of defaulting to 1667 --- Perforce.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/Perforce.py b/Perforce.py index 16f2006..1968ce8 100644 --- a/Perforce.py +++ b/Perforce.py @@ -78,7 +78,7 @@ def GetPerforceInfo(): return err settings = dict([entry.split(': ',1) for entry in result.splitlines()]) - return settings + return settings def getPerforceConfigFromPreferences(command): perforce_settings = sublime.load_settings('Perforce.sublime-settings') @@ -99,6 +99,30 @@ def addP4Var(command, var): command = addP4Var(command, "P4PASSWD") return command +def GetP4PortFromSet(): + command = ConstructCommand('p4 set') + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True) + result, err = p.communicate() + + if(err): + WarnUser("porterr " + err.strip()) + return -1 + + # locate the line containing "P4PORT=" and extract the following host:port + startindex = result.find("P4PORT=") + if(startindex == -1): + WarnUser("Unexpected output from 'p4 set'.") + return -1 + + startindex += 7 # advance after 'P4PORT=' + + endindex = result.find("\n", startindex) + if(endindex == -1): + WarnUser("Unexpected output from 'p4 set'.") + return -1 + + return result[startindex:endindex].strip(); + def GetUserFromClientspec(): command = ConstructCommand('p4 info') p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True) @@ -1110,15 +1134,21 @@ def __init__(self, command, filename): def run(self): p = GetPerforceInfo() - p4_port = 1667 + p4_port = -1 if 'P4PORT' in os.environ: p4_port = os.environ['P4PORT'] elif 'Broker address' in p: p4_port = p['Broker address'] elif 'Server license-ip' in p: p4_port = p['Server license-ip'] - command = ConstructCommand('p4v -p %s -u %s -c %s -cmd "%s %s"' % - (p4_port, p['User name'], p['Client name'], + else: + p4_port = GetP4PortFromSet() + p4_port_param = '' + if(p4_port != -1 and p4_port): + p4_port_param = '-p %s ' % (p4_port) + + command = ConstructCommand('p4v %s-u %s -c %s -cmd "%s %s"' % + (p4_port_param, p['User name'], p['Client name'], self.command, self.filename)) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True) result, err = p.communicate()