Skip to content

Commit 3b1bef7

Browse files
authored
Merge pull request #1935 from pierrechevalier83/fix_1923
Make author and committer date roundtrip
2 parents 46227e6 + c3c6504 commit 3b1bef7

File tree

331 files changed

+2013
-1529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

331 files changed

+2013
-1529
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,7 @@ no_effect_underscore_binding = "allow" # x1
377377
empty_docs = "allow"
378378
too_long_first_doc_paragraph = "allow"
379379
large_stack_arrays = "allow"
380+
381+
# Fix one day
382+
result_large_err = "allow"
383+
large_enum_variant = "allow"

examples/log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn run(args: Args) -> anyhow::Result<()> {
150150
commit_ref.author.actor().write_to(&mut buf)?;
151151
buf.into()
152152
},
153-
time: commit_ref.author.time.format(format::DEFAULT),
153+
time: commit_ref.author.time()?.format(format::DEFAULT),
154154
message: commit_ref.message.to_owned(),
155155
})
156156
}),

gitoxide-core/src/corpus/engine.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ impl Engine {
5757
let repos = self.refresh_repos(&corpus_path, corpus_id)?;
5858
self.state.progress.set_name("refresh repos".into());
5959
self.state.progress.info(format!(
60-
"Added or updated {} repositories under {corpus_path:?}",
61-
repos.len()
60+
"Added or updated {} repositories under '{corpus_path}'",
61+
repos.len(),
62+
corpus_path = corpus_path.display(),
6263
));
6364
Ok(())
6465
}
@@ -316,7 +317,7 @@ impl Engine {
316317
out.push(repo);
317318
progress.inc();
318319
}
319-
Err(err) => progress.fail(format!("{repo_path:?}: {err:#?}")),
320+
Err(err) => progress.fail(format!("{repo_path}: {err:#?}", repo_path = repo_path.display())),
320321
}
321322
}
322323
statement.finalize()?;

gitoxide-core/src/hours/core.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MINUTES_PER_HOUR: f32 = 60.0;
1717
pub const HOURS_PER_WORKDAY: f32 = 8.0;
1818

