我的 Windows 工作站上有一堆 Mercurial 存储库。我们是一家小商店,在某些日子(通常是糟糕的日子)我可能会对六个或更多的项目进行更改/错误修复。其中一些项目处于维护模式,大约每月才接触一次。当然,有时我在推送到中央 Hg 服务器之前会被打断。
有没有一种简单的方法可以定期将我的一堆存储库与中央服务器进行比较?如果我有尚未推送的更改,它应该警告我。理想情况下,某些内容位于系统托盘中,并按照“超过 48 小时的本地更改不在远程存储库中”的方式发出警报。
我想我应该设置一个脚本来检查我的存储库并比较它们。我可以养成每天运行脚本的习惯。
想法?
最佳答案
我在 Powershell 配置文件中使用辅助函数。它们在其他脚本语言中很容易实现,但我不敢在 .bat 或 .cmd 文件中执行此操作。
我保存了一个文件 D:\repos.config
,其中包含我想要快速浏览的所有本地存储库的绝对路径列表,以了解 3 件事:状态摘要、传入更改、传出更改。以下示例假定文件包含以下内容:
D:\repository1
D:\repository2
#D:\ignoredrepo
D:\repository3
D:\repository4
为了检查状态,脚本执行 $results = hg -R $path st
来获取状态列表,然后仅计算第一个字符,打印 1 行存储库路径和 1 行每个存储库路径的状态摘要行(如果有任何内容要显示):
----- D:\repository1
M 1 - A 1
----- D:\repository4
? 3
对于传入/传出,我将每个存储库的 hgrc
中的 [paths]
保持一致,以便 default
始终是我们的存储库服务器,bb
是 bitbucket 上的那个,等等。我循环遍历相同的路径列表,执行 $results = hg -R $path $type $alias --template '{rev} {node|short} {desc|firSTLine}\n' 对于每个。
$type是
in或
out,具体取决于我的调用,
$alias是每个存储库的
hgrc中应包含的路径别名(
default为空字符串,
bb ,
备份等)。我对
$results 做了一些处理,因为前两行不是实际的变更集。如果您想过滤掉 24 小时内的任何内容,您可能需要在模板中添加
{date|age}或
{date|shortdate}`。
这样我就可以在提示符下简单地编写 hgouts bb
并看到简洁的输出。有些存储库根本没有特定的别名,因此 2>$null
有助于防止出现一些 abort:repository bb not find!
消息。
----- D:\repository2
150 f7364a6f78d2 integrate FooBar
151 7a3d3d9fb0d0 fixes #1214; thingamajig wasn't getting closed
----- D:\repository4
4 dd88f00d93ff more changes to the doojiflopper
至于同步多个存储库,我对 TortoiseHg 2.0 及其存储库注册表感到非常满意,在我使用脚本告诉我需要执行哪些操作后,它可以帮助我一次执行一个操作。但循环遍历路径和 hg -R $path pull -u
或 hg -R $path push
整体,或使用位也不会太复杂脚本的选择性地仅拉/推工作目录中没有更改的所需内容。这只是我还不需要的东西。
编辑:我花了一点时间来清理代码。函数 hghg
是状态摘要,函数 hgins
[alias]
和 hgouts
[alias]
是我在提示符下实际调用的内容。
function hghg(){
$repos = [io.file]::readalllines('D:\repos.config')
$repos | % {
if (!$_.startswith('#') -and (test-path $_)){
hg-st $_
}
}
}
function hg-st($path){
$x = hg -R $path st
if ($x.length -gt 0){
write-host "----- $_"
$d = @{}
$x | % {
$c = $_[0]
if (!$d.containskey($c)){
$d[$c] = 0
}
$d[$c] += 1
}
$p = @()
$d.keys | % {
$cnt = $d[$_]
$p += "$_ $cnt"
}
write-host ' ' ([string]::join(' - ', $p))
}
}
function hgins($pathalias){
hg-inouts 'in' $pathalias
}
function hgouts($pathalias){
hg-inouts 'out' $pathalias
}
function hg-inouts($type, $pathalias){
$repos = [io.file]::readalllines('D:\repos.config')
$repos | % {
if (!$_.startswith('#') -and (test-path $_)){
hg-inout $type $_ $pathalias
}
}
}
function hg-inout($type, $source, $target){
$x = hg -R $source $type $target --template '{rev} {node|short} {desc|firstline}\n' 2>$null
if ($x.count -gt 2 -and $x[2] -ne 'no changes found'){
write-host "----- $source"
$y = $x[2..($x.length - 1)]
$y | % {write-host ' ' $_}
}
}
关于mercurial - 比较 Mercurial 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6388088/