Thursday, December 9, 2010

Git svn tree corruption

I use git over svn for all my subversion projects. This morning I hit the following problem:

$ git svn rebase
error: garbage at end of loose object 'd0df538270dcaf65a232fb4127b7c59212420129'
fatal: object d0df538270dcaf65a232fb4127b7c59212420129 is corrupted
diff-index HEAD --: command returned error: 128

Mmm no backup accessible right now, and no way I am pulling remotely a git svn for this 7 years old tree.

First let's find information on the commit.

$ mv .git/objects/d0/df538270dcaf65a232fb4127b7c59212420129 ../d0df538270dcaf65a232fb4127b7c59212420129
$ git fsck --full
broken link from tree 066ce753000ca9e1cfbd07a709cac4c7c3e5da47
to tree d0df538270dcaf65a232fb4127b7c59212420129
dangling tree 866d5ac672d6ef4009319e176f195fd01697165c
missing tree d0df538270dcaf65a232fb4127b7c59212420129

What does the previous tree contains ?

$ git ls-tree 066ce753000ca9e1cfbd07a709cac4c7c3e5da47
100755 blob 888ed870384e87dad0642199b4d7d938246946a8 xxx1
100755 blob 346bd13c9ba0d15046af891ccc88aa225d3c7ee3 xxx2
100755 blob 2eef3f1f2985ff1d9cdd4a23c8ebca54a9af1010 xxx3
100644 blob 6a501e34ee0fb197fa6770b2a8cc40cdf276607a xxx4
100755 blob fe61ef5d88201a7502057a2ff5fdd45db44f5075 xxx5
040000 tree 38354b54d3dca537d9c7c9d9ec1668c0c7287bc9 ddd1
040000 tree 50be3bfee5b37fc97b379ae04fe961a212a70a32 ddd2
040000 tree 6b108f1b534bb9465c2e31efe51d06fb05499376 ddd3
040000 tree 532a6da6ece3151b43a1cd0fd174fdadb071e402 ddd4
040000 tree 45363718750ed5142fad1d7be311581748057297 ddd5
040000 tree d0df538270dcaf65a232fb4127b7c59212420129 ddd6
040000 tree b77d3e9240185ed148727e01d4d03ad726411724 ddd7
040000 tree 8b69621e177132f3dc822c427501f1921f39bbe1 ddd8

Didn't help much.

In that SVN tree, my history is pretty linear. I try to find the commit before or after the one that fails:

$ git log --raw | grep svn+ssh | tail -1 | cut -d '@' -f 2
fatal: unable to read destination tree (d0df538270dcaf65a232fb4127b7c59212420129)
4321 20108eba-4dfa-0310-bbc5-8f3fd2a08cff

Log fails to find the full history, and I now know which commits maps to the broken tree: 4320: the one before the last succesffuly logged commit (4321).

Let's verify:

$ git svn find-rev r4320
$ git show 4e0264e69a5289c5ac5c461085c900009c90c5b9
fatal: unable to read destination tree (d0df538270dcaf65a232fb4127b7c59212420129)

Now let's just fetch some versions around that commit and replace our broken tree file.

$ svn clone svn+ssh:// -r 4318:4322 xxx2.git
$ mv xxx2.git/.git/objects/d0/df538270dcaf65a232fb4127b7c59212420129 .git/objects/d0/

Check the commit ?

$ git show 4e0264e69a5289c5ac5c461085c900009c90c5b9

git svn rebase now works !

1 comment:

  1. Nice! I ran into this problem a few weeks back, but ended up re-cloning the whole repository. I'll try this next time :)