比较Mercurial回购 [英] Compare Mercurial Repos

查看:63
本文介绍了比较Mercurial回购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows工作站上有一堆Mercurial存储库.我们是一家小商店,有时候(通常是糟糕的日子),我可能会在我的六个或更多项目中进行更改/错误修复.其中一些项目处于维护模式,每个月只接触一次.当然,有时我会在被推送到中央Hg服务器之前被打断.

I have a bunch of Mercurial repositories on my Windows workstation. We're a small shop, and on some days (usually bad ones) I may make changes / bug fixes in half a dozen or more of my projects. Some of these projects are in maintenance mode, they're only touched once a month or so. Of course, I sometimes get interrupted before I get to push to our central Hg server.

有没有一种简单的方法可以定期将一堆仓库与中央服务器进行比较?如果我有尚未推送的更改,它应该警告我.理想情况下,位于系统托盘中的东西会按照本地更改时间早于48小时而不在远程回购中"的方式发出警报.

Is there an easy way to regularly compare a bunch of my repos with the central server? It should warn me if I have changes that haven't been pushed. Ideally, something that sits in the system tray and alerts along the lines of "Local change older than 48 hours not in remote repo."

我想我应该设置一个脚本来检查我的存储库并进行比较.我可以养成每天运行脚本的习惯.

I suppose I should just set up a script to go through my repos and compare them. I could get in the habit of running the script daily.

有想法吗?

推荐答案

我在Powershell配置文件中使用了辅助函数.在其他脚本语言中,它们很容易,尽管我不敢在.bat或.cmd文件中做到这一点.

I use helper functions in my Powershell profile. They're easy enough in other scripting languages, though I wouldn't dare to do it in .bat or .cmd files.

我保存了一个文件D:\repos.config,其中列出了我想快速浏览的所有本地存储库的绝对路径的列表,其中包括三件事:状态摘要,传入更改,传出更改.以下示例假定文件包含以下内容:

I keep a file D:\repos.config with a list of the absolute paths of all the local repositories I want to quickly glance at for 3 things: status summary, incoming changes, outgoing changes. Examples that follow assume a file with these contents:

D:\repository1
D:\repository2
#D:\ignoredrepo
D:\repository3
D:\repository4

为了检查状态,脚本会执行$results = hg -R $path st来获取状态列表,然后我只计算第一个字符,为每个存储库路径打印1行作为回购路径,并为状态摘要打印1行(如果有任何要显示):

For checking the status, the script does $results = hg -R $path st to get the status list and then I count first-characters only, printing 1 line for the repo path and 1 line for status summary for each repository path (if there's anything to show):

----- D:\repository1
  M 1 - A 1
----- D:\repository4
  ? 3

对于传入/传出,我将我的[paths]放在每个存储库的hgrc中保持一致,以便default始终是服务器上的存储库,bb是bitbucket上的存储库,依此类推.相同的路径列表,执行$results = hg -R $path $type $alias --template '{rev} {node|short} {desc|firstline}\n' for each. $ type is either in or out depending on which I've called and $ alias is the path alias that should be in each repo's hgrc (empty string for default , bb , backup , etc.). I do a little processing of $ results , since the first 2 lines are not actual changesets. You'd probably want {date | age} or {date | shortdate}`,如果您想过滤掉少于24小时的内容.

For incoming/outgoing, I keep my [paths] in each repository's hgrc concistent so that the default is always the repository on our server, bb is the one on bitbucket, etc. I loop through the same list of paths, executing $results = hg -R $path $type $alias --template '{rev} {node|short} {desc|firstline}\n' for each.$typeis eitherinoroutdepending on which I've called and$aliasis the path alias that should be in each repo'shgrc(empty string fordefault,bb,backup, etc.). I do a little processing of$results, since the first 2 lines are not actual changesets. You'd probably want{date|age}or{date|shortdate}` in your template if you wanted to filter out anything less than 24 hours old.

这样,我可以在提示符下简单地编写hgouts bb,并查看简洁的输出.某些存储库根本没有特定的别名,因此2>$null有助于防止某些abort: repository bb not found!消息.

This way I can write simply hgouts bb at the prompt and see concise output. Some repositories don't have a particular alias at all, so 2>$null helps prevent some abort: repository bb not found! messages.

----- 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 -uhg -R $path push,或者使用脚本的某些位来选择性地仅拉/推那些在工作目录中没有更改的内容,也不会很复杂.只是我还不需要.

As for synchronizing multiple repositories, I'm satisfied enough with TortoiseHg 2.0 and its Repository Registry to help me do them 1 at a time after I use the script to tell me which ones I need to do. But it also wouldn't be terribly complicated to loop through the paths and hg -R $path pull -u or hg -R $path push en masse, or use bits of the script to selectively pull/push only what's needed that doesn't have changes in the working directory. It's just not something I've needed yet.

编辑:我花了一些时间整理一下代码.函数hghg是状态摘要,而函数hgins [alias] hgouts [alias] 是我在提示符下实际调用的. /p>

Edit: I took a bit of time to clean up the code just a little. The functions hghg is the status summary, and the functions hgins[alias] and hgouts[alias] are what I actually call from the prompt.

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回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