diff options
| author | Richard Purdie <rpurdie@linux.intel.com> | 2010-01-20 18:46:02 +0000 |
|---|---|---|
| committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-01-20 18:46:02 +0000 |
| commit | 22c29d8651668195f72e2f6a8e059d625eb511c3 (patch) | |
| tree | dd1dd43f0ec47a9964c8a766eb8b3ad75cf51a64 /bitbake-dev/lib/bb/fetch/git.py | |
| parent | 1bfd6edef9db9c9175058ae801d1b601e4f15263 (diff) | |
| download | poky-22c29d8651668195f72e2f6a8e059d625eb511c3.tar.gz | |
bitbake: Switch to bitbake-dev version (bitbake master upstream)
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake-dev/lib/bb/fetch/git.py')
| -rw-r--r-- | bitbake-dev/lib/bb/fetch/git.py | 216 |
1 files changed, 0 insertions, 216 deletions
diff --git a/bitbake-dev/lib/bb/fetch/git.py b/bitbake-dev/lib/bb/fetch/git.py deleted file mode 100644 index 0e68325db9..0000000000 --- a/bitbake-dev/lib/bb/fetch/git.py +++ /dev/null | |||
| @@ -1,216 +0,0 @@ | |||
| 1 | # ex:ts=4:sw=4:sts=4:et | ||
| 2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
| 3 | """ | ||
| 4 | BitBake 'Fetch' git implementation | ||
| 5 | |||
| 6 | """ | ||
| 7 | |||
| 8 | #Copyright (C) 2005 Richard Purdie | ||
| 9 | # | ||
| 10 | # This program is free software; you can redistribute it and/or modify | ||
| 11 | # it under the terms of the GNU General Public License version 2 as | ||
| 12 | # published by the Free Software Foundation. | ||
| 13 | # | ||
| 14 | # This program is distributed in the hope that it will be useful, | ||
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | # GNU General Public License for more details. | ||
| 18 | # | ||
| 19 | # You should have received a copy of the GNU General Public License along | ||
| 20 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
| 21 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 22 | |||
| 23 | import os | ||
| 24 | import bb | ||
| 25 | from bb import data | ||
| 26 | from bb.fetch import Fetch | ||
| 27 | from bb.fetch import runfetchcmd | ||
| 28 | |||
| 29 | class Git(Fetch): | ||
| 30 | """Class to fetch a module or modules from git repositories""" | ||
| 31 | def init(self, d): | ||
| 32 | # | ||
| 33 | # Only enable _sortable revision if the key is set | ||
| 34 | # | ||
| 35 | if bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True): | ||
| 36 | self._sortable_buildindex = self._sortable_buildindex_disabled | ||
| 37 | def supports(self, url, ud, d): | ||
| 38 | """ | ||
| 39 | Check to see if a given url can be fetched with git. | ||
| 40 | """ | ||
| 41 | return ud.type in ['git'] | ||
| 42 | |||
| 43 | def localpath(self, url, ud, d): | ||
| 44 | |||
| 45 | if 'protocol' in ud.parm: | ||
| 46 | ud.proto = ud.parm['protocol'] | ||
| 47 | elif not ud.host: | ||
| 48 | ud.proto = 'file' | ||
| 49 | else: | ||
| 50 | ud.proto = "rsync" | ||
| 51 | |||
| 52 | ud.branch = ud.parm.get("branch", "master") | ||
| 53 | |||
| 54 | gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.')) | ||
| 55 | ud.mirrortarball = 'git_%s.tar.gz' % (gitsrcname) | ||
| 56 | ud.clonedir = os.path.join(data.expand('${GITDIR}', d), gitsrcname) | ||
| 57 | |||
| 58 | tag = Fetch.srcrev_internal_helper(ud, d) | ||
| 59 | if tag is True: | ||
| 60 | ud.tag = self.latest_revision(url, ud, d) | ||
| 61 | elif tag: | ||
| 62 | ud.tag = tag | ||
| 63 | |||
| 64 | if not ud.tag or ud.tag == "master": | ||
| 65 | ud.tag = self.latest_revision(url, ud, d) | ||
| 66 | |||
| 67 | subdir = ud.parm.get("subpath", "") | ||
| 68 | if subdir != "": | ||
| 69 | if subdir.endswith("/"): | ||
| 70 | subdir = subdir[:-1] | ||
| 71 | subdirpath = os.path.join(ud.path, subdir); | ||
| 72 | else: | ||
| 73 | subdirpath = ud.path; | ||
| 74 | |||
| 75 | if 'fullclone' in ud.parm: | ||
| 76 | ud.localfile = ud.mirrortarball | ||
| 77 | else: | ||
| 78 | ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, subdirpath.replace('/', '.'), ud.tag), d) | ||
| 79 | |||
| 80 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | ||
| 81 | |||
| 82 | def go(self, loc, ud, d): | ||
| 83 | """Fetch url""" | ||
| 84 | |||
| 85 | if Fetch.try_mirror(d, ud.localfile): | ||
| 86 | bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % ud.localpath) | ||
| 87 | return | ||
| 88 | |||
| 89 | if ud.user: | ||
| 90 | username = ud.user + '@' | ||
| 91 | else: | ||
| 92 | username = "" | ||
| 93 | |||
| 94 | repofile = os.path.join(data.getVar("DL_DIR", d, 1), ud.mirrortarball) | ||
| 95 | |||
| 96 | coname = '%s' % (ud.tag) | ||
| 97 | codir = os.path.join(ud.clonedir, coname) | ||
| 98 | |||
| 99 | if not os.path.exists(ud.clonedir): | ||
| 100 | if Fetch.try_mirror(d, ud.mirrortarball): | ||
| 101 | bb.mkdirhier(ud.clonedir) | ||
| 102 | os.chdir(ud.clonedir) | ||
| 103 | runfetchcmd("tar -xzf %s" % (repofile), d) | ||
| 104 | else: | ||
| 105 | runfetchcmd("git clone -n %s://%s%s%s %s" % (ud.proto, username, ud.host, ud.path, ud.clonedir), d) | ||
| 106 | |||
| 107 | os.chdir(ud.clonedir) | ||
| 108 | # Remove all but the .git directory | ||
| 109 | if not self._contains_ref(ud.tag, d): | ||
| 110 | runfetchcmd("rm * -Rf", d) | ||
| 111 | runfetchcmd("git fetch %s://%s%s%s %s" % (ud.proto, username, ud.host, ud.path, ud.branch), d) | ||
| 112 | runfetchcmd("git fetch --tags %s://%s%s%s" % (ud.proto, username, ud.host, ud.path), d) | ||
| 113 | runfetchcmd("git prune-packed", d) | ||
| 114 | runfetchcmd("git pack-redundant --all | xargs -r rm", d) | ||
| 115 | |||
| 116 | os.chdir(ud.clonedir) | ||
| 117 | mirror_tarballs = data.getVar("BB_GENERATE_MIRROR_TARBALLS", d, True) | ||
| 118 | if mirror_tarballs != "0" or 'fullclone' in ud.parm: | ||
| 119 | bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git repository") | ||
| 120 | runfetchcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ), d) | ||
| 121 | |||
| 122 | if 'fullclone' in ud.parm: | ||
| 123 | return | ||
| 124 | |||
| 125 | if os.path.exists(codir): | ||
| 126 | bb.utils.prunedir(codir) | ||
| 127 | |||
| 128 | subdir = ud.parm.get("subpath", "") | ||
| 129 | if subdir != "": | ||
| 130 | if subdir.endswith("/"): | ||
| 131 | subdirbase = os.path.basename(subdir[:-1]) | ||
| 132 | else: | ||
| 133 | subdirbase = os.path.basename(subdir) | ||
| 134 | else: | ||
| 135 | subdirbase = "" | ||
| 136 | |||
| 137 | if subdir != "": | ||
| 138 | readpathspec = ":%s" % (subdir) | ||
| 139 | codir = os.path.join(codir, "git") | ||
| 140 | coprefix = os.path.join(codir, subdirbase, "") | ||
| 141 | else: | ||
| 142 | readpathspec = "" | ||
| 143 | coprefix = os.path.join(codir, "git", "") | ||
| 144 | |||
| 145 | bb.mkdirhier(codir) | ||
| 146 | os.chdir(ud.clonedir) | ||
| 147 | runfetchcmd("git read-tree %s%s" % (ud.tag, readpathspec), d) | ||
| 148 | runfetchcmd("git checkout-index -q -f --prefix=%s -a" % (coprefix), d) | ||
| 149 | |||
| 150 | os.chdir(codir) | ||
| 151 | bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout") | ||
| 152 | runfetchcmd("tar -czf %s %s" % (ud.localpath, os.path.join(".", "*") ), d) | ||
| 153 | |||
| 154 | os.chdir(ud.clonedir) | ||
| 155 | bb.utils.prunedir(codir) | ||
| 156 | |||
| 157 | def suppports_srcrev(self): | ||
| 158 | return True | ||
| 159 | |||
| 160 | def _contains_ref(self, tag, d): | ||
| 161 | output = runfetchcmd("git log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % tag, d, quiet=True) | ||
| 162 | return output.split()[0] != "0" | ||
| 163 | |||
| 164 | def _revision_key(self, url, ud, d): | ||
| 165 | """ | ||
| 166 | Return a unique key for the url | ||
| 167 | """ | ||
| 168 | return "git:" + ud.host + ud.path.replace('/', '.') | ||
| 169 | |||
| 170 | def _latest_revision(self, url, ud, d): | ||
| 171 | """ | ||
| 172 | Compute the HEAD revision for the url | ||
| 173 | """ | ||
| 174 | if ud.user: | ||
| 175 | username = ud.user + '@' | ||
| 176 | else: | ||
| 177 | username = "" | ||
| 178 | |||
| 179 | cmd = "git ls-remote %s://%s%s%s %s" % (ud.proto, username, ud.host, ud.path, ud.branch) | ||
| 180 | output = runfetchcmd(cmd, d, True) | ||
| 181 | if not output: | ||
| 182 | raise bb.fetch.FetchError("Fetch command %s gave empty output\n" % (cmd)) | ||
| 183 | return output.split()[0] | ||
| 184 | |||
| 185 | def _build_revision(self, url, ud, d): | ||
| 186 | return ud.tag | ||
| 187 | |||
| 188 | def _sortable_buildindex_disabled(self, url, ud, d, rev): | ||
| 189 | """ | ||
| 190 | Return a suitable buildindex for the revision specified. This is done by counting revisions | ||
| 191 | using "git rev-list" which may or may not work in different circumstances. | ||
| 192 | """ | ||
| 193 | |||
| 194 | cwd = os.getcwd() | ||
| 195 | |||
| 196 | # Check if we have the rev already | ||
| 197 | |||
| 198 | if not os.path.exists(ud.clonedir): | ||
| 199 | print "no repo" | ||
| 200 | self.go(None, ud, d) | ||
| 201 | if not os.path.exists(ud.clonedir): | ||
| 202 | bb.msg.error(bb.msg.domain.Fetcher, "GIT repository for %s doesn't exist in %s, cannot get sortable buildnumber, using old value" % (url, ud.clonedir)) | ||
| 203 | return None | ||
| 204 | |||
| 205 | |||
| 206 | os.chdir(ud.clonedir) | ||
| 207 | if not self._contains_ref(rev, d): | ||
| 208 | self.go(None, ud, d) | ||
| 209 | |||
| 210 | output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True) | ||
| 211 | os.chdir(cwd) | ||
| 212 | |||
| 213 | buildindex = "%s" % output.split()[0] | ||
| 214 | bb.msg.debug(1, bb.msg.domain.Fetcher, "GIT repository for %s in %s is returning %s revisions in rev-list before %s" % (url, repodir, buildindex, rev)) | ||
| 215 | return buildindex | ||
| 216 | |||
