-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix VC history operation and add VC tests #49
Conversation
@@ -340,87 +339,63 @@ fetchVCObjectHistory h = do | |||
head_h <- fetchCurrentHead h | |||
let head_fp = storePath </> "heads" </> show head_h | |||
preds <- readVCObjectHashTxt head_fp | |||
pure $ head_h : preds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preds
is stored in file as oldest-to-newest so this line adds head_h
to the wrong end of the history.
-- 2. Ignore this meta. | ||
-- Approach no. 2 is taken here by just returning the accumulator. | ||
pure acc | ||
(metas, removeds) <- foldM f ([], []) history |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fold reverses order to newest-to-oldest (but the latest version is now at the end).
-- i.e. original -> cloneof orignal = cloned -> cloneof cloned = cloned' | ||
-- when viewing cloned' history, it will only show up to cloned. | ||
case metas of | ||
all'@(x : _) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern match is looking at the second newest version, not the oldest version as intended.
Thanks for the review! I noticed we don't have tests for inferno-vc anywhere so I added some simple tests. Hope it catches small bugs in the future. |
timestamp o' `shouldBe` timestamp o | ||
obj o' `shouldBe` obj o | ||
|
||
-- -- TODO is fetchFunctionsForGRoups wrong? It is returning deleted scripts: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@siddharth-krishna is this something that needs to be addressed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs more investigation, but it is unrelated to this PR (if it is a bug it's an existing bug). Maybe I'll open an issue to track it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I wonder if the tests can be written in a way that doesn't need to spin up a server?
This PR fixes three bugs in the
fetchVCObjectHistory
operation:The first is in the order of the history of a VC object. Currently, given a script with 4 versions
s1 -> s2 -> s3 -> s4
,fetchVCObjectHistory
returns[s3, s2, s1, s4]
. This is because we store history in oldest-to-newest order in file, but the following line addshead_h
(i.e. the latest versions4
) to the wrong end of the history list:inferno/inferno-vc/src/Inferno/VersionControl/Operations.hs
Lines 339 to 343 in 73c59f1
(the
foldM
below then reverses the order, but withs4
still in the wrong place)Even after fixing the above,
fetchVCObjectHistory
incorrectly adds a second source script in the case of a script that is cloned twice in succession. Consider the following history:In this case,
fetchVCObjectHistory cUpepL
returns[F6LRpH, mcJDUg, 4I47d_, cUpepL]
(after the above fix) but it should return[mcJDUg, 4I47d_, cUpepL]
. Interestingly, the above bug hides this bug in production right now because becausehistory = [cUpepL, mcJDUg, 4I47d_]
(incorrect), sometas = [4I47d_, mcJDUg, cUpepL]
and so when it finds that4I47d_,
is a clone it addsoriginal = mcJDUg
and returnsnubBy [mcJDUg, 4I47d_, mcJDUg, cUpepL] = [4I47d_, mcJDUg, cUpepL]
. But once I fixhistory = [cUpepL, 4I47d_, mcJDUg]
, thenmetas = [mcJDUg, 4I47d_, cUpepL]
andoriginal = F6LRpH
and the code returns[F6LRpH, mcJDUg, 4I47d_, cUpepL]
. This is incorrect because we only want to add on the original version of the first cloning operation when going back in history.While fixing this second bug, I also noticed that
nubBy
(a linear operation) is unnecessary, as one can simply recurse through history and stop when one sees the first cloning operation. I thus simplified the fold function and the large case-split into a single recursive functiongetHistory
that walks through history newest-to-oldest, fetches the VC objects, and stops when it sees a cloning operation.NOTE: This PR requires a code change downstream. There is a third issue with the current system: since the frontend requires the history in newest-to-oldest order, but the current code returns the order
[s3, s2, s1, s4]
, OnPing is reversing the order it gets from the VC to puts4
first. This PR fixes the VC to return history in newest-to-oldest order, so OnPing should not reverse the order that it gets.I also benchmarked a few different ways of doing this operation (see below) and found that the fastest way would be to use a recursive function instead of a fold, and return the history in newest-to-oldest order.
Test cases:
I tested the new code on the above histories (
heads/
files) and it returned the correct responses.Benchmarking different ways of recursing through history