From 9a6388dce60002693b8deda1e6b0d9962f714395 Mon Sep 17 00:00:00 2001 From: Brian Camacho Date: Tue, 12 Nov 2024 02:17:06 -0500 Subject: [PATCH] logs around getFingerprint --- src/libfetchers/git-lfs-fetch.hh | 13 +++++++++---- src/libfetchers/git.cc | 7 ++++++- tests/nixos/fetch-git/test-cases/lfs/default.nix | 3 +++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/libfetchers/git-lfs-fetch.hh b/src/libfetchers/git-lfs-fetch.hh index 1abafeabe..034c5e3c2 100644 --- a/src/libfetchers/git-lfs-fetch.hh +++ b/src/libfetchers/git-lfs-fetch.hh @@ -380,7 +380,9 @@ void Fetch::init(git_repository* repo, std::string gitattributesContent) { const auto remoteUrl = lfs::getLfsEndpointUrl(repo); this->gitUrl = parseGitUrl(remoteUrl); - this->token = lfs::getLfsApiToken(this->gitUrl); + if (this->gitUrl.protocol == "ssh") { + this->token = lfs::getLfsApiToken(this->gitUrl); + } this->rules = lfs::parseGitAttrFile(gitattributesContent); this->ready = true; } @@ -420,14 +422,17 @@ std::vector Fetch::fetchUrls(const std::vector &metadatas) c curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlErrBuf); std::string responseString; std::string headerString; - auto lfsUrlBatch = gitUrl.toHttp() + "/info/lfs/objects/batch"; + const auto lfsUrlBatch = gitUrl.toHttp() + "/info/lfs/objects/batch"; curl_easy_setopt(curl, CURLOPT_URL, lfsUrlBatch.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, dataStr.c_str()); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); struct curl_slist *headers = NULL; - auto authHeader = "Authorization: " + token; - headers = curl_slist_append(headers, authHeader.c_str()); + if (this->token != "") { + const auto authHeader = "Authorization: " + token; + headers = curl_slist_append(headers, authHeader.c_str()); + } + headers = curl_slist_append(headers, "Content-Type: application/vnd.git-lfs+json"); headers = curl_slist_append(headers, "Accept: application/vnd.git-lfs+json"); diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 9e51d1515..d39d6840d 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -642,6 +642,7 @@ struct GitInputScheme : InputScheme bool exportIgnore = getExportIgnoreAttr(input); bool smudgeLfs = getLfsAttr(input); + std::cerr << "smudgeLfs: " << smudgeLfs << std::endl; auto accessor = repo->getAccessor(rev, exportIgnore, smudgeLfs); accessor->setPathDisplay("«" + input.to_string() + "»"); @@ -803,7 +804,11 @@ struct GitInputScheme : InputScheme std::optional getFingerprint(ref store, const Input & input) const override { if (auto rev = input.getRev()) - return rev->gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "") + (getLfsAttr(input) ? ";l" : ""); + { + const auto s = rev->gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "") + (getLfsAttr(input) ? ";l" : ""); + std::cerr << "getFingerprint: " << s << std::endl; + return s; + } else return std::nullopt; } diff --git a/tests/nixos/fetch-git/test-cases/lfs/default.nix b/tests/nixos/fetch-git/test-cases/lfs/default.nix index 014acc49f..e414a8018 100644 --- a/tests/nixos/fetch-git/test-cases/lfs/default.nix +++ b/tests/nixos/fetch-git/test-cases/lfs/default.nix @@ -53,11 +53,14 @@ }} """ + # fetch the repo via nix fetched_lfs = client.succeed(f""" nix eval --impure --raw --expr '({fetchGit_lfs_expr}).outPath' """) + assert fetched_lfs != fetched_nolfs, f"fetching with and without lfs yielded the same store path {fetched_lfs}, fingerprinting error?" + # check that file was smudged file_size_lfs = client.succeed(f""" stat -c %s {fetched_lfs}/beeg