Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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"
Expand Down
84 changes: 84 additions & 0 deletions Perforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Andrew Butt & Eric Martel - threading of the diff task and selector for the graphical diff application
# Eric Martel - Added the possibility to Submit the default changelist
# Jonathan Felchlin - Added a way to pass p4env parameters to the command building function
# Matt York - p4v commands to load history, time lapse view, and revision graph

import sublime
import sublime_plugin
Expand Down Expand Up @@ -67,6 +68,18 @@ def PrepareCommand():
def ConstructCommand(in_command):
return command_prefix + in_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')

Expand All @@ -86,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)
Expand Down Expand Up @@ -1088,3 +1125,50 @@ 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()
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']
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()

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")


7 changes: 6 additions & 1 deletion messages/1.0.14.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Perforce integration 1.0.14 Changelog:

Change
- Added the possibility to submit the Default changelist
- Added the possibility to submit the Default changelist

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
3 changes: 2 additions & 1 deletion messages/1.0.15.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Perforce integration 1.0.15 Changelog:

Bugfix
- Reverted a change that broke the Mac version
- Reverted a change that broke the Mac version
- Fix p4v commands to work in more perforce deployment scenarios
2 changes: 1 addition & 1 deletion package-metadata.json
Original file line number Diff line number Diff line change
@@ -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"}
{"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"}