diff options
author | Matt Madison <matt@madison.systems> | 2016-08-10 10:08:16 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-08-20 16:08:59 +0100 |
commit | ab09541d5517da9b1a23923ea8f5c26ddf745084 (patch) | |
tree | b0b81a809ec783b7481c012b430b9f6618e87a73 /bitbake/lib/bb/fetch2/git.py | |
parent | eefb4b66c8628fbf366ebc5c23cfe013c8fa3756 (diff) | |
download | poky-ab09541d5517da9b1a23923ea8f5c26ddf745084.tar.gz |
bitbake: fetch2: preserve current working directory
Fix the methods in all fetchers so they don't change
the current working directory of the calling process, which
could lead to "changed cwd" warnings from bitbake.
(Bitbake rev: 6aa78bf3bd1f75728209e2d01faef31cb8887333)
Signed-off-by: Matt Madison <matt@madison.systems>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index fd8f3fdf4d..1bec60ab71 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py | |||
@@ -219,9 +219,8 @@ class Git(FetchMethod): | |||
219 | def need_update(self, ud, d): | 219 | def need_update(self, ud, d): |
220 | if not os.path.exists(ud.clonedir): | 220 | if not os.path.exists(ud.clonedir): |
221 | return True | 221 | return True |
222 | os.chdir(ud.clonedir) | ||
223 | for name in ud.names: | 222 | for name in ud.names: |
224 | if not self._contains_ref(ud, d, name): | 223 | if not self._contains_ref(ud, d, name, ud.clonedir): |
225 | return True | 224 | return True |
226 | if ud.write_tarballs and not os.path.exists(ud.fullmirror): | 225 | if ud.write_tarballs and not os.path.exists(ud.fullmirror): |
227 | return True | 226 | return True |
@@ -242,8 +241,7 @@ class Git(FetchMethod): | |||
242 | # If the checkout doesn't exist and the mirror tarball does, extract it | 241 | # If the checkout doesn't exist and the mirror tarball does, extract it |
243 | if not os.path.exists(ud.clonedir) and os.path.exists(ud.fullmirror): | 242 | if not os.path.exists(ud.clonedir) and os.path.exists(ud.fullmirror): |
244 | bb.utils.mkdirhier(ud.clonedir) | 243 | bb.utils.mkdirhier(ud.clonedir) |
245 | os.chdir(ud.clonedir) | 244 | runfetchcmd("tar -xzf %s" % (ud.fullmirror), d, workdir=ud.clonedir) |
246 | runfetchcmd("tar -xzf %s" % (ud.fullmirror), d) | ||
247 | 245 | ||
248 | repourl = self._get_repo_url(ud) | 246 | repourl = self._get_repo_url(ud) |
249 | 247 | ||
@@ -258,34 +256,32 @@ class Git(FetchMethod): | |||
258 | progresshandler = GitProgressHandler(d) | 256 | progresshandler = GitProgressHandler(d) |
259 | runfetchcmd(clone_cmd, d, log=progresshandler) | 257 | runfetchcmd(clone_cmd, d, log=progresshandler) |
260 | 258 | ||
261 | os.chdir(ud.clonedir) | ||
262 | # Update the checkout if needed | 259 | # Update the checkout if needed |
263 | needupdate = False | 260 | needupdate = False |
264 | for name in ud.names: | 261 | for name in ud.names: |
265 | if not self._contains_ref(ud, d, name): | 262 | if not self._contains_ref(ud, d, name, ud.clonedir): |
266 | needupdate = True | 263 | needupdate = True |
267 | if needupdate: | 264 | if needupdate: |
268 | try: | 265 | try: |
269 | runfetchcmd("%s remote rm origin" % ud.basecmd, d) | 266 | runfetchcmd("%s remote rm origin" % ud.basecmd, d, workdir=ud.clonedir) |
270 | except bb.fetch2.FetchError: | 267 | except bb.fetch2.FetchError: |
271 | logger.debug(1, "No Origin") | 268 | logger.debug(1, "No Origin") |
272 | 269 | ||
273 | runfetchcmd("%s remote add --mirror=fetch origin %s" % (ud.basecmd, repourl), d) | 270 | runfetchcmd("%s remote add --mirror=fetch origin %s" % (ud.basecmd, repourl), d, workdir=ud.clonedir) |
274 | fetch_cmd = "LANG=C %s fetch -f --prune --progress %s refs/*:refs/*" % (ud.basecmd, repourl) | 271 | fetch_cmd = "LANG=C %s fetch -f --prune --progress %s refs/*:refs/*" % (ud.basecmd, repourl) |
275 | if ud.proto.lower() != 'file': | 272 | if ud.proto.lower() != 'file': |
276 | bb.fetch2.check_network_access(d, fetch_cmd, ud.url) | 273 | bb.fetch2.check_network_access(d, fetch_cmd, ud.url) |
277 | progresshandler = GitProgressHandler(d) | 274 | progresshandler = GitProgressHandler(d) |
278 | runfetchcmd(fetch_cmd, d, log=progresshandler) | 275 | runfetchcmd(fetch_cmd, d, log=progresshandler, workdir=ud.clonedir) |
279 | runfetchcmd("%s prune-packed" % ud.basecmd, d) | 276 | runfetchcmd("%s prune-packed" % ud.basecmd, d, workdir=ud.clonedir) |
280 | runfetchcmd("%s pack-redundant --all | xargs -r rm" % ud.basecmd, d) | 277 | runfetchcmd("%s pack-redundant --all | xargs -r rm" % ud.basecmd, d, workdir=ud.clonedir) |
281 | try: | 278 | try: |
282 | os.unlink(ud.fullmirror) | 279 | os.unlink(ud.fullmirror) |
283 | except OSError as exc: | 280 | except OSError as exc: |
284 | if exc.errno != errno.ENOENT: | 281 | if exc.errno != errno.ENOENT: |
285 | raise | 282 | raise |
286 | os.chdir(ud.clonedir) | ||
287 | for name in ud.names: | 283 | for name in ud.names: |
288 | if not self._contains_ref(ud, d, name): | 284 | if not self._contains_ref(ud, d, name, ud.clonedir): |
289 | raise bb.fetch2.FetchError("Unable to find revision %s in branch %s even from upstream" % (ud.revisions[name], ud.branches[name])) | 285 | raise bb.fetch2.FetchError("Unable to find revision %s in branch %s even from upstream" % (ud.revisions[name], ud.branches[name])) |
290 | 286 | ||
291 | def build_mirror_data(self, ud, d): | 287 | def build_mirror_data(self, ud, d): |
@@ -295,10 +291,9 @@ class Git(FetchMethod): | |||
295 | if os.path.islink(ud.fullmirror): | 291 | if os.path.islink(ud.fullmirror): |
296 | os.unlink(ud.fullmirror) | 292 | os.unlink(ud.fullmirror) |
297 | 293 | ||
298 | os.chdir(ud.clonedir) | ||
299 | logger.info("Creating tarball of git repository") | 294 | logger.info("Creating tarball of git repository") |
300 | runfetchcmd("tar -czf %s %s" % (ud.fullmirror, os.path.join(".") ), d) | 295 | runfetchcmd("tar -czf %s %s" % (ud.fullmirror, os.path.join(".") ), d, workdir=ud.clonedir) |
301 | runfetchcmd("touch %s.done" % (ud.fullmirror), d) | 296 | runfetchcmd("touch %s.done" % (ud.fullmirror), d, workdir=ud.clonedir) |
302 | 297 | ||
303 | def unpack(self, ud, destdir, d): | 298 | def unpack(self, ud, destdir, d): |
304 | """ unpack the downloaded src to destdir""" | 299 | """ unpack the downloaded src to destdir""" |
@@ -321,21 +316,21 @@ class Git(FetchMethod): | |||
321 | cloneflags += " --mirror" | 316 | cloneflags += " --mirror" |
322 | 317 | ||
323 | runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, cloneflags, ud.clonedir, destdir), d) | 318 | runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, cloneflags, ud.clonedir, destdir), d) |
324 | os.chdir(destdir) | ||
325 | repourl = self._get_repo_url(ud) | 319 | repourl = self._get_repo_url(ud) |
326 | runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, repourl), d) | 320 | runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, repourl), d, workdir=destdir) |
327 | if not ud.nocheckout: | 321 | if not ud.nocheckout: |
328 | if subdir != "": | 322 | if subdir != "": |
329 | runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.revisions[ud.names[0]], readpathspec), d) | 323 | runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.revisions[ud.names[0]], readpathspec), d, |
330 | runfetchcmd("%s checkout-index -q -f -a" % ud.basecmd, d) | 324 | workdir=destdir) |
325 | runfetchcmd("%s checkout-index -q -f -a" % ud.basecmd, d, workdir=destdir) | ||
331 | elif not ud.nobranch: | 326 | elif not ud.nobranch: |
332 | branchname = ud.branches[ud.names[0]] | 327 | branchname = ud.branches[ud.names[0]] |
333 | runfetchcmd("%s checkout -B %s %s" % (ud.basecmd, branchname, \ | 328 | runfetchcmd("%s checkout -B %s %s" % (ud.basecmd, branchname, \ |
334 | ud.revisions[ud.names[0]]), d) | 329 | ud.revisions[ud.names[0]]), d, workdir=destdir) |
335 | runfetchcmd("%s branch --set-upstream %s origin/%s" % (ud.basecmd, branchname, \ | 330 | runfetchcmd("%s branch --set-upstream %s origin/%s" % (ud.basecmd, branchname, \ |
336 | branchname), d) | 331 | branchname), d, workdir=destdir) |
337 | else: | 332 | else: |
338 | runfetchcmd("%s checkout %s" % (ud.basecmd, ud.revisions[ud.names[0]]), d) | 333 | runfetchcmd("%s checkout %s" % (ud.basecmd, ud.revisions[ud.names[0]]), d, workdir=destdir) |
339 | 334 | ||
340 | return True | 335 | return True |
341 | 336 | ||
@@ -349,7 +344,7 @@ class Git(FetchMethod): | |||
349 | def supports_srcrev(self): | 344 | def supports_srcrev(self): |
350 | return True | 345 | return True |
351 | 346 | ||
352 | def _contains_ref(self, ud, d, name): | 347 | def _contains_ref(self, ud, d, name, wd): |
353 | cmd = "" | 348 | cmd = "" |
354 | if ud.nobranch: | 349 | if ud.nobranch: |
355 | cmd = "%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % ( | 350 | cmd = "%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % ( |
@@ -358,7 +353,7 @@ class Git(FetchMethod): | |||
358 | cmd = "%s branch --contains %s --list %s 2> /dev/null | wc -l" % ( | 353 | cmd = "%s branch --contains %s --list %s 2> /dev/null | wc -l" % ( |
359 | ud.basecmd, ud.revisions[name], ud.branches[name]) | 354 | ud.basecmd, ud.revisions[name], ud.branches[name]) |
360 | try: | 355 | try: |
361 | output = runfetchcmd(cmd, d, quiet=True) | 356 | output = runfetchcmd(cmd, d, quiet=True, workdir=wd) |
362 | except bb.fetch2.FetchError: | 357 | except bb.fetch2.FetchError: |
363 | return False | 358 | return False |
364 | if len(output.split()) > 1: | 359 | if len(output.split()) > 1: |