git_repository pointing at a commit which is not the latest commit in the repo causes error because of git clone --depth 1. This is currently blocking us from upgrading to bazel 0.10.0.
Clone https://github.com/wix-playground/repoA
Run bazel build //... (with 0.10.0rc7)
Note this line points at a non-HEAD commit of repoB.
MacOS 10.12.6 & Debian8
bazel info release?release 0.10.0rc7
https://github.com/bazelbuild/bazel/commit/4f51c0849305e9bfff2af4d80792fc69c02dfa08#diff-837a9f01631c2638001dbb9c581868ad
â–¶ bazel build //...
ERROR: error loading package '': Encountered error while reading extension file 'whatever.bzl': no such package '@repoB//': Traceback (most recent call last):
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 69
_clone_or_update(ctx)
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 44, in _clone_or_update
fail(("error cloning %s:\n%s" % (ctx....)))
error cloning repoB:
+ cd /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external
+ rm -rf /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB
+ git clone --depth=1 [email protected]:wix-playground/repoB.git /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB
Cloning into '/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB'...
+ cd /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB
+ git reset --hard 735e089f501c182560c4df2451bd16011fd09113
fatal: Could not parse object '735e089f501c182560c4df2451bd16011fd09113'.
+ git fetch --depth=1 origin 735e089f501c182560c4df2451bd16011fd09113:735e089f501c182560c4df2451bd16011fd09113
ERROR: error loading package '': Encountered error while reading extension file 'whatever.bzl': no such package '@repoB//': Traceback (most recent call last):
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 69
_clone_or_update(ctx)
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 44, in _clone_or_update
fail(("error cloning %s:\n%s" % (ctx....)))
error cloning repoB:
+ cd /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external
+ rm -rf /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB
+ git clone --depth=1 [email protected]:wix-playground/repoB.git /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB
Cloning into '/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB'...
+ cd /private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/repoB
+ git reset --hard 735e089f501c182560c4df2451bd16011fd09113
fatal: Could not parse object '735e089f501c182560c4df2451bd16011fd09113'.
+ git fetch --depth=1 origin 735e089f501c182560c4df2451bd16011fd09113:735e089f501c182560c4df2451bd16011fd09113
INFO: Elapsed time: 5.505s
FAILED: Build did NOT complete successfully (0 packages loaded)
When this happened previously (see #4405, #4358) the root cause was that the output base was itself inside a git repository, and this confused git as to where the root of the git repository was located. Could that be the issue you are seeing?
I had thought that 0ba8307ff46746864e357d0b7834b3c4247421d0 was in the 0.10.0rc7 branch, I'll go verify that now.
Can you please run the test //src/test/shell/bazel:skylark_git_repository_test and see if that shows the same failure?
$ git branch --contains 0ba8307ff46746864e357d0b7834b3c4247421d0
master
* release-0.10.0
So yes, the fix for the previous issue is already in the 0.10.0 rc, so the problem you are seeing may be slightly different.
My output base is _not_ itself inside a git repository and //src/test/shell/bazel:skylark_git_repository_test passes for me.
So, testing the git commands manually, I see the same error:
jcater@jcater:~/repos$ git clone --depth=1 [email protected]:wix-playground/repoB.git
Cloning into 'repoB'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 5 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.
jcater@jcater:~/repos$ cd repoB/
jcater@jcater:~/repos/repoB:master$ git reset --hard 735e089f501c182560c4df2451bd16011fd09113
fatal: Could not parse object '735e089f501c182560c4df2451bd16011fd09113'.
If I remove the --depth=1 flag from the git clone command, then the git reset works. It looks like this was added in 512b9b9b353bcabc436a87329fadd449c684c44b.
I'll take a look at a quick fix, and if that doesn't work I'll see if we can revert the commit entirely.
@edbaunton Can you explain the purpose of the --depth=1 flag? It looks like it's to limit the amount of history downloaded, but it's stopping git_repository from using any commit older than the first, so I plan to just remove it until we can find a better solution.
Sent https://bazel-review.googlesource.com/c/bazel/+/35091 to fix this.
It was to improve performance; the related issue was https://github.com/bazelbuild/bazel/issues/4359 since you download a lot of unneeded data which is especially painful for large repositories.
There was obviously not a test case to catch this, so will introduce a test case and then try and find a fix for the issue.
Thanks, my patch just removes the depth flag, which obviously isn't great long term.
I tried to add a test, but it appears that depth is only used with actual network downloads. Even using file:// urls didn't take --depth=1 into account.
The patch looks good.
btw, important to say we really want @edbaunton's change since it can be a significant gain.
Just need to think how to do it.
I'd guess that if we can not fail when the git reset fails but fallback to the fetch then the flow should work.
@katre re testing- have you considered starting a lean git server for the test?
Is there a workaround for this? The patch doesn't seem to be the solution here. I wanted to release tomorrow, but if another cherry pick is needed to fix this issue I would like to cherry pick it ASAP.
cc: @aehlig any ideas?
Why do you think the patch doesn't seem to be the solution?
Because the --depth flag fixes https://github.com/bazelbuild/bazel/issues/4359, which is something that people want in 0.10.0.
I know. What @katre did was effectively a revert of 4f51c0849305e9bfff2af4d80792fc69c02dfa08. I guess it's up to you if you'd rather delay the release or lose the feature.
As I said we're also interested in the feature so if we can get both I'd be a happy camper :)
I can't see any easy fix to get this feature back so not worth delaying the release IMO. Reading https://stackoverflow.com/questions/31278902/how-to-shallow-clone-a-specific-commit-with-depth-1 there is no way to get away with using a specific sha without cloning the entire repository (that isn't server-side dependent).
In this specific instance you can use the github interface to grab https://github.com/wix-playground/repoB/archive/735e089f501c182560c4df2451bd16011fd09113.tar.gz without the interim use of git but obviously that isn't generic (but would solve the speed issue that @ittaiz is having).
In the future we might want to use the --no-local flag on the clone which I think would have found this issue here during testing (but would impose a small performance overhead when cloning local repositories).
On Tue, Jan 30, 2018 at 10:56:34AM +0000, Ed Baunton wrote:
Reading https://stackoverflow.com/questions/31278902/how-to-shallow-clone-a-specific-commit-with-depth-1 there is no way to get away with using a specific sha without cloning the entire repository (that isn't server-side dependent).
If we knew the commit date of the commit in question, a significant amount of traffic could be saved using --shallow-since, fetching only changes since the day of the commit. Maybe adding the commit date as an optional argument (used to shallow clone, if given) could be a good interim solution?
--
Klaus Aehlig
Google Germany GmbH, Erika-Mann-Str. 33, 80636 Muenchen
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschaeftsfuehrer: Paul Terence Manicle, Halimah DeLaine Prado
One other solution is to first attempt a --depth 1 and if that fails fallback to a full clone and fetch. This would make you pay a price on doing a full clone of a failed low depth attempt.
One other solution is to first attempt a
--depth 1and if that fails fallback to a full clone and fetch. This would make you pay a price on doing a full clone of a failed low depth attempt.
If retrying on failure, we could also try deepen the shallow clone until it is deep enough to contain the commit we need...
--
Klaus Aehlig
Google Germany GmbH, Erika-Mann-Str. 33, 80636 Muenchen
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschaeftsfuehrer: Paul Terence Manicle, Halimah DeLaine Prado
I just did a very unscientific test of that approach to get to the first commit in the wix repo (about 10 commits from the tip):
time $( i=1; while [ 1 ]; do rm -rf repoB; git clone --depth $i https://github.com/wix-playground/repoB.git && git -C repoB checkout 4bfc06f0054c430f6468fe3e3c5fa523efcafe7f; if [ $? -eq 0 ]; then break; fi; i=$((i+1)); done)
which took approximately the same amount of time as cloning the entire repo alone (2 seconds). That is, repeatedly searching the history for the commit in question degenerates in performance as you have to go further back in time.
I guess we could have a heuristic and give n attempts and otherwise fallback to cloning the entire repo.
Release update: since #4359 was not a regression issue but a feature request, it shouldn't have priority over a regression issue which blocks users to upgrade to bazel 0.10.0.
That said, I will merge and cherry pick the revert of --depth flag. After that, you are free to solve this another way.
Fine with me, apologies for the bug.
Sounds good to me.
On Tue, Jan 30, 2018 at 9:11 AM Ed Baunton notifications@github.com wrote:
Fine with me, apologies for the bug.
—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/bazelbuild/bazel/issues/4537#issuecomment-361604444,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAT7fzEV48vhSeTpN6VOshPNoqB-3_6_ks5tPyMLgaJpZM4Rw9x9
.
With 0.10.0rc8 I get the following:
â–¶ ~/bin/bazel build //...
ERROR: error loading package '': Encountered error while reading extension file 'whatever.bzl': no such package '@repoB//': Traceback (most recent call last):
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 69
_clone_or_update(ctx)
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 27, in _clone_or_update
ctx.execute(["bash", "-c", "\nset -ex\n( cd ...)])
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 27, in ctx.execute
"\nset -ex\n( cd {working_dir} &&\n if ! ( cd '{dir_link}' && [[ \"$(git rev-parse --git-dir)\" == '.git' ]] ) >/dev/null 2>&1; then\n rm -rf '{directory}' '{dir_link}'\n git clone '{remote}' '{directory}'\n fi\n cd '{directory}'\n git reset --hard {ref} || (git fetch origin {ref}:{ref} && git reset --hard {ref})\n git clean -xdf )\n ".format(working_dir = ctx.path(".").dirn..., <3 more arguments>)
Missing argument 'dir_link'
ERROR: error loading package '': Encountered error while reading extension file 'whatever.bzl': no such package '@repoB//': Traceback (most recent call last):
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 69
_clone_or_update(ctx)
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 27, in _clone_or_update
ctx.execute(["bash", "-c", "\nset -ex\n( cd ...)])
File "/private/var/tmp/_bazel_alonbl/46478dd6ac03b1b47726754e0c4e0fa0/external/bazel_tools/tools/build_defs/repo/git.bzl", line 27, in ctx.execute
"\nset -ex\n( cd {working_dir} &&\n if ! ( cd '{dir_link}' && [[ \"$(git rev-parse --git-dir)\" == '.git' ]] ) >/dev/null 2>&1; then\n rm -rf '{directory}' '{dir_link}'\n git clone '{remote}' '{directory}'\n fi\n cd '{directory}'\n git reset --hard {ref} || (git fetch origin {ref}:{ref} && git reset --hard {ref})\n git clean -xdf )\n ".format(working_dir = ctx.path(".").dirn..., <3 more arguments>)
Missing argument 'dir_link'
INFO: Elapsed time: 0.459s
FAILED: Build did NOT complete successfully (0 packages loaded)
Yes, I didn't resolve a conflict well. Will fix that...
@barlevalon do you mind trying again with RC8? https://releases.bazel.build/0.10.0/rc8/index.html
Irina,
Did you override rc8 somehow? Because Alon said he tested with rc8
On Tue, 30 Jan 2018 at 19:55 Irina Iancu notifications@github.com wrote:
@barlevalon https://github.com/barlevalon do you mind trying again with
RC8? https://releases.bazel.build/0.10.0/rc8/index.html—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/bazelbuild/bazel/issues/4537#issuecomment-361678208,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABUIF99OmCfEMmutyAUmwJ1L2mAeHym5ks5tP1ehgaJpZM4Rw9x9
.
Never mind. Saw the other thread.
On Tue, 30 Jan 2018 at 20:44 ittai zeidman ittaiz@gmail.com wrote:
Irina,
Did you override rc8 somehow? Because Alon said he tested with rc8
On Tue, 30 Jan 2018 at 19:55 Irina Iancu notifications@github.com wrote:@barlevalon https://github.com/barlevalon do you mind trying again
with RC8? https://releases.bazel.build/0.10.0/rc8/index.html—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/bazelbuild/bazel/issues/4537#issuecomment-361678208,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABUIF99OmCfEMmutyAUmwJ1L2mAeHym5ks5tP1ehgaJpZM4Rw9x9
.
Yes I did. There was no point in having a broken RC.
Looks good now. 👌