1

I want to get the 'BASE' number by 'svn info' command in Windows batch file as the following batch script:

svn update

for /f "tokens=2" %%i in ('svn info -rBASE^|find "Revision"') do (
 @echo %%i
 set svn_rev=%%i
)

But I always got the 'HEAD' number of my svn managed project code. So I tried the command directly in console:

>svn info -rBASE
Path: AliceAgent4.0b5856
URL: https://192.168.1.116:3443/svn/ProjectAliceVR/AliceOperationAgent/branches/AliceAgent4.0b5856
Relative URL: ^/AliceOperationAgent/branches/AliceAgent4.0b5856
Repository Root: https://192.168.1.116:3443/svn/ProjectAliceVR
Repository UUID: 794566ed1-6640e-7746-860d-66136dce9e99a
Revision: 5936
Node Kind: directory
Last Changed Author: yuanhui.he
Last Changed Rev: 5933
Last Changed Date: 2019-03-21 15:10:43 +0800 (周四, 21 3月 2019)

The Revision is 5936, other than 5933. Then, I tried the HEAD parameter of svn, it output the same result with BASE:

> svn info -rHEAD
Path: AliceAgent4.0b5856
URL: https://192.168.1.116:3443/svn/ProjectAliceVR/AliceOperationAgent/branches/AliceAgent4.0b5856
Relative URL: ^/AliceOperationAgent/branches/AliceAgent4.0b5856
Repository Root: https://192.168.1.116:3443/svn/ProjectAliceVR
Repository UUID: 794566ed1-6640e-7746-860d-66136dce9e99a
Revision: 5936
Node Kind: directory
Last Changed Author: yuanhui.he
Last Changed Rev: 5933
Last Changed Date: 2019-03-21 15:10:43 +0800 (周四, 21 3月 2019)

EDIT:

I have tried 'svn info -rBASE^|find "Last Changed Rev:"' but it only got a Changed string in the batch script.

So, how can I get the number 5933 in the Last Changed Rev: 5933 line?

Kara
  • 6,115
  • 16
  • 50
  • 57
Yuanhui
  • 459
  • 5
  • 15
  • 1
    Change the number of `tokens` and the string to `find`. Possible duplicate of [How do you determine the latest SVN revision number rooted in a directory?](https://stackoverflow.com/questions/56227/how-do-you-determine-the-latest-svn-revision-number-rooted-in-a-directory) – Compo Mar 22 '19 at 02:10
  • I have seen your edit, it appears that you've not use the advice from my previous comment regarding changing the `tokens` or the code shown in the linked duplicate, which contains at least one `For /F` loop using the appropriate string to `find` and correct number of `tokens`. – Compo Mar 22 '19 at 02:28
  • @Compo Because I'm trying your linked answer and find some useful information. Basically, these are two way to solve this issue. – Yuanhui Mar 22 '19 at 02:35
  • 1
    I suggest to stay with `tokens=2` but use `delims=:` and then do a `set /a svn_rev=%%i` to get rid of the leading space. –  Mar 22 '19 at 02:55

2 Answers2

1

Basically, there are two issues in this question:

  • How to get the COMMITTED number other than the HEAD number.
  • How to correct the find parameter in a Windows batch file to find the correct result.

Honestly, the question How do you determine the latest SVN revision number rooted in a directory? is not fixed my issue but some body answered my question.

I think anybody find my issue here because they are facing the same questions with me. Omit time for them is always valuable, so I arranged answers here:

A1: change BASE or HEAD to COMMITTED can directly get you wants:

svn update

for /f "tokens=2" %%i in ('svn info -rCOMMITTED^|find "Revision"') do (
 @echo %%i
 set svn_rev=%%i
)

A2: change the for loop's tokens value to 4, then change the find parameter to Last Changed Rev:. This can correct the action of the for loop to find the correct number. I'm not familiar with windows batch scrip, my fault, @Compo.

svn update

for /f "tokens=4" %%i in ('svn info -rHEAD^|find "Last Changed Rev:"') do (
 @echo %%i
 set svn_rev=%%i
)
Yuanhui
  • 459
  • 5
  • 15
0

As per my comment,

  • split the input at the colon
  • using simulated input per text file
  • use findstr with it's RegEx features ^ anchor at line begin and multiple search strings
  • set variable name from start of line (with spaces removed) and
  • use set /A to remove trailing space from number
    (might fail with 08xx/09xx being interpreted as octal)

:: Q:\Test\2019\03\22\SO_55291828.cmd
@Echo off&Setlocal EnableDelayedExpansion

::svn update

Echo svn info -rBASE
for /f "tokens=1-2delims=:" %%i in ('
  type svn_info-rBASE ^|findstr "^Last.Changed.Rev ^Revision"
') do (
 Set "var=%%i"
 set /A "_!var: =!=%%j"
)
Set _
Echo:
Echo svn info -rHEAD
for /f "tokens=1-2delims=:" %%i in ('
  type svn_info-rHEAD ^|findstr "^Last.Changed.Rev ^Revision"
') do (
 Set "var=%%i"
 set /A "_!var: =!=%%j"
)
Set _

Sample output:

> SO_55291828.cmd
svn info -rBASE
_LastChangedRev=5933
_Revision=5936

svn info -rHEAD
_LastChangedRev=5933
_Revision=5936