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

shallow_since appears to be a trap when used with commit, debug line should be removed #12857

Closed
djmarcin opened this issue Jan 20, 2021 · 7 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug

Comments

@djmarcin
Copy link

djmarcin commented Jan 20, 2021

Description of the problem / feature request:

The shallow_since option to new_git_repository appears to be a trap, at least when used with the commit option. When shallow_since is provided, instead of using depth 1 to check out only the relevant commit, the entire repo state since some timestamp is cloned. On one of our repos, this causes a 25x difference in clone time (7s -> 175s) and presumably a large size disparity as well.

Now that we have removed shallow_since, bazel emits a debug line encouraging us to add it back.

DEBUG: Rule 'foo' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1611092265 -0800"

This seems wrong -- as far as I understand, the repo at a specific commit hash is a canonical reproducible form, so it seems like bazel should not be suggesting this change.

Feature requests: what underlying problem are you trying to solve with this feature?

Bazel should not recommend adding shallow_since since it is dramatically slower in some cases, and seems generally unnecessary to obtain a snapshot of the repository.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Create a new_git_repository rule for a large git repository at a commit that is not close to HEAD. Providing shallow_since will slow down the clone substantially.

What operating system are you running Bazel on?

Linux, Ubuntu 20.04

What's the output of bazel info release?

INFO: Invocation ID: 6c8f5dce-cf89-4b6f-a335-93ff77612968
release 3.7.1

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

n/a

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

n/a (private repo)

Have you found anything relevant by searching the web?

No

Any other information, logs, or outputs that you want to share?

n/a

@thii
Copy link
Member

thii commented Jan 20, 2021

+1

Also git's --shallow-since has a bug that can sometimes make git impossible to fetch the desired commit using its suggested timestamp: #10292.

@gregestren gregestren added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website untriaged type: bug labels Jan 26, 2021
@philwo philwo added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Feb 8, 2021
@asuffield
Copy link
Contributor

There is no way to persuade git to fetch a specific commit with --depth=1. If you try fetching a commit hash, most servers will just give you "server does not allow request for unadvertised object", and if you fetch a ref name then it can return anything and is not reproducible.

shallow_since is the only feature git offers to do this. Unfortunately, it's completely broken.

@asuffield
Copy link
Contributor

Correction: --depth=1 on a single commit only works with protocol v2, see #12199

@djmarcin
Copy link
Author

djmarcin commented Mar 2, 2021

