[SOLVED] Support for the SVN columns -- with ideas for implementation

Features wanted...
Post Reply
sj515064
Posts: 51
Joined: 21 Feb 2019 06:14

[SOLVED] Support for the SVN columns -- with ideas for implementation

Post by sj515064 »

As a TortoiseSVN user, I would like to have the SVN related information displayed as extra columns, such as SVN status, revision number, etc., so that I can sort or filter the files accordingly.
Image_3.png
It seems that the SVN properties cannot be derived directly from the system. Rather, they should be read from somewhere else.

I did some search and found a possible solution: use the "SVN status -v [PATH]" command in CMD, which will return the SVN information about the files and folders in [PATH].
A typical return:
Image_4.png
It can be seen that there are five columns returned, in which the first, the third, the fourth, and the fifth one are exactly what we need.
The first column tells whether a file is modified (M), to be added (A), to be deleted (D), none-versioned (?), or normal (empty). The third column tells the last changed revision of the file/folder. The fourth column tells information of the author, and the fifth one is the corresponding file/folder. Details can be found in page 22 of the SVNbook, in the section "See an overview of your changes".

I assume that a script is enough to accomplish this, which runs the "SVN status -v [PATH]" command in the background for the current directory and parses the returned, and then displays the grabbed information in columns.

The command is available on machines where the TortoiseSVN (https://tortoisesvn.net/) client is installed.

The SVNbook can be downloaded here: http://svnbook.red-bean.com/ or https://sjtueducn-my.sharepoint.com/:b: ... Q?e=FpfiSc

Similar requests here:
viewtopic.php?f=5&t=2600&p=23267&hilit= ... umn#p23267
viewtopic.php?f=5&t=443&p=3870&hilit=SVN+column#p3870

Please consider an implementation :)
To see the attached files, you need to log into the forum.
Last edited by sj515064 on 08 Mar 2019 15:51, edited 2 times in total.

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Support for the SVN columns -- with ideas for implementation

Post by highend »

An implementation on automatically calling external commands for folders? Unlikely to happen...

Why don't you just use custom columns to display the necessary information yourself?
One of my scripts helped you out? Please donate via Paypal

sj515064
Posts: 51
Joined: 21 Feb 2019 06:14

Re: Support for the SVN columns -- with ideas for implementation

Post by sj515064 »

highend wrote: 21 Feb 2019 09:10 An implementation on automatically calling external commands for folders? Unlikely to happen...

Why don't you just use custom columns to display the necessary information yourself?
Yes, it may sound unsuitable at the first time to have XYplorer calling external commands for folders. However, this feature is non-trivial. Rather, SVN information is just like the metadata for photos, whereas not supported in Windows 10 anymore. Therefore, one can not simply add them in custom columns through click and selection. It has to be done through a script.

Would it possible for the implementation of this script :wink: Corresponding users can download and use it themselves. Main features of the product won't be cluttered in this way.

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Support for the SVN columns -- with ideas for implementation

Post by highend »

Scripting this is trivial. Zip a sample project (that contain state fields like a, m, ? and files in at least one subfolder) and mail it to forfun@posteo.me
One of my scripts helped you out? Please donate via Paypal

sj515064
Posts: 51
Joined: 21 Feb 2019 06:14

Re: Support for the SVN columns -- with ideas for implementation

Post by sj515064 »

Thank you very much :D

I will post the script here for convenience of other users.

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Support for the SVN columns -- with ideas for implementation

Post by highend »

Code: Select all

    $svn = "C:\Program Files\TortoiseSVN\bin\svn.exe";
    $result = runret("""$svn"" status -v ""<curpath>""", "%TEMP%");
    $match = regexmatches($result, "^.*?" . regexreplace(<cc_item>, "([\\.+(){\[^$])", "\$1") . "$");
    if (!$match) { return; }
    // Indexes for gettoken: State=1|Working revision=2|<removed>|User=3|Path=4
    $fields = regexreplace($match, "^([acdm? ])\s+([0-9]+)\s+([0-9?]+)\s+(\S+?)\s+(.+)$", "$1|$3|$4|$5");
    return gettoken($fields, 3, "|");
So to show 4 custom columns you name them accordingly like
State, Revision, User, Path
and change the script accordingly in the LAST line (and the first if TortoiseSVN is NOT installed in that path!). In this case it would show the user, because User=3
...
One of my scripts helped you out? Please donate via Paypal

sj515064
Posts: 51
Joined: 21 Feb 2019 06:14

Re: Support for the SVN columns -- with ideas for implementation

Post by sj515064 »

highend wrote: 21 Feb 2019 10:02

Code: Select all

    $svn = "C:\Program Files\TortoiseSVN\bin\svn.exe";
    $result = runret("""$svn"" status -v ""<curpath>""", "%TEMP%");
    $match = regexmatches($result, "^.*?" . regexreplace(<cc_item>, "([\\.+(){\[^$])", "\$1") . "$");
    if (!$match) { return; }
    // Indexes for gettoken: State=1|Working revision=2|<removed>|User=3|Path=4
    $fields = regexreplace($match, "^([acdm? ])\s+([0-9]+)\s+([0-9?]+)\s+(\S+?)\s+(.+)$", "$1|$3|$4|$5");
    return gettoken($fields, 3, "|");
