Skip to content

Instantly share code, notes, and snippets.

@qbikez qbikez/clone-hg.ps1
Last active Feb 22, 2016

Embed
What would you like to do?
a script to incrementally clone hg repo (for HUUGE repos)
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]$repo,
[Parameter(Mandatory=$true)]$targetdir,
$offset = 0,
$batchsize = 50,
$total = 40000
)
pushd
try {
if (!(test-path $targetdir)) {
write-verbose "cloning $repo to $targetdir"
hg clone $repo --rev 0 $targetdir
}
else {
if (!(test-path "$targetdir\.hg")) {
write-warning "directory $targetdir, but it doesn't look like hg repo. try specifying a directory that does not exist"
return
}
else {
write-verbose "repo at $targetdir already exists. pulling"
}
}
cd $targetdir
if (test-path ".pullstate") {
try {
$offset = (get-content ".pullstate" | out-string)
$offset = [int]$offset
} catch {
}
}
$ok = $true
$dir = pwd
write-verbose "pulling in $dir"
for($i = $offset; $ok -and $i -lt $total; $i+= $batchsize) {
write-progress "pulling rev $i/$total" -PercentComplete ($i/[float]$total * 100)
hg pull -r $i
if ($LASTEXITCODE -ne 0) {
$ok = $false
} else {
$i | out-file ".pullstate"
}
}
} finally {
popd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.