How to modify a PKGBUILD which uses git sources to pull only a shallow clone?
This can be done by using a custom dlagent. I do not really understand Arch packaging or how the dlagents work, so I only have a hack answer, but it gets the job done.
The idea is to modify the PKGBUILD to use a custom download agent. I modified the source
"${pkgname%-git}::git+http://github.com/Itseez/opencv.git"
into
"${pkgname%-git}::mygit://opencv.git"
and then defined a new dlagent called mygit
which does a shallow clone. I did this by adding to the DLAGENTS
array in /etc/makepkg.conf
the following dlagent:
'mygit::/usr/bin/git clone --depth 1 http://github.com/Itseez/opencv.git'
My guess is you could probably define this download agent somewhere else, but I do not know how. Also notice that the repository that is being cloned is hard coded into the command. Again, this can probably be avoided. Finally, the download location is not what the PKGBUILD expects. To work around this, I simply move the repository after downloading it. I do this by adding
mv "${srcdir}/../mygit:/opencv.git" "${srcdir}/../${pkgname%-git}"
at the beginning of the pkgver
function.
I think the cleaner solution would be to figure out what the git+http
dlagent is doing and redfine that temporarily. This should avoid all the hack aspects of the solution.
Personally I modified the makepkg script and it's working like a charm:
# vim `which makepkg` +/clone
...
541 msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
542 if ! git clone --mirror "$url" "$dir"; then
543 error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
...
Appending "--mirror --single-branch --depth 1" to the "git clone" command:
541 msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
542 if ! git clone --mirror --single-branch --depth 1 "$url" "$dir"; then
543 error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
Here is a diff view:
--- makepkg ...
+++ makepkg-patched ...
@@ -539,7 +539,7 @@
if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
- if ! git clone --mirror "$url" "$dir"; then
+ if ! git clone --mirror --single-branch --depth 1 "$url" "$dir"; then
error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
plain "$(gettext "Aborting...")"
exit 1
According to https://bugs.archlinux.org/task/23065 (credit to jasonwryan), adding shallow cloning functionality to AUR PKGBUILD was a wishlist item that was closed on Saturday, 05 March 2011 with the comment:
Reason for closing: Won't implement
This suggests that it is not going to happen unless someone submits a patch.
As I suggested to the poster in comments, what he is trying to do can almost certainly be accomplished by breaking the process up into two steps:
- Clone the git repository using shallow clone
- Run the PKGBUILD recipe, but point it at the local clone. I am not an Arch User, so don't know whether this is the case, but I'd be very surprised at a package building system that forced users to clone repositories from remote in order to build packages.