diff options
Diffstat (limited to 'bitbake/lib/bb/fetch/git.py')
| -rw-r--r-- | bitbake/lib/bb/fetch/git.py | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/bitbake/lib/bb/fetch/git.py b/bitbake/lib/bb/fetch/git.py index de415ec309..b37a09743e 100644 --- a/bitbake/lib/bb/fetch/git.py +++ b/bitbake/lib/bb/fetch/git.py | |||
| @@ -22,6 +22,7 @@ BitBake 'Fetch' git implementation | |||
| 22 | 22 | ||
| 23 | import os | 23 | import os |
| 24 | import bb | 24 | import bb |
| 25 | import bb.persist_data | ||
| 25 | from bb import data | 26 | from bb import data |
| 26 | from bb.fetch import Fetch | 27 | from bb.fetch import Fetch |
| 27 | from bb.fetch import runfetchcmd | 28 | from bb.fetch import runfetchcmd |
| @@ -117,6 +118,7 @@ class Git(Fetch): | |||
| 117 | 118 | ||
| 118 | repofile = os.path.join(data.getVar("DL_DIR", d, 1), ud.mirrortarball) | 119 | repofile = os.path.join(data.getVar("DL_DIR", d, 1), ud.mirrortarball) |
| 119 | 120 | ||
| 121 | |||
| 120 | coname = '%s' % (ud.tag) | 122 | coname = '%s' % (ud.tag) |
| 121 | codir = os.path.join(ud.clonedir, coname) | 123 | codir = os.path.join(ud.clonedir, coname) |
| 122 | 124 | ||
| @@ -206,11 +208,19 @@ class Git(Fetch): | |||
| 206 | output = runfetchcmd("%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % (basecmd, tag), d, quiet=True) | 208 | output = runfetchcmd("%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % (basecmd, tag), d, quiet=True) |
| 207 | return output.split()[0] != "0" | 209 | return output.split()[0] != "0" |
| 208 | 210 | ||
| 209 | def _revision_key(self, url, ud, d): | 211 | def _revision_key(self, url, ud, d, branch=False): |
| 210 | """ | 212 | """ |
| 211 | Return a unique key for the url | 213 | Return a unique key for the url |
| 212 | """ | 214 | """ |
| 213 | return "git:" + ud.host + ud.path.replace('/', '.') + ud.branch | 215 | key = 'git:' + ud.host + ud.path.replace('/', '.') |
| 216 | if branch: | ||
| 217 | return key + ud.branch | ||
| 218 | else: | ||
| 219 | return key | ||
| 220 | |||
| 221 | def generate_revision_key(self, url, ud, d, branch=False): | ||
| 222 | key = self._revision_key(url, ud, d, branch) | ||
| 223 | return "%s-%s" % (key, bb.data.getVar("PN", d, True) or "") | ||
| 214 | 224 | ||
| 215 | def _latest_revision(self, url, ud, d): | 225 | def _latest_revision(self, url, ud, d): |
| 216 | """ | 226 | """ |
| @@ -228,6 +238,74 @@ class Git(Fetch): | |||
| 228 | raise bb.fetch.FetchError("Fetch command %s gave empty output\n" % (cmd)) | 238 | raise bb.fetch.FetchError("Fetch command %s gave empty output\n" % (cmd)) |
| 229 | return output.split()[0] | 239 | return output.split()[0] |
| 230 | 240 | ||
| 241 | def latest_revision(self, url, ud, d): | ||
| 242 | """ | ||
| 243 | Look in the cache for the latest revision, if not present ask the SCM. | ||
| 244 | """ | ||
| 245 | persisted = bb.persist_data.persist(d) | ||
| 246 | revs = persisted['BB_URI_HEADREVS'] | ||
| 247 | |||
| 248 | key = self.generate_revision_key(url, ud, d, branch=True) | ||
| 249 | rev = revs[key] | ||
| 250 | if rev is None: | ||
| 251 | # Compatibility with old key format, no branch included | ||
| 252 | oldkey = self.generate_revision_key(url, ud, d, branch=False) | ||
| 253 | rev = revs[oldkey] | ||
| 254 | if rev is not None: | ||
| 255 | del revs[oldkey] | ||
| 256 | else: | ||
| 257 | rev = self._latest_revision(url, ud, d) | ||
| 258 | revs[key] = rev | ||
| 259 | |||
| 260 | return str(rev) | ||
| 261 | |||
| 262 | def sortable_revision(self, url, ud, d): | ||
| 263 | """ | ||
| 264 | |||
| 265 | """ | ||
| 266 | pd = bb.persist_data.persist(d) | ||
| 267 | localcounts = pd['BB_URI_LOCALCOUNT'] | ||
| 268 | key = self.generate_revision_key(url, ud, d, branch=True) | ||
| 269 | oldkey = self.generate_revision_key(url, ud, d, branch=False) | ||
| 270 | |||
| 271 | latest_rev = self._build_revision(url, ud, d) | ||
| 272 | last_rev = localcounts[key + '_rev'] | ||
| 273 | if last_rev is None: | ||
| 274 | last_rev = localcounts[oldkey + '_rev'] | ||
| 275 | if last_rev is not None: | ||
| 276 | del localcounts[oldkey + '_rev'] | ||
| 277 | localcounts[key + '_rev'] = last_rev | ||
| 278 | |||
| 279 | uselocalcount = bb.data.getVar("BB_LOCALCOUNT_OVERRIDE", d, True) or False | ||
| 280 | count = None | ||
| 281 | if uselocalcount: | ||
| 282 | count = Fetch.localcount_internal_helper(ud, d) | ||
| 283 | if count is None: | ||
| 284 | count = localcounts[key + '_count'] | ||
| 285 | if count is None: | ||
| 286 | count = localcounts[oldkey + '_count'] | ||
| 287 | if count is not None: | ||
| 288 | del localcounts[oldkey + '_count'] | ||
| 289 | localcounts[key + '_count'] = count | ||
| 290 | |||
| 291 | if last_rev == latest_rev: | ||
| 292 | return str(count + "+" + latest_rev) | ||
| 293 | |||
| 294 | buildindex_provided = hasattr(self, "_sortable_buildindex") | ||
| 295 | if buildindex_provided: | ||
| 296 | count = self._sortable_buildindex(url, ud, d, latest_rev) | ||
| 297 | if count is None: | ||
| 298 | count = "0" | ||
| 299 | elif uselocalcount or buildindex_provided: | ||
| 300 | count = str(count) | ||
| 301 | else: | ||
| 302 | count = str(int(count) + 1) | ||
| 303 | |||
| 304 | localcounts[key + '_rev'] = latest_rev | ||
| 305 | localcounts[key + '_count'] = count | ||
| 306 | |||
| 307 | return str(count + "+" + latest_rev) | ||
| 308 | |||
| 231 | def _build_revision(self, url, ud, d): | 309 | def _build_revision(self, url, ud, d): |
| 232 | return ud.tag | 310 | return ud.tag |
| 233 | 311 | ||
