解析源安全历史记录输出并运行 diff 命令

发布于 2024-12-26 10:51:21 字数 985 浏览 1 评论 0原文

我对编写批处理脚本相当陌生。我正在尝试编写一个脚本文件来完成以下任务。

我下面有一个源安全命令来获取两个日期之间更改的文件列表

ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R  

上述命令的输出如下通过

Building list for $/myproject.......................................................  
....................................................................................  
...................................  

***** AllPages.master  *****  
Version 67  
User: user1              Date: 1/12/12   Time: 1:08p  
Checked in $/myproject/websites/website1
Comment:  

***** AdminTSSetup.aspx.vb *****
Version 10
User: user2              Date: 1/12/12    Time: 1:09 p
Checked in $/myproject/websites/website1
Comment: 

上面的输出,我想读取文件名(allpages.master、AdminTsSetup.aspx.vb)和输出中每个文件的版本并运行以下命令

SS diff -DS <filename from output> -V<version from output - 1>~<version from output>

基本上,我试图将输出中每个文件的先前版本与当前版本进行比较。

有人可以帮忙吗?

I am fairly new to writing batch scripts. I am trying to write a script file to achieve the following task.

I have a source safe command below to get the list of files changed between two dates

ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R  

The output of the above command is as follows

Building list for $/myproject.......................................................  
....................................................................................  
...................................  

***** AllPages.master  *****  
Version 67  
User: user1              Date: 1/12/12   Time: 1:08p  
Checked in $/myproject/websites/website1
Comment:  

***** AdminTSSetup.aspx.vb *****
Version 10
User: user2              Date: 1/12/12    Time: 1:09 p
Checked in $/myproject/websites/website1
Comment: 

With the output above, I want to read the file name (allpages.master, AdminTsSetup.aspx.vb) and version of each file from the output and run the following command

SS diff -DS <filename from output> -V<version from output - 1>~<version from output>

Basically, I was trying to compare the previous version with the current version for each file in the output.

Can some one please help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情丝乱 2025-01-02 10:51:21

这应该会给你你所要求的。但您指定的 diff 命令似乎缺少对项目的引用。

即使文件名包含空格、!、; 或任何特殊字符(例如 &),此解决方案也应该有效。或^。

@echo off
setlocal disableDelayedExpansion
for /f "delims=*" %%A in ('ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R ^| findstr /b "***** Version"') do (
  set "ln=%%A"
  setlocal enableDelayedExpansion
  if "!ln:~0,1!"==" " (
    for /f "eol=: delims=" %%F in ("!ln:~1!") do (
      endlocal
      set "file=%%~nxF"
    )
  ) else (
    for /f "tokens=2 delims= " %%V in ("!ln!") do (
      set /a "version1=%%V, version0=version1-1"
      ss.exe dif -DS "!file!" -V!version0!~!version1!
      endlocal
    )
  )
)

这是一个从“签入”行添加项目信息的版本

@echo off
setlocal disableDelayedExpansion
for /f "delims=*" %%A in ('ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R ^| findstr /b "***** Version Checked"') do (
  set "ln=%%A"
  setlocal enableDelayedExpansion
  if "!ln:~0,1!"==" " (
    for /f "eol=: delims=" %%F in ("!ln:~1!") do (
      endlocal
      set "file=%%~nxF"
    )
  ) else if "!ln:~0,1!"=="V" (
    for /f "tokens=2 delims= " %%V in ("!ln!") do (
      endlocal
      set /a "version1=%%V, version0=version1-1"
    )
  ) else (
    for /f "tokens=2* delims= " %%B in ("!ln!") do (
      endlocal
      set "proj=%%C"
      setlocal enableDelayedExpansion
      ss.exe dif -DS "!proj!/!file!" -V!version0!~!version1!
      endlocal
    )
  )
)

This should give you what you asked for. But it seems like the diff command you specified is missing a reference to the project.

This solution should work even if the file name contains spaces, !, ;, or any special characters like & or ^.

@echo off
setlocal disableDelayedExpansion
for /f "delims=*" %%A in ('ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R ^| findstr /b "***** Version"') do (
  set "ln=%%A"
  setlocal enableDelayedExpansion
  if "!ln:~0,1!"==" " (
    for /f "eol=: delims=" %%F in ("!ln:~1!") do (
      endlocal
      set "file=%%~nxF"
    )
  ) else (
    for /f "tokens=2 delims= " %%V in ("!ln!") do (
      set /a "version1=%%V, version0=version1-1"
      ss.exe dif -DS "!file!" -V!version0!~!version1!
      endlocal
    )
  )
)

Here is a version that adds the project information from the "Checked in" line

@echo off
setlocal disableDelayedExpansion
for /f "delims=*" %%A in ('ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R ^| findstr /b "***** Version Checked"') do (
  set "ln=%%A"
  setlocal enableDelayedExpansion
  if "!ln:~0,1!"==" " (
    for /f "eol=: delims=" %%F in ("!ln:~1!") do (
      endlocal
      set "file=%%~nxF"
    )
  ) else if "!ln:~0,1!"=="V" (
    for /f "tokens=2 delims= " %%V in ("!ln!") do (
      endlocal
      set /a "version1=%%V, version0=version1-1"
    )
  ) else (
    for /f "tokens=2* delims= " %%B in ("!ln!") do (
      endlocal
      set "proj=%%C"
      setlocal enableDelayedExpansion
      ss.exe dif -DS "!proj!/!file!" -V!version0!~!version1!
      endlocal
    )
  )
)
两人的回忆 2025-01-02 10:51:21

基本上你需要一个 for 循环和一个小状态:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims= " %%i in ('ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R') do (
  if "%%i"=="*****" (
    rem a file name
    set "FileName=%%j"
  ) else (
    if "%%i"=="Version" (
      set Version=%%j
      set /a LastVersion=Version - 1
      ss diff -DS "!FileName!" -V!LastVersion!~!Version!
      set FileName=&set Version=&setLastVersion=
    )
  )
)

我想应该可以工作。

Basically you need a for loop and a little state:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims= " %%i in ('ss.exe history $/myproject -Vd04/01/2012~01/01/2012 -R') do (
  if "%%i"=="*****" (
    rem a file name
    set "FileName=%%j"
  ) else (
    if "%%i"=="Version" (
      set Version=%%j
      set /a LastVersion=Version - 1
      ss diff -DS "!FileName!" -V!LastVersion!~!Version!
      set FileName=&set Version=&setLastVersion=
    )
  )
)

Should kinda work, I guess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文