So to show 4 custom columns you name them accordingly like
State, Revision, User, Path
and change the script accordingly in the LAST line (and the first if TortoiseSVN is NOT installed in that path!). In this case it would show the user, because User=3
...

That's awesome! :tup: Output of the script is very close to the expected behavior, though with some minor problems (when setting the index in the last line to 1, the State together with the Path is displayed).
Also, it is found that running the script harms responsiveness of the application. A similar phenomenon is observed when doing large-scale file searching. Therefore, I will fall back to icon overlay for telling the SVN status for the moment. Anyway, thank you very much for the help.

Last but not least, it is advised that custom script execution and file searching both be treated as "background tasks", like file copying, in case they would cause XYplorer to hang up.

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Support for the SVN columns -- with ideas for implementation

Post by highend »

when setting the index in the last line to 1, the State together with the Path is displayed
Show the full output of "C:\Program Files\TortoiseSVN\bin\svn.exe" status -v "<path>">
where <path> is the path to the svn repository and ofc this thing must be executed from a command prompt
Also, it is found that running the script harms responsiveness of the application
The whole thing could be done instantly, but that would require a manual user interaction (because he would
need to "update" the state) e.g. via a button...

E.g. the code to update the status:
It assumes svn.exe is in the path and you're in the svn repository folder when you execute it...

Code: Select all

    perm $P_SVN_Result;
    $P_SVN_Result = runret("""svn"" status -v ""<curpath>""", "%TEMP%");
    if (regexmatches($P_SVN_Result, "w155007")) { status "No svn repository path, aborted!", "8B4513", "stop"; end true; }

    $P_SVN_Result = regexreplace($P_SVN_Result, "^([acdm? ])\s+([0-9]+)\s+([0-9?]+)\s+(\S+?)\s+(.+)$", "$1|$3|$4|$5");
    #485; // View - Refresh List
    writepv;
And the belonging simplified custom column (and no, as long as I haven't seen your output there is no fix for your problem):

Code: Select all

    // 1=State, 2=Working revision, 3=User, 4=Path
    $showID  = 3; // In other words: User

    $match = regexmatches($P_SVN_Result, "^.*?" . regexreplace(<cc_item>, "([\\.+(){\[^$])", "\$1") . "$");
    if (!$match) { return; }
    return gettoken($match, $showID, "|");
it is advised that custom script execution and file searching both be treated as "background tasks"
There is no threading...
One of my scripts helped you out? Please donate via Paypal

sj515064
Posts: 51
Joined: 21 Feb 2019 06:14

Re: Support for the SVN columns -- with ideas for implementation

Post by sj515064 »

highend wrote: 21 Feb 2019 13:11
when setting the index in the last line to 1, the State together with the Path is displayed
Show the full output of "C:\Program Files\TortoiseSVN\bin\svn.exe" status -v "<path>">
where <path> is the path to the svn repository and ofc this thing must be executed from a command prompt
Also, it is found that running the script harms responsiveness of the application
The whole thing could be done instantly, but that would require a manual user interaction (because he would
need to "update" the state) e.g. via a button...

E.g. the code to update the status:
It assumes svn.exe is in the path and you're in the svn repository folder when you execute it...

Code: Select all

    perm $P_SVN_Result;
    $P_SVN_Result = runret("""svn"" status -v ""<curpath>""", "%TEMP%");
    if (regexmatches($P_SVN_Result, "w155007")) { status "No svn repository path, aborted!", "8B4513", "stop"; end true; }

    $P_SVN_Result = regexreplace($P_SVN_Result, "^([acdm? ])\s+([0-9]+)\s+([0-9?]+)\s+(\S+?)\s+(.+)$", "$1|$3|$4|$5");
    #485; // View - Refresh List
    writepv;
And the belonging simplified custom column (and no, as long as I haven't seen your output there is no fix for your problem):

Code: Select all

    // 1=State, 2=Working revision, 3=User, 4=Path
    $showID  = 3; // In other words: User

    $match = regexmatches($P_SVN_Result, "^.*?" . regexreplace(<cc_item>, "([\\.+(){\[^$])", "\$1") . "$");
    if (!$match) { return; }
    return gettoken($match, $showID, "|");
it is advised that custom script execution and file searching both be treated as "background tasks"
There is no threading...
Sorry for being late.

The output of the "svn status" command is as follows:
Image_6.png
And the custom column under the original script shows as:
Image_7.png
It is desired that the custom column displays different texts according to the retrieved State from the return of the "svn status" command:
Image_8.png
I don't know the internal mechanism of custom columns via script. However, if it is executed per file, then the efficiency would be rather low.
It only has to be executed once when the user navigates to a certain directory.

Thank you for your kind help :)
To see the attached files, you need to log into the forum.

highend
Posts: 14954
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Support for the SVN columns -- with ideas for implementation

Post by highend »

This is the fastest way... (but again, the main script needs to be executed manually to update the custom column fields)...

If it is only for your own username, you could remove the "|hybrid2016" part...
The $users is necessary, otherwise a line like:
? C:\Users\hybrid2016\Documents\MATLAB\lib_repo\trunk\params\l.txt
can't be treated correctly easily...

Code: Select all

    $users = "%username%|hybrid2016";

    perm $P_SVN_Result;
    $P_SVN_Result = runret("""svn"" status -v ""<curpath>""", "%TEMP%");
    if (regexmatches($P_SVN_Result, "w155007")) { status "No svn repository path, aborted!", "8B4513", "stop"; end true; }

    $P_SVN_Result = regexreplace($P_SVN_Result, "^([acdm? ])\s+([0-9]+)?\s+([0-9?]+)?\s+($users)?\s+(.+)$", "$1|$3|$4|$5");
    #485; // View - Refresh List
    writepv;
Custom column with different messages if the id to be shown is 1 (= State):
Only the $showID needs to be modified...

Code: Select all

    // 1=State, 2=Working revision, 3=User, 4=Path
    $showID  = 1; // In other words: State

    $match = regexmatches($P_SVN_Result, "^.*?" . regexreplace(<cc_item>, "([\\.+(){\[^$])", "\$1") . "$");
    if (!$match) { return; }
    $field = gettoken($match, $showID, "|");
    if ($showID == 1) {
        switch ($field) {
            case "M": $field = "modified"; break;
            case "?": $field = "empty"; break;
            case "A": $field = "added"; break;
            case "C": $field = "conflict"; break;
            case "D": $field = "deleted"; break;
            default: $field = "normal";
        }
    }
    return $field;
One of my scripts helped you out? Please donate via Paypal

sj515064
Posts: 51
Joined: 21 Feb 2019 06:14

Re: Support for the SVN columns -- with ideas for implementation

Post by sj515064 »

That works perfectly!!! :D It also runs fast.

For other people using TortoiseSVN together with XYplorer (both are great products), the scripts above can help you.

What you have to do:
1. Add a custom button on the toolbar;
2. Assign the first script to the button;
3. Define a custom column in settings: Infomation | Custom Columns;
4. Define the newly added custom column with the second script.

Now add the custom column to the tab, navigate to your working copy, and press the custom button, you'll see the SVN status appears in the custom column! You'll then be able to sort files according to SVN status, and quickly locate those modified.

Update: I make a few modifications to the original scripts for improvement (maybe :) ), as follows:
For the custom toolbar button:

