Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gitoxide-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ organize = ["dep:gix-url", "dep:jwalk"]
## Derive the amount of time invested into a git repository akin to [git-hours](https://github.com/kimmobrunfeldt/git-hours).
estimate-hours = ["dep:fs-err", "dep:crossbeam-channel", "dep:smallvec"]
## Gather information about repositories and store it in a database for easy querying.
query = ["dep:rusqlite", "dep:crossbeam-channel"]
query = ["dep:rusqlite"]
## Run algorithms on a corpus of repositories and store their results for later comparison and intelligence gathering.
## *Note that* `organize` we need for finding git repositories fast.
corpus = ["dep:rusqlite", "dep:sysinfo", "organize", "dep:crossbeam-channel", "dep:serde_json", "dep:tracing-forest", "dep:tracing-subscriber", "tracing", "dep:parking_lot"]
Expand Down
7 changes: 3 additions & 4 deletions gitoxide-core/src/corpus/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
version int
)"#;
con.execute_batch(meta_table)?;
let version: Option<i64> = con.query_row("SELECT version FROM meta", [], |r| r.get(0)).optional()?;
let version = version.map(|v| v as usize);
let version: Option<usize> = con.query_row("SELECT version FROM meta", [], |r| r.get(0)).optional()?;
match version {
None => {
con.execute("INSERT into meta(version) values(?)", params![VERSION as i64])?;
con.execute("INSERT into meta(version) values(?)", params![VERSION])?;
}
Some(version) if version != VERSION => match con.close() {
Ok(()) => {
Expand Down Expand Up @@ -213,7 +212,7 @@ impl Engine {
repository: Id,
) -> anyhow::Result<Run> {
let insertion_time = std::time::UNIX_EPOCH.elapsed()?.as_secs();
let id = con.query_row("INSERT INTO run (gitoxide_version, runner, task, repository, insertion_time) VALUES (?1, ?2, ?3, ?4, ?5) RETURNING id", params![gitoxide_version, runner, task, repository, insertion_time as i64], |r| r.get(0))?;
let id = con.query_row("INSERT INTO run (gitoxide_version, runner, task, repository, insertion_time) VALUES (?1, ?2, ?3, ?4, ?5) RETURNING id", params![gitoxide_version, runner, task, repository, insertion_time], |r| r.get(0))?;
Ok(Run {
id,
duration: Default::default(),
Expand Down
8 changes: 4 additions & 4 deletions gitoxide-core/src/corpus/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ impl Engine {
Ok(db::Repo {
id: r.get(0)?,
path: corpus_path.join(r.get::<_, String>(1)?),
odb_size: ByteSize(r.get::<_, i64>(2)? as u64),
num_objects: r.get::<_, i64>(3)? as u64,
num_references: r.get::<_, i64>(4)? as usize,
odb_size: ByteSize(r.get(2)?),
num_objects: r.get(3)?,
num_references: r.get(4)?,
})
})?
.inspect(|_| self.state.progress.inc())
Expand Down Expand Up @@ -313,7 +313,7 @@ impl Engine {
match repo_res {
Ok(mut repo) => {
let rela_path = repo.path.strip_prefix(corpus_path)?;
repo.id = statement.query_row(params![rela_path.to_str().context("only valid UTF8 is allowed for repository paths")?, corpus_id, repo.odb_size.as_u64() as i64, repo.num_objects as i64, repo.num_references as i64], |r| r.get(0))?;
repo.id = statement.query_row(params![rela_path.to_str().context("only valid UTF8 is allowed for repository paths")?, corpus_id, repo.odb_size.as_u64(), repo.num_objects, repo.num_references], |r| r.get(0))?;
out.push(repo);
progress.inc();
}
Expand Down
7 changes: 3 additions & 4 deletions gitoxide-core/src/query/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
version int
)"#;
con.execute_batch(meta_table)?;
let version: Option<i64> = con.query_row("SELECT version FROM meta", [], |r| r.get(0)).optional()?;
let version = version.map(|v| v as usize);
let version: Option<usize> = con.query_row("SELECT version FROM meta", [], |r| r.get(0)).optional()?;
match version {
None => {
con.execute("INSERT into meta(version) values(?)", params![VERSION as i64])?;
con.execute("INSERT into meta(version) values(?)", params![VERSION])?;
}
Some(version) if version != VERSION => match con.close() {
Ok(()) => {
Expand All @@ -28,7 +27,7 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
})?;
con = rusqlite::Connection::open(path)?;
con.execute_batch(meta_table)?;
con.execute("INSERT into meta(version) values(?)", params![VERSION as i64])?;
con.execute("INSERT into meta(version) values(?)", params![VERSION])?;
}
Err((_, err)) => return Err(err.into()),
},
Expand Down
8 changes: 4 additions & 4 deletions gitoxide-core/src/query/engine/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl query::Engine {
.query_row(
"SELECT file_id FROM files WHERE file_path = ?",
params![relpath.to_str_lossy()],
|r| r.get::<_, i64>(0).map(|v| v as usize),
|r| r.get(0),
)
.optional()?
.with_context(|| format!("Path '{relpath}' not found anywhere in recorded history"))?;
Expand All @@ -62,8 +62,8 @@ impl query::Engine {
let mut progress = progress.add_child("run sql query");
progress.init(None, gix::progress::count("round"));
while let Some(file_id) = stack.pop() {
let rows = by_file_id.query_map([file_id as i64], |r| {
Ok((r.get(0)?, r.get::<_, i64>(1)? as usize, r.get::<_, Option<i64>>(2)?.map(|v| v as usize), r.get(3)?, r.get::<_, i64>(4)? as usize, r.get::<_, i64>(5)? as usize))
let rows = by_file_id.query_map([file_id], |r| {
Ok((r.get(0)?, r.get(1)?, r.get(2)?, r.get(3)?, r.get(4)?, r.get(5)?))
})?;
progress.inc();
for row in rows {
Expand Down Expand Up @@ -92,7 +92,7 @@ impl query::Engine {
if let Some(source_id) = source_file_id {
if let std::collections::hash_map::Entry::Vacant(e) = seen.entry(source_id) {
stack.push(source_id);
e.insert(path_by_id.query_row([source_id as i64], |r| r.get(0))?);
e.insert(path_by_id.query_row([source_id], |r| r.get(0))?);
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions gitoxide-core/src/query/engine/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ pub fn update(
let start = Instant::now();
let (tx_stats, rx_stats) = std::sync::mpsc::channel::<Result<(SequenceId, Vec<CommitDiffStats>), Infallible>>();

let mut all_commits = Vec::with_capacity(con.query_row("SELECT COUNT(hash) from commits", [], |r| {
r.get::<_, i64>(0).map(|v| v as usize)
})?);
let mut all_commits =
Vec::with_capacity(con.query_row("SELECT COUNT(hash) from commits", [], |r| r.get::<_, usize>(0))?);
for item in con
.prepare("SELECT hash from commits ORDER BY ROWID")?
.query_map([], |r| {
Expand Down Expand Up @@ -110,23 +109,23 @@ pub fn update(
id.as_bytes(),
change.relpath.to_str_lossy(),
has_diff,
lines.added as i64,
lines.removed as i64,
lines.before as i64,
lines.after as i64,
change.mode as i64,
lines.added,
lines.removed,
lines.before,
lines.after,
change.mode as usize,
source_relpath.to_str_lossy(),
])?;
} else {
insert_commit_file.execute(params![
id.as_bytes(),
change.relpath.to_str_lossy(),
has_diff,
lines.added as i64,
lines.removed as i64,
lines.before as i64,
lines.after as i64,
change.mode as i64,
lines.added,
lines.removed,
lines.before,
lines.after,
change.mode as usize,
])?;
}
}
Expand Down Expand Up @@ -418,9 +417,12 @@ pub fn update(
});
}
if self.chunk.borrow().len() == self.chunk_size {
let chunk =
std::mem::replace(&mut *self.chunk.borrow_mut(), Vec::with_capacity(self.chunk_size));
self.tx.send((*self.chunk_id.borrow(), chunk)).ok();
self.tx
.send((
*self.chunk_id.borrow(),
std::mem::replace(&mut self.chunk.borrow_mut(), Vec::with_capacity(self.chunk_size)),
))
.ok();
*self.chunk_id.borrow_mut() += 1;
}
}
Expand Down