Almost time to refactor this library already, as implementing this surfaced how it could be done better. But for now, calling the inlineCredit function exposed by the node module will give the correct hash (!!!) for a given file/line :)
LQ3SUK3P3KXY5CQA552EJGFH2MESGNHKK4YZTIKOGFJAKVBMHHUQC
let write_txn = txn.write();
let mut record_builder = RecordBuilder::new();
record_builder.record(
txn.clone(),
libpijul::Algorithm::default(),
false,
&libpijul::DEFAULT_SEPARATOR,
channel.clone(),
&repo.working_copy,
&repo.changes,
&prefix,
std::thread::available_parallelism()?.into(),
)?;
let recorded = record_builder.finish();
let mut write_txn = txn.write();
let actions: Vec<_> = recorded
.actions
.into_iter()
.map(|rec| rec.globalize(&*write_txn).unwrap())
.collect();
let contents = if let Ok(cont) = std::sync::Arc::try_unwrap(recorded.contents) {
cont.into_inner()
} else {
unreachable!()
};
let mut change = LocalChange::make_change(
&*write_txn,
&channel,
actions,
contents,
ChangeHeader::default(),
Vec::new(),
)?;
for (change_id, lines) in credit_buffer.changes {
let hash = txn.read().get_external(&change_id)?.unwrap().to_owned();
hashes.push((Hash::from(hash), lines));
let mut changes: Vec<Change> = Vec::new();
for (change_id, lines) in credit_buffer.hashes {
let hash = Hash::from(txn.read().get_external(&change_id)?.unwrap().to_owned());
let change = repo.changes.get_change(&hash)?;
if !changes.iter().any(|c| c.hash().unwrap() == hash) {
changes.push(change);
}
hashes.push((hash, lines));
fn inline_credit(mut cx: FunctionContext) -> JsResult<JsString> {
let path: Handle<JsString> = cx.argument(0)?;
let path = PathBuf::from(path.value(&mut cx));
let target_line: Handle<JsNumber> = cx.argument(1)?;
let target_line: f64 = target_line.value(&mut cx);
assert!(target_line.is_finite());
assert_eq!(target_line.round(), target_line);
let target_line: u64 = target_line as u64;
let (changes, hashes) = file_credits(path).unwrap();
let mut current_line: u64 = 0;
for (hash, line_count) in hashes {
if (current_line..current_line + line_count).contains(&target_line) {
return Ok(cx.string(format!("{hash:?}")));
}
current_line += line_count;
}
Ok(cx.string("Inline diff error"))
}