Skip to content

Commit 8af61f2

Browse files
committed
fix: Ignore all changed files with an extension.
There are non-crate files that as far as we know all have file extensions, as opposed to the crate files we are interested in, which do not. Thus skipping all files with extension helps us to get past the initial commit which includes such files, like `.github/*.yml`. Related to rust-lang/docs.rs#1807 (comment)
1 parent 9d41b20 commit 8af61f2

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

src/index/diff/delegate.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::index::diff::Error;
22
use crate::{Change, CrateVersion};
3+
use bstr::BStr;
34
use git_repository as git;
45
use git_repository::diff::tree::visit::Action;
56
use similar::ChangeTag;
@@ -24,6 +25,7 @@ impl<'repo> Delegate<'repo> {
2425
}
2526
}
2627
fn handle(&mut self, change: git::diff::tree::visit::Change) -> Result<(), Error> {
28+
use git::bstr::ByteSlice;
2729
use git::diff::tree::visit::Change::*;
2830
use git::objs::tree::EntryMode::*;
2931
fn entry_data(
@@ -36,12 +38,14 @@ impl<'repo> Delegate<'repo> {
3638
.transpose()
3739
.map_err(Into::into)
3840
}
39-
use git::bstr::ByteSlice;
41+
if self.file_name.contains(&b'.') {
42+
return Ok(());
43+
}
4044
match change {
4145
Addition { entry_mode, oid } => {
4246
if let Some(obj) = entry_data(self.repo, entry_mode, oid)? {
4347
for line in (&obj.data).lines() {
44-
let version = version_from_json_line(line)?;
48+
let version = version_from_json_line(line, self.file_name.as_ref())?;
4549
self.changes.push(if version.yanked {
4650
Change::Yanked(version)
4751
} else {
@@ -70,7 +74,10 @@ impl<'repo> Delegate<'repo> {
7074
for change in diff.iter_all_changes() {
7175
match change.tag() {
7276
ChangeTag::Delete | ChangeTag::Insert => {
73-
let version = version_from_json_line(change.value())?;
77+
let version = version_from_json_line(
78+
change.value(),
79+
self.file_name.as_ref(),
80+
)?;
7481
if change.tag() == ChangeTag::Insert {
7582
self.changes.push(if version.yanked {
7683
Change::Yanked(version)
@@ -129,9 +136,10 @@ impl git::diff::tree::Visit for Delegate<'_> {
129136
}
130137
}
131138

132-
fn version_from_json_line(line: &[u8]) -> Result<CrateVersion, Error> {
139+
fn version_from_json_line(line: &[u8], file_name: &BStr) -> Result<CrateVersion, Error> {
133140
serde_json::from_slice(line).map_err(|err| Error::VersionDecode {
134141
source: err,
142+
file_name: file_name.into(),
135143
line: line.into(),
136144
})
137145
}

src/index/diff/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ pub enum Error {
2323
PeelToTree(#[from] git::object::peel::to_kind::Error),
2424
#[error("Failed to diff two trees to find changed crates")]
2525
Diff(#[from] git::diff::tree::changes::Error),
26-
#[error("Failed to decode {line:?} as crate version")]
26+
#[error("Failed to decode {line:?} in file {file_name:?} as crate version")]
2727
VersionDecode {
2828
source: serde_json::Error,
29+
file_name: bstr::BString,
2930
line: bstr::BString,
3031
},
3132
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:a4c725b07eae662b3f2fcd7a2ae6440fbaaaca0f1a73c9d44fa92f48d34c4a13
3-
size 582732
2+
oid sha256:4a5cca6f276fb9ba92fa7f33c645e1daf8e0361acbf1ecf610e4251253b4aa59
3+
size 586144
Binary file not shown.

tests/fixtures/make-index-parts.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ out="$root/index-parts"
1010
mkdir -p "$out"
1111
(
1212
cd "${1:?first argument is the clone of https://github.com/arlosi/crates.io-index}"
13-
path=gi/
13+
paths="gi/ .github"
1414
revlist="$root/.tmp.revs"
15-
{ git log --format=format:%H $path; echo; } | tail -r > "$revlist"
15+
{ git log --format=format:%H $paths; echo; } | tail -r > "$revlist"
1616

1717
first_commit="$(head -1 "$revlist")"
18-
git archive --format tar "$first_commit" $path > "$out/init.$first_commit.tar"
18+
git archive --format tar "$first_commit" $paths > "$out/init.$first_commit.tar"
1919

2020
commit_list=$out/commit.list
2121
tail +2 "$revlist" > "$commit_list"
2222
while read -r commit; do
23-
git diff "$commit"~1.."$commit" -- $path > "$out/$commit".diff
23+
git diff "$commit"~1.."$commit" -- $paths > "$out/$commit".diff
2424
git log --format=%B -n1 "$commit" > "$out/$commit.msg"
2525
done < "$commit_list"
2626

0 commit comments

Comments
 (0)