From patchwork Thu Oct 13 15:50:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryce Ferguson X-Patchwork-Id: 681841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3svwFK3PFhz9snm for ; Fri, 14 Oct 2016 02:51:17 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id C26B5C1CC9; Thu, 13 Oct 2016 15:51:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I7IAHyIlnlMH; Thu, 13 Oct 2016 15:51:15 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3CCFDC1CF7; Thu, 13 Oct 2016 15:51:15 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id D992C1CF602 for ; Thu, 13 Oct 2016 15:51:13 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id D2534C1CF7 for ; Thu, 13 Oct 2016 15:51:13 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Mgn0vhaYWGOq for ; Thu, 13 Oct 2016 15:51:13 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from secvs01.rockwellcollins.com (secvs01.rockwellcollins.com [205.175.225.240]) by fraxinus.osuosl.org (Postfix) with ESMTPS id C9C56C1CC9 for ; Thu, 13 Oct 2016 15:51:12 +0000 (UTC) Received: from ofwgwc03.rockwellcollins.com (HELO ciulimr01.rockwellcollins.com) ([205.175.225.12]) by secvs01.rockwellcollins.com with ESMTP; 13 Oct 2016 10:51:12 -0500 X-Received: from largo.rockwellcollins.com (unknown [192.168.140.76]) by ciulimr01.rockwellcollins.com (Postfix) with ESMTP id 9DA83602FC; Thu, 13 Oct 2016 10:51:11 -0500 (CDT) From: Bryce Ferguson To: buildroot@buildroot.org Date: Thu, 13 Oct 2016 10:50:59 -0500 Message-Id: <1476373859-51202-1-git-send-email-bryce.ferguson@rockwellcollins.com> X-Mailer: git-send-email 1.9.1 Cc: Bryce Ferguson , Brandon Maier Subject: [Buildroot] [PATCH 1/1] support/download: Add git download method for SHAs X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Brandon Maier Shallow clones don't work for downloading SHAs. However it's common to track a tag or branch by the commit SHA so that a branch or tag doesn't unexpectedly change. We can take advantage of this scenario by searching the remote for a ref that it equivalent to our sha, then shallow cloning that ref instead. Signed-off-by: Brandon Maier Signed-off-by: Bryce Ferguson --- support/download/git | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/support/download/git b/support/download/git index 281db61..1c6548d 100755 --- a/support/download/git +++ b/support/download/git @@ -55,6 +55,23 @@ if [ -n "$(_git ls-remote "'${repo}'" "'${cset}'" 2>&1)" ]; then fi fi if [ ${git_done} -eq 0 ]; then + # See if $cset is a sha that maps to a branch, then shallow clone that branch + equivalent_ref="$(_git ls-remote --heads --tags "'${repo}'" | awk "/^${cset}/{ print \$2; exit }" | sed 's,refs/\(tags\|heads\)/,,')" + if [ -n "$equivalent_ref" ]; then + printf "Doing shallow clone with cset '%s' as '%s'\n" "$cset" "$equivalent_ref" + if _git clone ${verbose} "${@}" --depth 1 -b "'${equivalent_ref}'" "'${repo}'" "'${basename}'"; then + if (cd "${basename}" && _git show "'${cset}'" >/dev/null 2>&1); then + git_done=1 + else + rm -rf "${basename}" + printf "Shallow clone failed, checked out wrong revision, falling back to doing a full clone\n" + fi + else + printf "Shallow clone failed, falling back to doing a full clone\n" + fi + fi +fi +if [ ${git_done} -eq 0 ]; then printf "Doing full clone\n" _git clone ${verbose} "${@}" "'${repo}'" "'${basename}'" fi