dirstate: add --minimal flag to debugrebuilddirstate
On repositories with hundreds of thousands of files, hg
debugrebuilddirstate causes every dirstate entry to be marked lookup,
and the next hg status can take many minutes.
This adds a --minimal flag that allows us to only rebuild the parts of the
dirstate that are inconsistent. This follows two rules:
1) If a file is in the dirstate but not in the parent manifest, and it is not
marked 'add', it is busted and we should drop it.
2) If a file is not in the dirstate at all, but it is in the parent
manifest, it should be added to the dirstate and we need to mark it as
lookup.
This allows us to fix repositories where the dirstate doesn't match
the manifest much more quickly.
Tested by artificially adding bad dirstate entries (via code) for both cases
above.
Test issue2761
$ hg init
$ touch to-be-deleted
$ hg add
adding to-be-deleted
$ hg ci -m first
$ echo a > to-be-deleted
$ hg ci -m second
$ rm to-be-deleted
$ hg diff -r 0
Same issue, different code path
$ hg up -C
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ touch does-not-exist-in-1
$ hg add
adding does-not-exist-in-1
$ hg ci -m third
$ rm does-not-exist-in-1
$ hg diff -r 1