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

Fix shallow clone support for libraries in recent git versions #5897

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 0 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ jobs:
- script: |
brew upgrade
brew install ccache flex bison
brew unlink git
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/1024ec738fe0972e467859ce55687e9e0131f83a/Formula/git.rb
brew switch git 2.21.0
displayName: "Install Homebrew and prerequisites"
timeoutInMinutes: 20

Expand Down
4 changes: 3 additions & 1 deletion libraries/cmake/source/modules/Findlibcryptsetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/utils.cmake")
importSourceSubmodule(
NAME "libcryptsetup"

SHALLOW_SUBMODULES
# This git repo is hosted on gitlab, which doesn't properly support
# making a shallow clone.
SUBMODULES
"src"
)
4 changes: 3 additions & 1 deletion libraries/cmake/source/modules/Findlibgcrypt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/utils.cmake")
importSourceSubmodule(
NAME "libgcrypt"

SHALLOW_SUBMODULES
# Hosting for this repo does not support shallow clones in newer
# versions of git.
SUBMODULES
"src"
)
4 changes: 3 additions & 1 deletion libraries/cmake/source/modules/Findlibgpg-error.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ include("${CMAKE_CURRENT_LIST_DIR}/utils.cmake")
importSourceSubmodule(
NAME "libgpg-error"

SHALLOW_SUBMODULES
# Hosting for this repo does not support shallow clones in newer
# versions of git.
SUBMODULES
"src"
)
11 changes: 10 additions & 1 deletion libraries/cmake/source/modules/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,19 @@ function(initializeGitSubmodule submodule_path no_recursive shallow)
set(optional_depth_arg "")
endif()

# In git versions >= 2.18.0 we need to explicitly set the protocol
# in order to do a shallow clone without error.
if(GIT_VERSION_STRING VERSION_EQUAL "2.18.0" OR GIT_VERSION_STRING VERSION_GREATER "2.18.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. To work around the gitlab issue. do we need another condition? Maybe on shallow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can work around the GitLab issue. I think this depends on their git server's configuration. It might improve in the future but the protocol-2-approach we're using has some gaps due to these server expectations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is the issue is only present for a shallow clone. So this workaround is only needed for the shallow cloning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, on my home not-very-fast cable modem

$ time git clone --quiet https://gitlab.com/cryptsetup/cryptsetup.git

real	0m4.690s
user	0m0.925s
sys	0m0.536s

From real network, it's sub 1 second.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing, I guess you can leave the -c protocol.version=2 in place even for gitlab. It just wouldn't help, but it doesn't cause an error.

If that matches your understanding, I think I'm good with this. If there are performance issues due to the cloning, we should tackle them separately, possible by mirroring to github.

set(optional_protocol_arg -c protocol.version=2)
else()
set(optional_protocol_arg "")
endif()


get_filename_component(working_directory "${submodule_path}" DIRECTORY)

execute_process(
COMMAND "${GIT_EXECUTABLE}" submodule update --init ${optional_recursive_arg} ${optional_depth_arg} "${submodule_path}"
COMMAND "${GIT_EXECUTABLE}" ${optional_protocol_arg} submodule update --init ${optional_recursive_arg} ${optional_depth_arg} "${submodule_path}"
RESULT_VARIABLE process_exit_code
WORKING_DIRECTORY "${working_directory}"
)
Expand Down