I do not understand why a --reverse-order switch or something is very difficult.
I will probably revert back to what I have used before:
// Diffs open workspace file against its have-revision.
// Suggested key binding: Ctrl+D
_command
vusrmacs_vcdiff() name_info(','VSARG2_EDITORCTL)
{
_macro('R',1);
if (!p_HasBuffer || (p_buf_flags & VSBUFFLAG_HIDDEN))
{
message('vusrmacs_vcdiff: A regular buffer is required.');
return -1;
}
// vcdiff() crashes when using Perforce if the file is not under
// version control or it is opened for add.
if (def_vc_system == 'SCC:Perforce SCM') // <-- this needs to change after switching to the p4 command line version
_PerforceDiff();
else
execute('vcdiff'); // <-- execute('vcdiff --reverse-order'); ?
}
// Runs a diff between the have-revision of the current file and the
// current file itself.
static void
_PerforceDiff()
{
_str diffToolPath = _GetDiffToolPath();
if (diffToolPath == null)
{
message('vusrmacs_vcdiff: No diff tool found.');
return;
}
_str filename = p_buf_name;
_str tempDir = get_env('TEMP') :+ '\vcdiff\' :+
stranslate(strip_filename(filename, 'N'), '', ':');
make_path(tempDir);
_str tempName = tempDir :+ strip_filename(filename, 'P');
_str newDirectory = get_env('TREE_ROOT');
if (newDirectory == '')
newDirectory = strip_filename(filename, 'N');
_str oldDirectory = getcwd();
chdir(newDirectory, /* changeDrive */ 1);
int shellReturnCode = shell(
'p4.exe print "' :+ filename :+
'"#have > "' :+ tempName :+ '" 2>&1', 'PQ');
chdir(oldDirectory, /* changeDrive */ 1);
int temp_view_id=0;
int orig_view_id=0;
int status = _open_temp_view(tempName, temp_view_id, orig_view_id);
if (status != 0)
{
message('vusrmacs_vcdiff: Could not open "' :+ tempName :+ '".');
return;
}
top();
_str output;
get_line(output);
if (_CheckPerforceOutput(output, shellReturnCode))
{
_delete_line();
_str revision = stranslate(output, '\1', '.*#([0-9]+) - .*', 'u');
tempName = strip_filename(tempName, 'E') :+ '#' :+ revision :+
_get_extension(tempName, /* returnDot */ true);
save('+o 'tempName, SV_OVERWRITE|SV_NOADDFILEHIST);
_str diffToolFlags = '';
if (strip_filename(diffToolPath, 'P') == 'vsdiff.exe')
diffToolFlags = ' -r1';
// We run the diff asynchronously so that we can continue using
// SlickEdit while the diff is in progress.
shell('"' :+ diffToolPath :+ '"' :+ diffToolFlags :+ ' "' :+
tempName :+ '" "' :+ filename :+ '"', 'APQ');
}
_delete_temp_view(temp_view_id);
p_window_id = orig_view_id;
}
// Returns the path of the diff tool to use.
static _str
_GetDiffToolPath()
{
_str path = null;
// We could look for the diff tool in config files for different version
// control systems, but for now we only check the P4V config file.
if (true /* def_vc_system == 'SCC:Perforce SCM' */)
{
_str appsettingsFilename = get_env('USERPROFILE') :+
'\.p4scc\appsettings.xml';
int status = -1;
int handle = _xmlcfg_open(
appsettingsFilename, status, VSXMLCFG_OPEN_ADD_PCDATA);
if (status != 0)
{
_str query = '//PropertyList/Associations[' \
'@varName="Diff Associations"]/Association[' \
'@varName="Default Association"]/Application/text()';
int index = _xmlcfg_find_simple(handle, query);
if (index >= 0)
path = _xmlcfg_get_value_unindent(handle, index);
_xmlcfg_close(handle);
}
}
// Use vsdiff if no other diff tool was found.
if (path == null)
path = path_search('vsdiff.exe');
if (path == '')
path = null;
return path;
}
// Returns true if the output of "p4 print" indicates no errors.
// Reports an error and returns false otherwise.
static boolean
_CheckPerforceOutput(
_str output,
int shellReturnCode)
{
if (output == 'Perforce client error:')
{
while (down() == 0)
{
_str line;
get_line(line);
output = output :+ "\n" :+ line;
}
_message_box(output);
return false;
}
if (shellReturnCode != 0)
{
message('vusrmacs_vcdiff: ' :+ output);
return false;
}
if (pos(' - no such file\(s\)\.$', output, 1, 'u') > 0)
{
message('vusrmacs_vcdiff: "' :+ p_buf_name :+ '" is not ' \
'under source control.');
return false;
}
return true;
}
I do not like it, but it (kind of) works..