Re: Pre-lock script templates (to the contrib directory)
Daniel Sahlberg via TortoiseSVN-dev <[email protected]>
| Newsgroups | gmane.comp.version-control.subversion.tortoisesvn.devel |
|---|---|
| Message-ID | <[email protected]> |
Sorry, the attachments were not accepted. Adding them here, should be renamed .js.tmpl. -- You received this message because you are subscribed to the Google Groups "TortoiseSVN-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/tortoisesvn-dev/56e6d72f-2174-48d3-b607-4453993a4aa3n%40googlegroups.com.
PreLock-add-computer-and-path.txt
(text/plain, 748 B)
/* this script is a local pre-lock hook script that sets the lock message to include the computer name and wc path. */
var ForAppending = 8;
var objArgs, num;
objArgs = WScript.Arguments;
num = objArgs.length;
if (num !== 5)
{
WScript.Echo("Usage: [CScript | WScript] PreLock.js path/to/pathsfile lock force path/to/msgfile path/to/CWD ");
WScript.Quit(1);
}
if (objArgs(1) == "true")
{
var fs = new ActiveXObject("Scripting.FileSystemObject");
if (fs.FileExists(objArgs(3)))
{
var wshl = new ActiveXObject("WScript.Shell")
var a = fs.OpenTextFile(objArgs(3), ForAppending);
a.WriteLine("Locked on " + wshl.ExpandEnvironmentStrings("%COMPUTERNAME%") + " in wc " + objArgs(4));
a.Close();
}
}
PreLock.txt
(text/plain, 1.5 KB)
/* this script is a local pre-lock hook script. */
var ForReading = 1;
var objArgs, num;
objArgs = WScript.Arguments;
num = objArgs.length;
if (num !== 5)
{
WScript.Echo("Usage: [CScript | WScript] PreLock.js path/to/pathsfile lock force path/to/msgfile path/to/CWD ");
WScript.Quit(1);
}
var paths = readPaths(objArgs(0));
var message = "list of paths selected for locking:\n";
for (var i = 0; i < paths.length; i++)
{
message = message + paths[i] + "\n";
}
message = message + (objArgs(1) == "true" ? "Getting" : "Releasing") + " lock" + (objArgs(2) == "true" ? " - forcefully" : "") + "\n";
message = message + readFile(objArgs(3));
message = message + "CWD is: " + objArgs(4) + "\n";
WScript.Echo(message);
WScript.Quit(0);
function readPaths(path)
{
var retPaths = [];
var fs = new ActiveXObject("Scripting.FileSystemObject");
if (fs.FileExists(path))
{
var a = fs.OpenTextFile(path, ForReading);
while (!a.AtEndOfStream)
{
var line = a.ReadLine();
retPaths.push(line);
}
a.Close();
}
return retPaths;
}
function readFile(path)
{
var msg = "";
var lines = 0;
var fs = new ActiveXObject("Scripting.FileSystemObject");
if (fs.FileExists(path))
{
var a = fs.OpenTextFile(path, ForReading);
while (!a.AtEndOfStream)
{
msg += a.ReadLine() + "\r\n";
lines++;
}
a.Close();
}
return "Lock message (" + lines + " lines):\r\n" + msg;
}