1919
pub fn estimate_hours(
20-
commits: &[(u32, gix::actor::SignatureRef<'static>)],
20+
commits: &[(u32, super::SignatureRef<'static>)],
2121
stats: &[(u32, FileStats, LineStats)],
2222
) -> WorkByEmail {
2323
assert!(!commits.is_empty());
@@ -31,7 +31,7 @@ pub fn estimate_hours(
3131
let mut cur = commits.next().expect("at least one commit if we are here");
3232

3333
for next in commits {
34-
let change_in_minutes = (next.time.seconds.saturating_sub(cur.time.seconds)) as f32 / MINUTES_PER_HOUR;
34+
let change_in_minutes = (next.seconds().saturating_sub(cur.seconds())) as f32 / MINUTES_PER_HOUR;
3535
if change_in_minutes < MAX_COMMIT_DIFFERENCE_IN_MINUTES {
3636
hours += change_in_minutes / MINUTES_PER_HOUR;
3737
} else {
@@ -166,13 +166,11 @@ pub fn spawn_tree_delta_threads<'scope>(
166166
(true, true) => {
167167
files.modified += 1;
168168
if let Some(cache) = cache.as_mut() {
169-
let mut diff = change.diff(cache).map_err(|err| {
170-
std::io::Error::new(std::io::ErrorKind::Other, err)
171-
})?;
169+
let mut diff = change.diff(cache).map_err(std::io::Error::other)?;
172170
let mut nl = 0;
173-
if let Some(counts) = diff.line_counts().map_err(|err| {
174-
std::io::Error::new(std::io::ErrorKind::Other, err)
175-
})? {
171+
if let Some(counts) =
172+
diff.line_counts().map_err(std::io::Error::other)?
173+
{
176174
nl += counts.insertions as usize + counts.removals as usize;
177175
lines.added += counts.insertions as usize;
178176
lines.removed += counts.removals as usize;

gitoxide-core/src/hours/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{collections::BTreeSet, io, path::Path, time::Instant};
22

33
use anyhow::bail;
44
use gix::{
5-
actor,
65
bstr::{BStr, ByteSlice},
76
prelude::*,
87
progress, Count, NestedProgress, Progress,
@@ -27,6 +26,18 @@ pub struct Context<W> {
2726
pub out: W,
2827
}
2928

29+
pub struct SignatureRef<'a> {
30+
name: &'a BStr,
31+
email: &'a BStr,
32+
time: gix::date::Time,
33+
}
34+
35+
impl SignatureRef<'_> {
36+
fn seconds(&self) -> gix::date::SecondsSinceUnixEpoch {
37+
self.time.seconds
38+
}
39+
}
40+
3041
/// Estimate the hours it takes to produce the content of the repository in `_working_dir_`, with `_refname_` for
3142
/// the start of the commit graph traversal.
3243
///
@@ -85,7 +96,7 @@ where
8596

8697
out.push((
8798
commit_idx,
88-
actor::SignatureRef {
99+
SignatureRef {
89100
name,
90101
email,
91102
time: author.time,
@@ -97,7 +108,7 @@ where
97108
out.sort_by(|a, b| {
98109
a.1.email
99110
.cmp(b.1.email)
100-
.then(a.1.time.seconds.cmp(&b.1.time.seconds).reverse())
111+
.then(a.1.seconds().cmp(&b.1.seconds()).reverse())
101112
});
102113
Ok(out)
103114
});

gitoxide-core/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
#![deny(rust_2018_idioms)]
3131
#![forbid(unsafe_code)]
3232

33-
use anyhow::bail;
3433
use std::str::FromStr;
3534

35+
use anyhow::bail;
36+
3637
#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)]
3738
pub enum OutputFormat {
3839
Human,

gitoxide-core/src/organize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::borrow::Cow;
21
use std::{
2+
borrow::Cow,
33
ffi::OsStr,
44
path::{Path, PathBuf},
55
};
@@ -138,9 +138,9 @@ fn handle(
138138

139139
if let Some(parent_repo_path) = find_parent_repo(git_workdir) {
140140
progress.fail(format!(
141-
"Skipping repository at {:?} as it is nested within repository {:?}",
141+
"Skipping repository at '{}' as it is nested within repository '{}'",
142142
git_workdir.display(),
143-
parent_repo_path
143+
parent_repo_path.display()
144144
));
145145
return Ok(());
146146
}
@@ -157,7 +157,7 @@ fn handle(
157157
};
158158
if url.path.is_empty() {
159159
progress.info(format!(
160-
"Skipping repository at {:?} whose remote does not have a path: {:?}",
160+
"Skipping repository at '{}' whose remote does not have a path: {}",
161161
git_workdir.display(),
162162
url.to_bstring()
163163
));

gitoxide-core/src/pack/receive.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::net;
2-
use crate::pack::receive::protocol::fetch::negotiate;
3-
use crate::OutputFormat;
4-
use gix::config::tree::Key;
5-
use gix::protocol::maybe_async;
6-
use gix::remote::fetch::Error;
7-
use gix::DynNestedProgress;
1+
use std::{
2+
io,
3+
path::PathBuf,
4+
sync::{atomic::AtomicBool, Arc},
5+
};
6+
7+
use gix::{config::tree::Key, protocol::maybe_async, remote::fetch::Error, DynNestedProgress};
88
pub use gix::{
99
hash::ObjectId,
1010
objs::bstr::{BString, ByteSlice},
@@ -18,11 +18,8 @@ pub use gix::{
1818
},
1919
NestedProgress, Progress,
2020
};
21-
use std::{
22-
io,
23-
path::PathBuf,
24-
sync::{atomic::AtomicBool, Arc},
25-
};
21+
22+
use crate::{net, pack::receive::protocol::fetch::negotiate, OutputFormat};
2623

2724
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3;
2825
pub struct Context<W> {
@@ -294,7 +291,7 @@ fn receive_pack_blocking(
294291
None::<gix::objs::find::Never>,
295292
options,
296293
)
297-
.map_err(|err| io::Error::new(io::ErrorKind::Other, err))?;
294+
.map_err(io::Error::other)?;
298295

299296
if let Some(directory) = refs_directory.take() {
300297
write_raw_refs(refs, directory)?;

gitoxide-core/src/query/db.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ pub fn create(path: impl AsRef<std::path::Path>) -> anyhow::Result<rusqlite::Con
1919
}
2020
Some(version) if version != VERSION => match con.close() {
2121
Ok(()) => {
22-
std::fs::remove_file(path)
23-
.with_context(|| format!("Failed to remove incompatible database file at {path:?}"))?;
22+
std::fs::remove_file(path).with_context(|| {
23+
format!(
24+
"Failed to remove incompatible database file at {path}",
25+
path = path.display()
26+
)
27+
})?;
2428
con = rusqlite::Connection::open(path)?;
2529
con.execute_batch(meta_table)?;
2630
con.execute("INSERT into meta(version) values(?)", params![VERSION])?;

gitoxide-core/src/query/engine/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl query::Engine {
7676
usize,
7777
) = row?;
7878
let id = gix::ObjectId::from(hash);
79-
let commit_time = id.attach(&self.repo).object()?.into_commit().committer()?.time;
79+
let commit_time = id.attach(&self.repo).object()?.into_commit().committer()?.time()?;
8080
let mode = FileMode::from_usize(mode).context("invalid file mode")?;
8181
info.push(trace_path::Info {
8282
id,

gitoxide-core/src/repository/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn fetch_rev_info(
8484
Ok(match object.kind {
8585
gix::object::Kind::Commit => {
8686
let commit = object.into_commit();
87-
(Some(commit.committer()?.time.seconds), commit.tree_id()?.detach())
87+
(Some(commit.committer()?.seconds()), commit.tree_id()?.detach())
8888
}
8989
gix::object::Kind::Tree => (None, object.id),
9090
gix::object::Kind::Tag => fetch_rev_info(object.peel_to_kind(gix::object::Kind::Commit)?)?,

gitoxide-core/src/repository/attributes/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub struct Options {
88
}
99

1010
pub(crate) mod function {
11+
use std::{borrow::Cow, io, path::Path};
12+
1113
use anyhow::bail;
1214
use gix::bstr::BStr;
13-
use std::borrow::Cow;
14-
use std::{io, path::Path};
1515

1616
use crate::{
1717
is_dir_to_mode,

gitoxide-core/src/repository/attributes/validate_baseline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub(crate) mod function {
4444
if repo.is_bare() {
4545
writeln!(
4646
err,
47-
"Repo {:?} is bare - disabling git-ignore baseline as `git check-ignore` needs a worktree",
48-
repo.path()
47+
"Repo at '{repo}' is bare - disabling git-ignore baseline as `git check-ignore` needs a worktree",
48+
repo = repo.path().display()
4949
)
5050
.ok();
5151
ignore = false;

gitoxide-core/src/repository/blame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use gix::bstr::ByteSlice;
2-
use gix::config::tree;
31
use std::ffi::OsStr;
42

3+
use gix::{bstr::ByteSlice, config::tree};
4+
55
pub fn blame_file(
66
mut repo: gix::Repository,
77
file: &OsStr,

gitoxide-core/src/repository/cat.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use crate::repository::revision::resolve::{BlobFormat, TreeMode};
21
use anyhow::{anyhow, Context};
3-
use gix::diff::blob::ResourceKind;
4-
use gix::filter::plumbing::driver::apply::Delay;
5-
use gix::revision::Spec;
2+
use gix::{diff::blob::ResourceKind, filter::plumbing::driver::apply::Delay, revision::Spec};
3+
4+
use crate::repository::revision::resolve::{BlobFormat, TreeMode};
65

76
pub fn display_object(
87
repo: &gix::Repository,

gitoxide-core/src/repository/clean.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ pub struct Options {
2020
pub find_untracked_repositories: FindRepository,
2121
}
2222
pub(crate) mod function {
23-
use crate::repository::clean::{FindRepository, Options};
24-
use crate::OutputFormat;
23+
use std::{borrow::Cow, path::Path};
24+
2525
use anyhow::bail;
26-
use gix::bstr::BString;
27-
use gix::bstr::ByteSlice;
28-
use gix::dir::entry::{Kind, Status};
29-
use gix::dir::walk::EmissionMode::CollapseDirectory;
30-
use gix::dir::walk::ForDeletionMode::*;
31-
use gix::dir::{walk, EntryRef};
32-
use std::borrow::Cow;
33-
use std::path::Path;
26+
use gix::{
27+
bstr::{BString, ByteSlice},
28+
dir::{
29+
entry::{Kind, Status},
30+
walk,
31+
walk::{EmissionMode::CollapseDirectory, ForDeletionMode::*},
32+
EntryRef,
33+
},
34+
};
35+
36+
use crate::{
37+
repository::clean::{FindRepository, Options},
38+
OutputFormat,
39+
};
3440

3541
pub fn clean(
3642
repo: gix::Repository,

gitoxide-core/src/repository/diff.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
use anyhow::Context;
2-
use gix::bstr::{BString, ByteSlice};
3-
use gix::diff::blob::intern::TokenSource;
4-
use gix::diff::blob::unified_diff::{ContextSize, NewlineSeparator};
5-
use gix::diff::blob::UnifiedDiff;
6-
use gix::objs::tree::EntryMode;
7-
use gix::odb::store::RefreshMode;
8-
use gix::prelude::ObjectIdExt;
9-
use gix::ObjectId;
2+
use gix::{
3+
bstr::{BString, ByteSlice},
4+
diff::blob::{
5+
intern::TokenSource,
6+
unified_diff::{ContextSize, NewlineSeparator},
7+
UnifiedDiff,
8+
},
9+
objs::tree::EntryMode,
10+
odb::store::RefreshMode,
11+
prelude::ObjectIdExt,
12+
ObjectId,
13+
};
1014

1115
pub fn tree(
1216
mut repo: gix::Repository,

gitoxide-core/src/repository/dirty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::OutputFormat;
21
use anyhow::bail;
32

3+
use crate::OutputFormat;
4+
45
pub enum Mode {
56
IsClean,
67
IsDirty,

gitoxide-core/src/repository/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub(crate) mod function {
169169

170170
let start = std::time::Instant::now();
171171
progress.set_name("layout graph".into());
172-
progress.info(format!("writing {path:?}…"));
172+
progress.info(format!("writing {}…", path.display()));
173173
let mut svg = SVGWriter::new();
174174
vg.do_it(false, false, false, &mut svg);
175175
std::fs::write(path, svg.finalize().as_bytes())?;

gitoxide-core/src/repository/index/entries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub(crate) mod function {
2323
io::{BufWriter, Write},
2424
};
2525

26-
use gix::index::entry::Stage;
2726
use gix::{
2827
bstr::{BStr, BString},
28+
index::entry::Stage,
2929
worktree::IndexPersistedOrInMemory,
3030
Repository,
3131
};

gitoxide-core/src/repository/mailmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use anyhow::bail;
2-
use gix::bstr::{BString, ByteSlice};
31
use std::io;
42

3+
use anyhow::bail;
4+
use gix::bstr::{BString, ByteSlice};
55
#[cfg(feature = "serde")]
66
use gix::mailmap::Entry;
77

0 commit comments

Comments
 (0)