Ganesh, thanks for the comments.
As I found out by myself in the meantime, my claim that "(a) using the
index in the IgnoreIndex case can be replaced by passing the pending_tree
instead" is not fully correct and the resulting code changes may perhaps
break things. More on that below. I think the second statement (b) is
correct and the only possible explanation I have for why it doesn't lead
to misbehavior is that we duplicate some of the work of filtering out
irrelevant parts in other places e.g. command implementations.
Pushing this change to screened was premature and I regret having done
so. (The same goes for the "resolve issue1959" patch which prompted this
refactor.) Even though they pass the test suite that doesn't tell us much
because when the test suite is run we set "ALL --ignore-times" which
means we don't use the index... except that this option is not honored by
all commands and not all the functions exported by Darcs.Repository.State
give us the possibility to avoid access to the index.
In other words: this is a big and ugly mess and cleaning it up is slow
going.
The main problem for me was to reverse engineer a clear specification of
what "I.readIndex >>= updateIndex" is supposed to give back as a result
i.e. an equivalent IO action that does not involve the index. I currently
believe that this may capture it:
If pending_tree is the recorded state with the pending patch applied,
then we have
I.readIndex >>= updateIndex
===
do
guide <- expand pending_tree
expand =<< restrict guide <$> readPlainTree (repoLocation repo)
We don't use it like that, though. Instead we have another TreeFilter in
between in case we want to restrict the operation to a list of paths
given by the user. So in practice it's rather
I.readIndex >>= updateIndex . applyTreeFilter treeFilter
===
do
guide <- expand pending_tree
expand =<< applyTreeFilter treeFilter . restrict guide <$>
readPlainTree (repoLocation repo)
I found this out by modifying the code so that it always does /both/
versions, then asserts equality of the two resulting trees (using their
set of paths to determine equality). This allowed me to use the test
suite as a comprehensive source of inputs and still be independent of the
--ignore-times option.
My problem now is that I am reluctant to throw this code away as it is
very useful and also documents the behavior nicely. OTOH, we don't want
to keep it in the main code path because it duplicates work and doesn't
allow us to fix issue1959. Any idea? Perhaps I should disable the
unwanted code with a global constant.
I am not sure what to do with this patch as it is. I am considering a
rollback.
|