Recovering from a deleted store/data/*i file (or merging commits of two "unrelated" repositories containg the same files?)

Benito van der Zander benito at benibela.de
Sat Nov 3 17:07:51 UTC 2012


>
> Perhaps use a bash script to do that from the wiki for the first 4 years 
Finally, managed to write it:

export OLDHG=/pathToDamagedRepository 
OKHG=pathToPartialUndamanagedRepository FIXHG=pathToTemporaryDirectory

#find the damaged revisions and files
cd $OLDHG
hg verify 2>&1 | grep "in manifests not found" | grep -oE "@[0-9]+:" | 
grep -oE [0-9]+ | sort -n | uniq > /tmp/damagedrevs
hg verify 2>&1 | grep "in manifests not found" | grep -oE "^.*@" | sort 
| uniq | grep -oE "^[^@]+" > /tmp/damagedfiles
#get the file names of the revlog files
sed -Ee 's/([_A-Z])/_\1/g' < /tmp/damagedfiles > 
/tmp/damagedfilescasefolded

#get the log of the undamaged repository
hg log -R $OKHG > /tmp/oklog

#make a clone of the damaged repository up to (excluding) the first 
damaged revision in $FIXHG
head -1 /tmp/damagedrevs | sed -Ee 's/([0-9]+)/\1 - 1/ ' | bc | xargs 
-I{} hg clone -r {} $OLDHG $FIXHG; cd $FIXHG

#now process all damaged revisions
while read REV; do
   echo; echo
   echo FIXING REVISION $REV

   #pull everything till the revision before the damage one
   hg pull  -r $((REV-1))  $OLDHG
   hg update

   #get the summary and date of the old log and search the corresponding 
changeset in the undamaged repository
   hg log -R $OLDHG -r $REV | grep summary: | sed -e "s/summary: *//" | 
xargs -d \\n -I{} grep -F -B 6 {} /tmp/oklog > /tmp/currevpre
   hg log -R $OLDHG -r $REV | grep date: | sed -e "s/date: *//" | xargs 
-d \\n -I{} grep -F -B 5 {} /tmp/currevpre > /tmp/currev
   #check that at least one matching changeset has been found
   LINES=`wc -l /tmp/currev | grep -oE [0-9]+ `
   if [ $LINES -lt 6 ]; then echo FAILED TO FIND REVISION; hg log -R 
$OLDHG -r $REV; break; fi
   #update the undamaged repository to that revision
   cat /tmp/currev | grep changeset | tail -1 | sed -e "s/changeset: 
*//" | xargs -I{} hg update -r {} -R $OKHG

   #copy the files from the undamaged repository to the temporary one
   xargs -I{} cp $OKHG/{} $FIXHG/{} < /tmp/damagedfiles
   #commit the files
   xargs -I{} hg add $FIXHG/{} < /tmp/damagedfiles
   hg commit -m fix  || (echo FAILED TO COMMIT; break )

   #copy the revlogs created for this changelog in the undamaged repository
   xargs -I{} cp  $FIXHG/.hg/store/data/{}.i $OLDHG/.hg/store/data/{}.i 
2> /dev/null < /tmp/damagedfilescasefolded
   xargs -I{} cp  $FIXHG/.hg/store/data/{}.d $OLDHG/.hg/store/data/{}.d 
2> /dev/null < /tmp/damagedfilescasefolded

   #revert the commit
   hg rollback > /dev/null
   hg revert --all > /dev/null

   #pull the now fixed commit from the damaged repository
   hg pull  -r $REV  $OLDHG || (echo FAILED TO PULL; break)
   hg update || (echo FAILED TO UPDATE; break)

done < /tmp/damagedrevs




On 10/24/2012 07:00 PM, Benito van der Zander wrote:
>> It is, but so are backups and/or clones.
> That repository was supposed to be the backup!
>
> And a clone was there, but did not help, because I did a "locate 
> filename | grep .o | xargs rm"...
>> MQ does not guarantee perfect round-trip integrity (due to limitations
>> of existing patch formats).
> But the data (file changes, time, commit message) will all be there?
>
> I just noticed that I don't have the last 2 weeks of file content, so 
> restoring the revlog will not work anyways...
>
> Perhaps use a bash script to do that from the wiki for the first 4 
> years and then use MQ for the last weeks
>
>
>
> On 10/23/2012 05:04 PM, Matt Mackall wrote:
>> On Tue, 2012-10-23 at 14:38 +0200, Benito van der Zander wrote:
>>>> Someone who understands what they're doing could probably 
>>>> accomplish it
>>>> with the convert tool or possibly the dump/undump tools, provided all
>>>> the necessary data exists somewhere. That's either you (after some
>>>> research) or some expert you pay $$$.
>>> I hoped someone had already a tool for that, lying somewhere online 
>>> around
>>>
>>> An accidentally deleted file is not so uncommon, is it?
>> It is, but so are backups and/or clones.
>>
>>>> If you want to do it yourself, I recommend you start by reading this
>>>> stuff:
>>>>
>>>> http://mercurial.selenic.com/wiki/Revlog
>>>> http://mercurial.selenic.com/wiki/RevlogNG
>>>> http://mercurial.selenic.com/wiki/Presentations?action=AttachFile&do=view&target=ols-mercurial-paper.pdf 
>>>>
>>>> http://www.selenic.com/hg/file/default/contrib/dumprevlog
>>> Or dump everything with the MQ extension and fix it there?
>>> At least I have looked at that file format before
>> MQ does not guarantee perfect round-trip integrity (due to limitations
>> of existing patch formats).
>>
>
>
> _______________________________________________
> Mercurial mailing list
> Mercurial at selenic.com
> http://selenic.com/mailman/listinfo/mercurial
>




More information about the Mercurial mailing list