-- For a given file name, find all changes in the history of
-- that file, stopping at the point where it was added or
-- renamed.
SELECT
substr(b.uuid,0,12) as manifestUuid,
datetime(p.mtime) as manifestTime,
--       ml.*,
ml.mid AS manifestRid,
b.size AS manifestSize,
ml.pid AS parentManifestRid,
ml.fid AS fileContentRid
-- fileContentRid=0 if renamed/removed. The fields (manifestUuid,
-- manifestTime, manifestRid, manifestSize, prevFileContentRid) will match at the rename
-- point across this query and the same query against the renamed
-- file. Only the
-- (fileContentRid, filename) differ across the rename-point records.
-- renamed.fileContentRid = orig.prevFileContentRid if no changes were
-- made to the file between moving and committing.
,
ml.pid AS prevFileContentRid
  -- prevFileContentRid=0 at start of history,
  -- prevFileContentRid=fileContentRid for a file which was just
  -- renamed UNLESS it was modified after the rename, in which case...
  -- 
,
fn.name AS filename
FROM
mlink ml,
filename fn,
blob b,
plink p
WHERE
fn.name
    -- IN('f-status.c', 'f-apps/f-status.c')
    GLOB '*f-status.c'
    -- = 'test.c'
    -- = 'f-status.c' -- was renamed/moved to...
    -- = 'f-apps/f-status.c' -- was target of ^^^^ that rename
    -- = 'src/fsl_io.c' -- short history
    -- = 'Makefile.in' -- long history with merge
AND ml.fnid=fn.fnid
AND ml.mid=b.rid
AND p.cid=ml.mid -- renamed file will have non-0 here
ORDER BY manifestTime DESC
;