@asuffield I don't think we're on protocol v2 (although I'm not completely sure how to verify that) and we've been using the commit only since I posted the issue without any apparent problems or non-reproducibility. As far as I can tell, the actions bazel is taking are equivalent to the following commands, which appear to work for me.

mkdir ruby ; cd ruby
git init
git remote add origin [email protected]:ruby/ruby.git
# A random old commit
git fetch origin 5de38c41ae7bf17ae599fdfa9f8face87f16d8bb --depth 1
git checkout 5de38c41ae7bf17ae599fdfa9f8face87f16d8bb

Do you mean that it doesn't work reliably with all git servers, so maybe it works on github but not elsewhere?

$ git --version
git version 2.25.1
$ echo $GIT_PROTOCOL

@djmarcin
Copy link
Author

djmarcin commented Mar 2, 2021

It looks like maybe the server config option uploadpack.allowReachableSHA1InWant needs to be set to enable this, but the repository rules already seem to handle falling back when the server doesn't support this option anyway. shallow_since is perhaps better than the fallback option, but it's probably worse than fetching the commit directly when supported, so it shouldn't be recommended when fetching by commit is supported.

# Perhaps uploadpack.allowReachableSHA1InWant or similar is not enabled on the server;

@asuffield
Copy link
Contributor

It definitely fails with git 2.18 (ugh, upgrading that right now) against gitlab, I haven't tested exhaustively. But the main problem in the PR linked above is that one of bazel's target platforms has an old git version, and that's going to sabotage us here.

@CodingCanuck
Copy link

Are there ways to improve this situation, even given bazel's support for ubuntu 18.04 and its associated git version?

One option is simply to drop the warning from this rule (by making the rule output a canonical version that omits shallow_since if the caller did not specify it).

Another is to add something like an explicit depth arg to the git_repository rules: I don't like that from an API perspective, but it could allow callers to explicitly use a depth-based canonical form (rather than a shallow_since-based form) if that works for their environments.

I think that any change to the canonical form of this rule would involve changing what's returned from the git_repo function.

Are there other ideas that could remove warnings from a correct repository setup that's relying on depth=1 rather than a shallow_since date?

fmeum added a commit to fmeum/bazel that referenced this issue Jan 30, 2023
Git's `--shallow-since` feature can lead to broken checkouts and a fix
isn't likely to happen:
https://public-inbox.org/git/CAPSG9dZV2EPpVKkOMcjv5z+NF7rUu=V-ZkZNx47rCv122HsiKg@mail.gmail.com/T/#u

This commit removes `shallow_since` from the canonical reproducible form
of `git_repository` unless the attribute is provided explicitly. In
cases where Bazel's attempt at fetching with `--depth=1` fail, e.g. if
there is no server support for shallow fetches of arbitrary commits, the
progress message is now used to inform the user about this potential for
fetch time optimizations.

Fixes bazelbuild#10292
Fixes bazelbuild#12857
fmeum added a commit to fmeum/bazel that referenced this issue Jan 30, 2023
Git's `--shallow-since` feature can lead to broken checkouts and a fix
isn't likely to happen:
https://public-inbox.org/git/CAPSG9dZV2EPpVKkOMcjv5z+NF7rUu=V-ZkZNx47rCv122HsiKg@mail.gmail.com/T/#u

This commit removes `shallow_since` from the canonical reproducible form
of `git_repository` unless the attribute is provided explicitly. In
cases where Bazel's attempt at fetching with `--depth=1` fail, e.g. if
there is no server support for shallow fetches of arbitrary commits, the
progress message is now used to inform the user about this potential for
fetch time optimizations.

Fixes bazelbuild#10292
Fixes bazelbuild#12857
fmeum added a commit to fmeum/bazel that referenced this issue Jan 30, 2023
Git's `--shallow-since` feature can lead to broken checkouts and a fix
isn't likely to happen:
https://public-inbox.org/git/CAPSG9dZV2EPpVKkOMcjv5z+NF7rUu=V-ZkZNx47rCv122HsiKg@mail.gmail.com/T/#u

This commit removes `shallow_since` from the canonical reproducible form
of `git_repository` unless the attribute is provided explicitly. In
cases where Bazel's attempt at fetching with `--depth=1` fail, e.g. if
there is no server support for shallow fetches of arbitrary commits, the
progress message is now used to inform the user about this potential for
fetch time optimizations.

Fixes bazelbuild#10292
Fixes bazelbuild#12857
hvadehra pushed a commit that referenced this issue Feb 14, 2023
Git's `--shallow-since` feature can lead to broken checkouts and a fix isn't likely to happen:
https://public-inbox.org/git/CAPSG9dZV2EPpVKkOMcjv5z+NF7rUu=V-ZkZNx47rCv122HsiKg@mail.gmail.com/T/#u

This commit removes `shallow_since` from the canonical reproducible form of `git_repository` unless the attribute is provided explicitly. In cases where Bazel's attempt at fetching with `--depth=1` fail, e.g. if there is no server support for shallow fetches of arbitrary commits, the progress message is now used to inform the user about this potential for fetch time optimizations.

Fixes #10292
Fixes #12857

Closes #17356.

PiperOrigin-RevId: 508569071
Change-Id: I01e6662e38c236d1800d427f66d48a05df818800
ShreeM01 added a commit that referenced this issue Feb 16, 2023
Git's `--shallow-since` feature can lead to broken checkouts and a fix isn't likely to happen:
https://public-inbox.org/git/CAPSG9dZV2EPpVKkOMcjv5z+NF7rUu=V-ZkZNx47rCv122HsiKg@mail.gmail.com/T/#u

This commit removes `shallow_since` from the canonical reproducible form of `git_repository` unless the attribute is provided explicitly. In cases where Bazel's attempt at fetching with `--depth=1` fail, e.g. if there is no server support for shallow fetches of arbitrary commits, the progress message is now used to inform the user about this potential for fetch time optimizations.

Fixes #10292
Fixes #12857

Closes #17356.

PiperOrigin-RevId: 508569071
Change-Id: I01e6662e38c236d1800d427f66d48a05df818800

Co-authored-by: Fabian Meumertzheim <[email protected]>
fhanau added a commit to cloudflare/workerd that referenced this issue Jan 19, 2024
Based on bazelbuild/bazel#12857 shallow_since
may actually slow down the build. As of version 6.1.0, bazel no longer
prints a warning if shallow_since is absent.
fhanau added a commit to cloudflare/workerd that referenced this issue Jan 23, 2024
Based on bazelbuild/bazel#12857 shallow_since
may actually slow down the build. As of version 6.1.0, bazel no longer
prints a warning if shallow_since is absent.
lucamilanesio pushed a commit to GerritCodeReview/plugins_events that referenced this issue Feb 9, 2024
This reverts commit 5e3a41a.

Since bazel v6.1.0 the warning about shallow_since has been removed
since it was determined [1] to be potentially harmful to build
performance and reliability.

[1] bazelbuild/bazel#12857

Change-Id: Id9b44d260688b706a15be5df20d5a80e0968c548
lucamilanesio pushed a commit to GerritCodeReview/plugins_task that referenced this issue Feb 9, 2024
This reverts commit a7246ed.

Since bazel v6.1.0 the warning about shallow_since has been removed
since it was determined [1] to be potentially harmful to build
performance and reliability.

[1] bazelbuild/bazel#12857

Change-Id: I6003ae03511bdc7b5ba2cbb6b15b928bba18bfb5
copybara-service bot pushed a commit to google/pigweed that referenced this issue Feb 21, 2024
Using shallow_since is not recommended, and the attribute is expected
to be removed in a future Bazel version:
bazelbuild/bazel#17356,
bazelbuild/bazel#12857

Change-Id: I3d6daeefad609fc34566b69de67eee2a49f7d5e4
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/193473
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Pigweed-Auto-Submit: Ted Pudlik <[email protected]>
Reviewed-by: Armando Montanez <[email protected]>
yperess pushed a commit to yperess/zephyr-bazel that referenced this issue Mar 22, 2024
Using shallow_since is not recommended, and the attribute is expected
to be removed in a future Bazel version:
bazelbuild/bazel#17356,
bazelbuild/bazel#12857

Original-Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/193473

https://pigweed.googlesource.com/pigweed/pigweed
third_party/pigweed Rolled-Commits: 371015e36501c36..9a3bb012f2c6dc4
Roller-URL: https://ci.chromium.org/b/8755460054149076049
GitWatcher: ignore
CQ-Do-Not-Cancel-Tryjobs: true
Change-Id: I8952a6aa062170a57fca6a2f0420e40d7242d403
Reviewed-on: https://pigweed-review.googlesource.com/c/example/echo/+/193492
Bot-Commit: Pigweed Roller <[email protected]>
Commit-Queue: Pigweed Roller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants