KGM44JFVCAMKTJM6I7VX6PNNKHVWY3MMXW46IWB2NGECZFST7SHQC
47DXBIWXK2U3VJZW5V4XZEARZBV4H3WG375BN4OWW5XY5DN42GEQC
S34LGQX3XOVZUKWNE2YQNB3LJPXBBHP5GUYPYGTBFV63HYBLTQWAC
BS2SCVKJS7HVJDGBLKPURU75NGJGH5YQ2KDAT6QNEYGUJBVS6FUQC
B7YKJDKD7ZQ2JV4FLKZUHMIH6BQXH57ALGQOGQ4YTFGITBYMWY4QC
37UOV7PCILKVEPDUBJHLHBZEOTQ5NX5FCV6MQWTRY5GM5KXZNDGAC
LSSPVZONPCHHLOWSJWORILOV6ZP55Q4DFIX47J7YG3VCHQCA6SBAC
LQ3SUK3P3KXY5CQA552EJGFH2MESGNHKK4YZTIKOGFJAKVBMHHUQC
fn is_current_state(&self, hash: &Hash) -> bool {
self.current_state
.hash()
.map(|h| &h == hash)
.unwrap_or(false)
}
}
// TODO: Refactor repository setup into separate module to prevent code duplication
pub fn file_credits(path: PathBuf) -> Result<FileState, anyhow::Error> {
let repo = Repository::find_root(Some(path.to_owned())).expect("Could not find root");
let txn = repo.pristine.arc_txn_begin()?;
let channel_name = txn
.read()
.current_channel()
.unwrap_or(libpijul::DEFAULT_CHANNEL)
.to_string();
pub fn new(path: PathBuf) -> Result<Self, anyhow::Error> {
let repo = Repository::find_root(Some(path.to_owned())).expect("Could not find root");
let txn = repo.pristine.arc_txn_begin()?;
let channel_name = txn
.read()
.current_channel()
.unwrap_or(libpijul::DEFAULT_CHANNEL)
.to_string();
let channel = txn.write().open_or_create_channel(&channel_name)?;
let prefix = path.strip_prefix(&repo.path)?.to_string_lossy().to_string();
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(),
)?;
let channel = txn.write().open_or_create_channel(&channel_name)?;
let prefix = path.strip_prefix(&repo.path)?.to_string_lossy().to_string();
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(),
)?;
repo.changes
.save_change(&mut change, |_, _| Ok::<_, anyhow::Error>(()))?;
write_txn.apply_change(&repo.changes, &mut channel.write(), &change.hash()?)?;
repo.changes
.save_change(&mut change, |_, _| Ok::<_, anyhow::Error>(()))?;
write_txn.apply_change(&repo.changes, &mut channel.write(), &change.hash()?)?;
let mut credit_buffer = InlineCreditBuffer::new()?;
libpijul::output::output_file(
&repo.changes,
&txn,
&channel,
oldest_change,
&mut credit_buffer,
)?;
let mut credit_buffer = InlineCreditBuffer::new()?;
libpijul::output::output_file(
&repo.changes,
&txn,
&channel,
oldest_change,
&mut credit_buffer,
)?;
let mut hashes = Vec::new();
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);
let mut hashes = Vec::new();
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));
// Make sure to not pollute .pijul/changes
repo.changes.del_change(&change.hash()?)?;
// TODO: State::Ignored
fn annotate(&self) -> State {
let mut annotations = Vec::new();
for change in &self.current_state.changes {
match change {
BaseHunk::Edit { .. } | BaseHunk::Replacement { .. } => {
annotations.push(Annotation::Modified);
}
BaseHunk::FileAdd { .. } => {
return State::Added;
}
_ => todo!(),
}
}