Skip to content

Commit 581cbd7

Browse files
committed
first PoC for writing long paths, even though it doens't produce the entire file yet
1 parent d7a8a7d commit 581cbd7

File tree

5 files changed

+39
-40
lines changed

5 files changed

+39
-40
lines changed

git-index/src/entry/write.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Entry, State};
1+
use crate::{entry, Entry, State};
22
use std::convert::TryInto;
33

44
impl Entry {
@@ -17,14 +17,13 @@ impl Entry {
1717
out.write_all(&stat.size.to_be_bytes())?;
1818
out.write_all(self.id.as_bytes())?;
1919
let path = self.path(state);
20-
let path_len: u16 = path
21-
.len()
22-
.try_into()
23-
.expect("Cannot handle paths longer than 16bits ever");
24-
assert!(
25-
path_len <= 0xFFF,
26-
"Paths can't be longer than 12 bits as they share space with bit flags in a u16"
27-
);
20+
let path_len: u16 = if path.len() >= entry::Flags::PATH_LEN.bits() as usize {
21+
entry::Flags::PATH_LEN.bits() as u16
22+
} else {
23+
path.len()
24+
.try_into()
25+
.expect("we just checked that the length is smaller than 0xfff")
26+
};
2827
out.write_all(&(self.flags.to_storage().bits() | path_len).to_be_bytes())?;
2928
out.write_all(path)?;
3029
out.write_all(b"\0")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
pub use git_testtools::Result;
2+
13
mod index;
24
pub use index::*;

git-index/tests/index-single-threaded.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pub use git_testtools::Result;
2+
13
#[cfg(not(feature = "internal-testing-git-features-parallel"))]
24
mod index;
35
#[cfg(not(feature = "internal-testing-git-features-parallel"))]

git-index/tests/index/file/write.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ use git_index::{decode, extension, write, State, Version};
55
use std::cmp::{max, min};
66

77
#[test]
8-
#[ignore]
9-
fn roundtrips() {
8+
fn roundtrips() -> crate::Result {
109
enum Kind {
1110
Generated(&'static str),
1211
Loose(&'static str),
1312
}
1413
use Kind::*;
1514
let input = [
16-
(Loose("very-long-path"), write::Options::default()),
17-
(Generated("v2"), write::Options::default()),
18-
(Generated("V2_empty"), write::Options::default()),
15+
(Loose("very-long-path"), write::Options::default(), false), // unclear why the file is smaller when written back
16+
(Generated("v2"), write::Options::default(), true),
17+
(Generated("V2_empty"), write::Options::default(), true),
1918
(
2019
Generated("v2_more_files"),
2120
write::Options {
@@ -25,24 +24,28 @@ fn roundtrips() {
2524
},
2625
..write::Options::default()
2726
},
27+
true,
2828
),
2929
];
3030

31-
for (fixture, options) in input {
31+
for (fixture, options, compare_byte_by_byte) in input {
3232
let (path, fixture) = match fixture {
3333
Generated(name) => (crate::fixture_index_path(name), name),
3434
Loose(name) => (loose_file_path(name), name),
3535
};
36-
let expected_index = git_index::File::at(&path, decode::Options::default()).unwrap();
37-
let expected_bytes = std::fs::read(&path).unwrap();
36+
let expected = git_index::File::at(&path, decode::Options::default())?;
37+
let expected_bytes = std::fs::read(&path)?;
3838
let mut out_bytes = Vec::new();
3939

40-
expected_index.write_to(&mut out_bytes, options).unwrap();
41-
let (out_index, _) = State::from_bytes(&out_bytes, FileTime::now(), decode::Options::default()).unwrap();
40+
expected.write_to(&mut out_bytes, options)?;
41+
let (actual, _) = State::from_bytes(&out_bytes, FileTime::now(), decode::Options::default())?;
4242

43-
compare_states(&out_index, &expected_index, options, fixture);
44-
compare_raw_bytes(&out_bytes, &expected_bytes, fixture);
43+
compare_states(&actual, &expected, options, fixture);
44+
if compare_byte_by_byte {
45+
compare_raw_bytes(&out_bytes, &expected_bytes, fixture);
46+
}
4547
}
48+
Ok(())
4649
}
4750

4851
#[test]
@@ -135,12 +138,13 @@ fn v2_index_eoie_extensions() {
135138
}
136139
}
137140

138-
fn compare_states(generated: &State, expected: &State, options: write::Options, fixture: &str) {
139-
generated.verify_entries().expect("valid");
140-
generated.verify_extensions(false, no_find).expect("valid");
141-
assert_eq!(generated.version(), options.version, "version mismatch in {}", fixture);
141+
fn compare_states(actual: &State, expected: &State, options: write::Options, fixture: &str) {
142+
actual.verify_entries().expect("valid");
143+
actual.verify_extensions(false, no_find).expect("valid");
144+
145+
assert_eq!(actual.version(), options.version, "version mismatch in {}", fixture);
142146
assert_eq!(
143-
generated.tree(),
147+
actual.tree(),
144148
options
145149
.extensions
146150
.should_write(extension::tree::SIGNATURE)
@@ -149,19 +153,14 @@ fn compare_states(generated: &State, expected: &State, options: write::Options,
149153
fixture
150154
);
151155
assert_eq!(
152-
generated.entries().len(),
156+
actual.entries().len(),
153157
expected.entries().len(),
154158
"entry count mismatch in {}",
155159
fixture
156160
);
161+
assert_eq!(actual.entries(), expected.entries(), "entries mismatch in {}", fixture);
157162
assert_eq!(
158-
generated.entries(),
159-
expected.entries(),
160-
"entries mismatch in {}",
161-
fixture
162-
);
163-
assert_eq!(
164-
generated.path_backing(),
163+
actual.path_backing(),
165164
expected.path_backing(),
166165
"path_backing mismatch in {}",
167166
fixture

git-repository/src/repository/identity.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use std::borrow::Cow;
22

3-
use git_actor::SignatureRef;
4-
use git_config::File;
5-
63
use crate::{bstr::BString, permission};
74

85
/// Identity handling.
@@ -15,8 +12,8 @@ impl crate::Repository {
1512
/// # Note
1613
///
1714
/// The values are cached when the repository is instantiated.
18-
pub fn user_default(&self) -> SignatureRef<'_> {
19-
SignatureRef {
15+
pub fn user_default(&self) -> git_actor::SignatureRef<'_> {
16+
git_actor::SignatureRef {
2017
name: "gitoxide".into(),
2118
email: "gitoxide@localhost".into(),
2219
time: git_date::Time::now_local_or_utc(),
@@ -105,7 +102,7 @@ impl Personas {
105102
fn env_var(name: &str) -> Option<BString> {
106103
std::env::var_os(name).map(|value| git_path::into_bstr(Cow::Owned(value.into())).into_owned())
107104
}
108-
fn entity_in_section(name: &str, config: &File<'_>) -> (Option<BString>, Option<BString>) {
105+
fn entity_in_section(name: &str, config: &git_config::File<'_>) -> (Option<BString>, Option<BString>) {
109106
config
110107
.section(name, None)
111108
.map(|section| {

0 commit comments

Comments
 (0)