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

Use project-relative path when calculating gitlab message fingerprint #11532

Merged
merged 1 commit into from
May 26, 2024
Merged
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
10 changes: 5 additions & 5 deletions crates/ruff_linter/src/message/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ impl Serialize for SerializedMessages<'_> {
|project_dir| relativize_path_to(message.filename(), project_dir),
);

let mut message_fingerprint = fingerprint(message, 0);
let mut message_fingerprint = fingerprint(message, &path, 0);

// Make sure that we do not get a fingerprint that is already in use
// by adding in the previously generated one.
while fingerprints.contains(&message_fingerprint) {
message_fingerprint = fingerprint(message, message_fingerprint);
message_fingerprint = fingerprint(message, &path, message_fingerprint);
}
fingerprints.insert(message_fingerprint);

Expand All @@ -109,20 +109,20 @@ impl Serialize for SerializedMessages<'_> {
}

/// Generate a unique fingerprint to identify a violation.
fn fingerprint(message: &Message, salt: u64) -> u64 {
fn fingerprint(message: &Message, project_path: &str, salt: u64) -> u64 {
let Message {
kind,
range: _,
fix: _fix,
file,
file: _,
noqa_offset: _,
} = message;

let mut hasher = DefaultHasher::new();

salt.hash(&mut hasher);
kind.name.hash(&mut hasher);
file.name().hash(&mut hasher);
project_path.hash(&mut hasher);

hasher.finish()
}
Expand Down
Loading