Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | """ |
| 2 | BitBake 'Fetch' git annex implementation |
| 3 | """ |
| 4 | |
| 5 | # Copyright (C) 2014 Otavio Salvador |
| 6 | # Copyright (C) 2014 O.S. Systems Software LTDA. |
| 7 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 8 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
| 11 | import os |
| 12 | import bb |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | from bb.fetch2.git import Git |
| 14 | from bb.fetch2 import runfetchcmd |
| 15 | from bb.fetch2 import logger |
| 16 | |
| 17 | class GitANNEX(Git): |
| 18 | def supports(self, ud, d): |
| 19 | """ |
| 20 | Check to see if a given url can be fetched with git. |
| 21 | """ |
| 22 | return ud.type in ['gitannex'] |
| 23 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 24 | def urldata_init(self, ud, d): |
| 25 | super(GitANNEX, self).urldata_init(ud, d) |
| 26 | if ud.shallow: |
| 27 | ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*'] |
| 28 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 29 | def uses_annex(self, ud, d, wd): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | for name in ud.names: |
| 31 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 32 | runfetchcmd("%s rev-list git-annex" % (ud.basecmd), d, quiet=True, workdir=wd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | return True |
| 34 | except bb.fetch.FetchError: |
| 35 | pass |
| 36 | |
| 37 | return False |
| 38 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 39 | def update_annex(self, ud, d, wd): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | except bb.fetch.FetchError: |
| 43 | return False |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 44 | runfetchcmd("chmod u+w -R %s/annex" % (ud.clonedir), d, quiet=True, workdir=wd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | |
| 46 | return True |
| 47 | |
| 48 | def download(self, ud, d): |
| 49 | Git.download(self, ud, d) |
| 50 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 51 | if not ud.shallow or ud.localpath != ud.fullshallow: |
| 52 | if self.uses_annex(ud, d, ud.clonedir): |
| 53 | self.update_annex(ud, d, ud.clonedir) |
| 54 | |
| 55 | def clone_shallow_local(self, ud, dest, d): |
| 56 | super(GitANNEX, self).clone_shallow_local(ud, dest, d) |
| 57 | |
| 58 | try: |
| 59 | runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest) |
| 60 | except bb.fetch.FetchError: |
| 61 | pass |
| 62 | |
| 63 | if self.uses_annex(ud, d, dest): |
| 64 | runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest) |
| 65 | runfetchcmd("chmod u+w -R %s/.git/annex" % (dest), d, quiet=True, workdir=dest) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | |
| 67 | def unpack(self, ud, destdir, d): |
| 68 | Git.unpack(self, ud, destdir, d) |
| 69 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 71 | runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | except bb.fetch.FetchError: |
| 73 | pass |
| 74 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 | annex = self.uses_annex(ud, d, ud.destdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | if annex: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 77 | runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir) |
| 78 | runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir) |
| 79 | |