Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically trigger Hg repository verification before pushing/pulling, without programming

We discovered that our Hg repository got corrupted several weeks ago. This corruption seems to have propagated: all clones (the central repo and the user repos) are corrupted, pretty badly, in the same way. I think we could have prevented it if we did verification at that time.

Is there some Hg setting that would cause verification on each push, and prevent push in case of verification failure? I know I could implement it as a hook in Python, but is there maybe a simpler solution?

Is it also possible to do the opposite: make sure the remote repository is verified before pulling?

FWIW, I am on Windows 10 and we are using TortoiseHg.

Update: I've tried creating hooks as suggested by Jordi. Hg now hangs waiting for locks. Here is what I see:

c:\Users\username\test-hook>hg init
c:\Users\username\test-hook>cd ..
c:\Users\username>hg clone test-hook test-hook-clone
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved

# At this point I edited clone repository settings to include
# [hooks]
# preoutgoing = hg verify
#
# Then I created a test.txt file and "added" it via TortoiseHg context menu.

c:\Users\username\test-hook-clone>hg commit
c:\Users\username\test-hook-clone>hg status

c:\Users\username\test-hook-clone>hg outgoing
comparing with c:\Users\username\test-hook
searching for changes
changeset:   0:a61d33af6cdb
tag:         tip
user:        username
date:        Mon May 06 20:32:54 2019 +0200
summary:     test file added

c:\Users\username\test-hook-clone>hg push -verbose
pushing to c:\Users\username\test-hook
searching for changes
running hook preoutgoing: hg verify
waiting for lock on repository c:\Users\username\test-hook-clone held by process '16840' on host 'LT407233'
like image 219
texnic Avatar asked Jun 07 '26 06:06

texnic


1 Answers

To answer your question, the hook does not have to be written in Python. In the appropriate server's hgrc (either at the repository level or the system level), simply set

[hooks]
preoutgoing = hg verify
preincoming = hg verify

This may significantly slow down all pull and push operations, but perhaps you are willing to sacrifice speed for correctness.

This will result in output like this when a client tries to pull from a corrupt repo:

$ hg clone http://localhost:9000 sample-repo
requesting all changes
remote: abort: preoutgoing hook exited with status 1

and in your server logs, you should see output similar to

127.0.0.1 - - [18/Apr/2019 12:41:09] "GET /?cmd=batch HTTP/1.1" 200 - x-hgarg-1:cmds=lheads+%3Bknown+nodes%3D x-hgproto-1:0.1 0.2 comp=zstd,zlib,none,bzip2 partial-pull
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
 a@0: broken revlog! (index data/a.i is corrupted)
warning: orphan data file 'data/a.i'
checked 2 changesets with 1 changes to 2 files
1 warnings encountered!
1 integrity errors encountered!
(first damaged changeset appears to be 0)
like image 110
Jordi Gutiérrez Hermoso Avatar answered Jun 10 '26 11:06

Jordi Gutiérrez Hermoso



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!