add p4 多个文件_diff - 如何将P4DIFF限制为仅SQL文件? - 堆栈内存溢出

本文介绍如何利用P4Report查询,结合SQL和Perforce命令,实现对特定文件的版本差异操作。作者分享了从文件、路径和修订版号抓取信息,以及使用foreach循环执行Diff操作的详细过程,旨在提高报告生成效率。
摘要由CSDN通过智能技术生成

通过使用完整的仓库路径和修订版号构建单独的查询,我能够完成仅SQL的Diff操作 。 有很多改进的余地 (例如解析第一个查询中的信息,而不是运行所有三个查询),但是由于我想将其用于今天的报告,所以我用光了时间。 任何有用的建议,将不胜感激!

我首先使用P4Report并从文件表(符合条件的第1行和第2行)中查询所有信息,然后将其输出到“报告”文本文件中。 最终,这将使我的报告成为Excel的标题。

P4报表查询:

select * from files where RIGHT (FILE,9) = 'chema.sql' and TIME > timestampadd(4, -8, now()) and action in ('add', 'edit', 'integrate') order by time;

然后,我只查询路径和文件名,并将其存储在变量中(第3和4行)。

P4报表查询:

select file from files where RIGHT (FILE,9) = 'chema.sql' and TIME > timestampadd(4, -8, now()) and action in ('add', 'edit', 'integrate') order by time;

最后,我查询了修订版本号,并将其也存储在变量中(第7和8行)。

P4报表查询:

select revision from files where RIGHT (FILE,9) = 'chema.sql' and TIME > timestampadd(4, -8, now()) and action in ('add', 'edit', 'integrate') order by time;

然后,我使用一个foreach循环来创建和执行每个Perforce命令行字符串,并将每个结果附加到“ _Diff_Report”文本文件中。

最后,我从“ _Diff_Report”中删除了所有选项卡(这使我导入Excel时更加整洁)。

$Rpt = '"C:\Program Files\Perforce\P4Report\p4sql.exe" -d ""~"" -i C:\Users\UserName\documents\Queries\DataQ\_Report.txt > C:\Users\UserName\Documents\Queries\Report.txt'

$out = iex "& $Rpt"

$Cmd1 = '"C:\Program Files\Perforce\P4Report\p4sql.exe" -i C:\Users\UserName\Documents\Queries\DataQ\_Files.txt'

$fil = iex "& $Cmd1"

# Debug

# $fil | Out-File C:\Users\UserName\Documents\Queries\_fil_Debug.txt

$Cmd2 = '"C:\Program Files\Perforce\P4Report\p4sql.exe" -i C:\Users\UserName\Documents\Queries\DataQ\_Revisions.txt'

$rev = iex "& $Cmd2"

# Debug

# $rev | Out-File C:\Users\UserName\Documents\Queries\_Rev_Debug.txt

$dt = Get-Date

$dt | Out-File C:\Users\UserName\Documents\Queries\DataQ\_Diff_Report.txt

$f = $fil

$r = $rev

# Debug

# $r | Out-File C:\Users\UserName\Documents\Queries\_R_variable_Debug.txt

$cnt = 2

foreach ($Change in $f)

{

$revision = $r[$cnt] -1

$Cmd3 = '"C:\Program Files\Perforce\p4" diff2 -db '

$Cmd3 = $Cmd3 + '"'

$Cmd3 = $Cmd3 + $f[$cnt]

$Cmd3 = $Cmd3 + '--'

$Cmd3 = $Cmd3 + $revision

$Cmd3 = $Cmd3 + '"'

$Cmd3 = $Cmd3 + ' ' + '"'

$Cmd3 = $Cmd3 + $f[$cnt]

$Cmd3 = $Cmd3 + '--'

$Cmd3 = $Cmd3 + $r[$cnt]

$Cmd3 = $Cmd3 + '"'

$Cmd3

$Diffs = iex "& $Cmd3"

$Diffs | Out-File C:\Users\UserName\Documents\Queries\DataQ\_Diff_Report.txt -Append

$cnt = $cnt + 1

}

$Content = [IO.File]::ReadAllText("C:\Users\UserName\Documents\Queries\DataQ\_Diff_Report.txt")

$Content = $Content -replace "`t",''

Write-Host $Content

[IO.File]::WriteAllText("C:\Users\UserName\Documents\Queries\Diff_Report.txt", $Content)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Java-diff-utils实现自动化对比两个文件夹下的同名文件,具体步骤如下: 1. 首先需要导入Java-diff-utils库,可以使用Maven或手动导入jar包的方式。 2. 读取两个文件夹下的文件列表,并筛选出同名文件。 3. 循环遍历同名文件列表,对每个文件进行比较。 4. 使用DiffUtils类的静态方法,比较两个文件的差异,并将结果保存到DiffResult对象中。 5. 根据DiffResult对象的结果,输出差异信息。 下面是一个示例代码,可以根据自己的需要进行修改和优化: ``` import difflib.*; import java.io.*; import java.util.*; public class FolderComparator { public static void main(String[] args) throws IOException { String folder1 = "/path/to/folder1"; String folder2 = "/path/to/folder2"; List<String> fileNames1 = Arrays.asList(new File(folder1).list()); List<String> fileNames2 = Arrays.asList(new File(folder2).list()); for (String fileName : fileNames1) { if (fileNames2.contains(fileName)) { String path1 = folder1 + "/" + fileName; String path2 = folder2 + "/" + fileName; List<String> lines1 = readLines(path1); List<String> lines2 = readLines(path2); Patch patch = DiffUtils.diff(lines1, lines2); if (!patch.getDeltas().isEmpty()) { System.out.println("The file " + fileName + " has differences:"); for (Delta delta : patch.getDeltas()) { System.out.println(delta); } } } } } private static List<String> readLines(String filePath) throws IOException { List<String> lines = new ArrayList<>(); BufferedReader reader = new BufferedReader(new FileReader(filePath)); String line = reader.readLine(); while (line != null) { lines.add(line); line = reader.readLine(); } reader.close(); return lines; } } ``` 请注意,这只是一个简单的示例代码,并没有对异常情况进行处理。在实际使用中,需要根据具体场景进行优化和修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值