Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mailmap support #366

Merged
merged 32 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a30a5da
empty git-mailmap crate (#366)
Byron Mar 26, 2022
c43af35
Release git-mailmap v0.0.0
Byron Mar 26, 2022
fc47c49
the first empty test (#366)
Byron Mar 26, 2022
3e78ff5
refactor
Byron Mar 26, 2022
903c526
basic testing of common cases for mailmap (#366)
Byron Mar 26, 2022
9449bc7
thanks clippy
Byron Mar 26, 2022
2fb4310
fix serde support (#366)
Byron Mar 26, 2022
f458817
high-level parsing to deal with allowed mailmap lines (#366)
Byron Mar 26, 2022
67a2050
all tests (so far) green (#366)
Byron Mar 26, 2022
fb5593a
quickfix for unintentionally using 'unicode' feature of bytecode (#366)
Byron Mar 26, 2022
8ff53af
cleanup bstr usage to not accidentally pull in unicode (#366)
Byron Mar 26, 2022
471fa62
Commit to using 'unicode' feature of bstr as git-object wants it too
Byron Mar 26, 2022
b67b0f9
Add typical malmap example (#366)
Byron Mar 27, 2022
d71d067
sketch of mailmap snapshot for lookups (#366)
Byron Mar 28, 2022
77ef2cb
feat: `Time::default()` (#366)
Byron Mar 28, 2022
85e3820
add `fixture_bytes` to test tools
Byron Mar 28, 2022
1890db7
sketch `Snapshot` API to implement map building and signature resolut…
Byron Mar 28, 2022
8116664
actual lookup and tests, all seems to be working (#366)
Byron Mar 28, 2022
1038dab
thanks clippy
Byron Mar 28, 2022
87fb932
Add method to return borrowed values for new name/email (#366)
Byron Mar 28, 2022
deaeb7d
Another test to validate correct merging and overwriting (#366)
Byron Mar 28, 2022
1c768a5
add all docs (#366)
Byron Mar 28, 2022
e31754d
fix email-only case (#366)
Byron Mar 29, 2022
f498dac
verify universal line-endings are supported (#366)
Byron Mar 29, 2022
b2df941
Merge branch 'main' into mailmap
Byron Mar 29, 2022
e3bc1b4
feat: unstable mailmap module (#366)
Byron Mar 29, 2022
384ed66
feat: `gix mailmap verify` command (#366)
Byron Mar 29, 2022
f89fe2f
gix mailmap verify can now detect collisions (#366)
Byron Mar 29, 2022
c8c87ec
frame for `Repository::load_mailmap_into()` (#366)
Byron Mar 29, 2022
98d745e
the first possibly working version of loading a mailmap with multiple…
Byron Mar 29, 2022
2a01f47
frame for printing mailmap entries using git-repository (#366)
Byron Mar 29, 2022
d2388d8
feat: `gix repository mailmap entries` (#366)
Byron Mar 29, 2022
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
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ members = [
"git-worktree",
"git-revision",
"git-packetline",
"git-mailmap",
"git-submodule",
"git-transport",
"git-protocol",
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ check: ## Build all code in suitable configurations
&& cargo check --features verbose-object-parsing-errors
cd git-index && cargo check --features serde1
cd git-revision && cargo check --features serde1
cd git-attributes && cargo check --features serde1
cd git-mailmap && cargo check --features serde1
cd git-worktree && cargo check --features serde1
cd git-actor && cargo check --features serde1
cd git-pack && cargo check --features serde1 \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Follow linked crate name for detailed status. Please note that all crates follow
* [git-attributes](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-attributes)
* [git-quote](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-quote)
* **idea**
* [git-mailmap](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-mailmap)
* [git-pathspec](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-pathspec)
* [git-subomdule](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-submodule)
* [git-tui](https://github.com/Byron/gitoxide/blob/main/crate-status.md#git-tui)
Expand Down
5 changes: 5 additions & 0 deletions crate-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ Check out the [performance discussion][git-traverse-performance] as well.
* **ansi-c**
* [x] quote
* [ ] unquote
*
### git-mailmap

* [ ] parsing
* [ ] lookup and mapping of author names

### git-pathspec

Expand Down
5 changes: 2 additions & 3 deletions git-actor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ use bstr::{BStr, BString};

///
pub mod signature;
mod time;

const SPACE: &[u8; 1] = b" ";

/// A mutable signature is created by an actor at a certain time.
///
/// Note that this is not a cryptographical signature.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[derive(Default, PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Signature {
/// The actors name.
Expand Down Expand Up @@ -63,5 +64,3 @@ pub struct Time {
/// the sign of `offset`, used to encode `-0000` which would otherwise loose sign information.
pub sign: Sign,
}

mod time;
18 changes: 2 additions & 16 deletions git-actor/src/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,12 @@ mod _ref {
}

mod convert {
use crate::{Sign, Signature, SignatureRef, Time};

impl Default for Signature {
fn default() -> Self {
Signature::empty()
}
}
use crate::{Signature, SignatureRef};

impl Signature {
/// An empty signature, similar to 'null'.
pub fn empty() -> Self {
Signature {
name: Default::default(),
email: Default::default(),
time: Time {
seconds_since_unix_epoch: 0,
offset_in_seconds: 0,
sign: Sign::Plus,
},
}
Signature::default()
}

/// Borrow this instance as immutable
Expand Down
10 changes: 10 additions & 0 deletions git-actor/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ impl From<i32> for Sign {
}
}

impl Default for Time {
fn default() -> Self {
Time {
seconds_since_unix_epoch: 0,
offset_in_seconds: 0,
sign: Sign::Plus,
}
}
}

impl Time {
/// Serialize this instance to `out` in a format suitable for use in header fields of serialized git commits or tags.
pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions git-attributes/src/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod pattern {
use bitflags::bitflags;

bitflags! {
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Mode: u32 {
/// The pattern does not contain a sub-directory and - it doesn't contain slashes after removing the trailing one.
const NO_SUB_DIR = 1 << 0;
Expand Down
4 changes: 3 additions & 1 deletion git-attributes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![forbid(unsafe_code, rust_2018_idioms)]
#![forbid(unsafe_code)]
#![deny(rust_2018_idioms)]

use bstr::BStr;

Expand All @@ -11,6 +12,7 @@ pub enum State<'a> {
Unset,
/// The attribute is set to the given value, which followed the `=` sign.
/// Note that values can be empty.
#[cfg_attr(feature = "serde1", serde(borrow))]
Value(&'a BStr),
/// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
Unspecified,
Expand Down
3 changes: 3 additions & 0 deletions git-attributes/src/parse/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub(crate) fn parse_line(mut line: &[u8]) -> Option<(BString, ignore::pattern::M
line = &line[1..];
}
}
if line.iter().all(|b| b.is_ascii_whitespace()) {
return None;
}
let mut line = truncate_non_escaped_trailing_spaces(line);
if line.last() == Some(&b'/') {
mode |= ignore::pattern::Mode::MUST_BE_DIR;
Expand Down
14 changes: 6 additions & 8 deletions git-attributes/tests/parse/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bstr::{BStr, ByteSlice};
use git_attributes::ignore::pattern::Mode;
use git_attributes::{parse, State};
use git_testtools::fixture_path;
use git_testtools::fixture_bytes;

#[test]
fn byte_order_marks_are_no_patterns() {
Expand All @@ -14,9 +14,9 @@ fn byte_order_marks_are_no_patterns() {

#[test]
fn line_numbers_are_counted_correctly() {
let ignore = std::fs::read(fixture_path("attributes/various.txt")).unwrap();
let input = fixture_bytes("attributes/various.txt");
assert_eq!(
try_lines(&String::from_utf8(ignore).unwrap()).unwrap(),
try_lines(&String::from_utf8(input).unwrap()).unwrap(),
vec![
(pattern(r"*.[oa]", Mode::NO_SUB_DIR), vec![set("c")], 2),
(
Expand Down Expand Up @@ -44,13 +44,14 @@ fn line_endings_can_be_windows_or_unix() {
}

#[test]
fn comment_lines_are_ignored() {
fn comment_lines_are_ignored_as_well_as_empty_ones() {
assert!(git_attributes::parse(b"# hello world").next().is_none());
assert!(git_attributes::parse(b"# \"hello world\"").next().is_none());
assert!(
git_attributes::parse(b" \t\r# \"hello world\"").next().is_none(),
"also behind leading whitespace"
);
assert!(git_attributes::parse(b"\n\r\n\t\t \n").next().is_none());
}

#[test]
Expand Down Expand Up @@ -266,10 +267,7 @@ fn try_line(input: &str) -> Result<ExpandedAttribute, parse::Error> {
}

fn line(input: &str) -> ExpandedAttribute {
let mut lines = git_attributes::parse(input.as_bytes());
let res = expand(lines.next().expect("single line")).unwrap();
assert!(lines.next().is_none(), "expected only one line");
res
try_line(input).unwrap()
}

fn try_lines(input: &str) -> Result<Vec<ExpandedAttribute>, parse::Error> {
Expand Down
9 changes: 5 additions & 4 deletions git-attributes/tests/parse/ignore.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use git_attributes::ignore::pattern::Mode;
use git_testtools::fixture_path;
use git_testtools::fixture_bytes;

#[test]
fn byte_order_marks_are_no_patterns() {
Expand All @@ -11,8 +11,8 @@ fn byte_order_marks_are_no_patterns() {

#[test]
fn line_numbers_are_counted_correctly() {
let ignore = std::fs::read(fixture_path("ignore/various.txt")).unwrap();
let actual: Vec<_> = git_attributes::parse::ignore(&ignore).collect();
let input = fixture_bytes("ignore/various.txt");
let actual: Vec<_> = git_attributes::parse::ignore(&input).collect();
assert_eq!(
actual,
vec![
Expand Down Expand Up @@ -66,8 +66,9 @@ fn mark_ends_with_pattern_specifically() {
}

#[test]
fn comments_are_ignored() {
fn comments_are_ignored_as_well_as_empty_ones() {
assert!(git_attributes::parse::ignore(b"# hello world").next().is_none());
assert!(git_attributes::parse::ignore(b"\n\r\n\t\t \n").next().is_none());
}

#[test]
Expand Down
9 changes: 7 additions & 2 deletions git-features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,17 @@ time = { version = "0.3.2", optional = true, default-features = false, features

# path
## make bstr utilities available in the `path` modules, which itself is gated by the `path` feature.
bstr = { version = "0.2.17", optional = true }
bstr = { version = "0.2.17", optional = true, default-features = false, features = ["std"] }

document-features = { version = "0.2.0", optional = true }

[target.'cfg(unix)'.dependencies]
## for fs::open_options_no_follow()
# TODO: ideally we conditionally import it only if a plumbing crate wants to use the underlying feature. Wanted to avoid to add to feature-toggle complexity.
libc = { version = "0.2.119" }

[dev-dependencies]
bstr = "0.2.15"
bstr = { version = "0.2.15", default-features = false }

[package.metadata.docs.rs]
features = ["document-features"]
Expand Down
16 changes: 16 additions & 0 deletions git-features/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ pub mod walkdir {

#[cfg(any(feature = "walkdir", feature = "jwalk"))]
pub use self::walkdir::{walkdir_new, walkdir_sorted_new, WalkDir};

/// Prepare open options which won't follow symlinks when the file is opened.
///
/// Note: only effective on unix currently.
pub fn open_options_no_follow() -> std::fs::OpenOptions {
let mut options = std::fs::OpenOptions::new();
#[cfg(unix)]
{
/// Make sure that it's impossible to follow through to the target of symlinks.
/// Note that this will still follow symlinks in the path, which is what we assume
/// has been checked separately.
use std::os::unix::fs::OpenOptionsExt;
options.custom_flags(libc::O_NOFOLLOW);
}
options
}
29 changes: 29 additions & 0 deletions git-mailmap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.0.0 (2022-03-26)

An empty crate without any content to reserve the name for the gitoxide project.

### Commit Statistics

<csr-read-only-do-not-edit/>

- 1 commit contributed to the release.
- 0 commits where understood as [conventional](https://www.conventionalcommits.org).
- 1 unique issue was worked on: [#366](https://github.com/Byron/gitoxide/issues/366)

### Commit Details

<csr-read-only-do-not-edit/>

<details><summary>view details</summary>

* **[#366](https://github.com/Byron/gitoxide/issues/366)**
- empty git-mailmap crate ([`a30a5da`](https://github.com/Byron/gitoxide/commit/a30a5da60d67a4e52ba69727318edb9832b7cae2))
</details>

26 changes: 26 additions & 0 deletions git-mailmap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "git-mailmap"
version = "0.0.0"
repository = "https://github.com/Byron/gitoxide"
license = "MIT/Apache-2.0"
description = "A WIP crate of the gitoxide project for parsing mailmap files"
authors = ["Sebastian Thiel <[email protected]>"]
edition = "2018"

[lib]
doctest = false

[features]
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
serde1 = ["serde", "bstr/serde1", "git-actor/serde1"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
git-actor = { version = "^0.8.1", path = "../git-actor" }
bstr = { version = "0.2.13", default-features = false, features = ["std", "unicode"]}
quick-error = "2.0.0"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}

[dev-dependencies]
git-testtools = { path = "../tests/tools"}
Loading