Code: Select all

perm $P_SVN_Result;
          run "cmd /c svn status -v ""<curpath>"" > ""<xydata>\temp\output.txt""", ,2,0;
          $P_SVN_Result = readfile("<xydata>\temp\output.txt");

          if !$P_SVN_Result { status "No svn repository path, aborted!", "8B4513", "stop"; end true; }
          
          //remove null chars at the beginning of each line
          $P_SVN_Result = regexreplace($P_SVN_Result, "^\x00+", "");
          //replace the first space in each line with "N"
          $P_SVN_Result = regexreplace($P_SVN_Result, "^ ", "N");
          //remove all lines starting with "?"
          $P_SVN_Result = regexreplace($P_SVN_Result, "^\?.*<crlf>", "");

          #485; // View - Refresh List

For the custom column:

Code: Select all

if (!$P_SVN_Result) { return ""; }
    $tk_index = gettokenindex("*<cc_path><cc_name>", $P_SVN_Result, <crlf>, "w");
    $matched_line = gettoken($P_SVN_Result,$tk_index ,<crlf>);
    if (!$matched_line) { return ""; }
    $field = gettoken($matched_line);
        switch ($field) {
            case "M": $field = "modified"; break;
            case "?": $field = ""; break;
            case "A": $field = "added"; break;
            case "C": $field = "conflict"; break;
            case "D": $field = "deleted"; break;
	    case "N": $field = "normal"; break;
            default: $field = "error";
        }
    return $field;

Update: the third line of the first scipt should be updated
[code] $users = "%username%|hybrid2016";

perm $P_SVN_Result;
$P_SVN_Result = runret("""svn"" status -v ""<curpath>""", "%TEMP%");
if (regexmatches($P_SVN_Result, "w155007")) { status "No svn repository path, aborted!", "8B4513", "stop"; end true; }

$P_SVN_Result = regexreplace($P_SVN_Result, "^([acdm? ])\s+([0-9]+)?\s+([0-9?]+)?\s+($users)?\s+(.+)$", "$1|$3|$4|$5");
#485; // View - Refresh List
writepv;[/code]
Note the "-u" parameter above, it forces retrieving SVN information from the repository, rather than from the local cache. Thus, every time you modify a file, click the button, the SVN status will be updated from "normal" to "modified". (My fault :wink:)


Comment(s):
1. You have to manully click the button to update the SVN text status for each item in the list.
2. "svn status -u -v" sometimes fail to return anything in my environment, so I fall back to "svn status -v" and it works fine.
The scipts are only applicable to files, not folders. In other words, it won't show SVN status for folders.
However, it suffices daily use since the files are what we are really going to edit and the number of them is larger than folders.


Thanks again for highend's great scripts!

Cheers

Post Reply