Remove UNC prefixes on Windows (#1086)

## Summary

This PR adds a `NormalizedDisplay` trait that we can use for user-facing
paths, to strip the UNC prefix on Windows.

On other platforms, the implementation is a no-op (vs. `Display`).

I audited all usages of `.display()`, and changed any that were
user-facing, either via `println!` or `eprintln!`, or by way of being
included in error messages. I did _not_ change uses that were only in
tests or only went to tracing.

Closes https://github.com/astral-sh/puffin/issues/1084.
This commit is contained in:
Charlie Marsh 2024-01-25 08:44:22 -08:00 committed by GitHub
parent 035cd81ac8
commit f4939e50a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 98 additions and 43 deletions

View file

@ -14,6 +14,7 @@ workspace = true
[dependencies]
cache-key = { path = "../cache-key" }
puffin-fs = { path = "../puffin-fs" }
anyhow = { workspace = true }
cargo-util = { workspace = true }

View file

@ -9,6 +9,7 @@ use std::{env, str};
use anyhow::{anyhow, Context as _, Result};
use cargo_util::{paths, ProcessBuilder};
use git2::{self, ErrorClass, ObjectType};
use puffin_fs::NormalizedDisplay;
use reqwest::Client;
use reqwest::StatusCode;
use tracing::{debug, warn};
@ -149,7 +150,7 @@ impl GitRemote {
let reference = locked_ref.as_ref().unwrap_or(reference);
if let Some(mut db) = db {
fetch(&mut db.repo, self.url.as_str(), reference, strategy, client)
.with_context(|| format!("failed to fetch into: {}", into.display()))?;
.with_context(|| format!("failed to fetch into: {}", into.normalized_display()))?;
let resolved_commit_hash = match locked_rev {
Some(rev) => db.contains(rev).then_some(rev),
@ -169,7 +170,7 @@ impl GitRemote {
paths::create_dir_all(into)?;
let mut repo = init(into, true)?;
fetch(&mut repo, self.url.as_str(), reference, strategy, client)
.with_context(|| format!("failed to clone into: {}", into.display()))?;
.with_context(|| format!("failed to clone into: {}", into.normalized_display()))?;
let rev = match locked_rev {
Some(rev) => rev,
None => reference.resolve(&repo)?,