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 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | import bb |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | from bb.fetch2.git import Git |
| 13 | from bb.fetch2 import runfetchcmd |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 14 | |
| 15 | class GitANNEX(Git): |
| 16 | def supports(self, ud, d): |
| 17 | """ |
| 18 | Check to see if a given url can be fetched with git. |
| 19 | """ |
| 20 | return ud.type in ['gitannex'] |
| 21 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 22 | def urldata_init(self, ud, d): |
| 23 | super(GitANNEX, self).urldata_init(ud, d) |
| 24 | if ud.shallow: |
| 25 | ud.shallow_extra_refs += ['refs/heads/git-annex', 'refs/heads/synced/*'] |
| 26 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 27 | def uses_annex(self, ud, d, wd): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | for name in ud.names: |
| 29 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 30 | 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] | 31 | return True |
| 32 | except bb.fetch.FetchError: |
| 33 | pass |
| 34 | |
| 35 | return False |
| 36 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 37 | def update_annex(self, ud, d, wd): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 38 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 39 | runfetchcmd("%s annex get --all" % (ud.basecmd), d, quiet=True, workdir=wd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | except bb.fetch.FetchError: |
| 41 | return False |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 42 | 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] | 43 | |
| 44 | return True |
| 45 | |
| 46 | def download(self, ud, d): |
| 47 | Git.download(self, ud, d) |
| 48 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 49 | if not ud.shallow or ud.localpath != ud.fullshallow: |
| 50 | if self.uses_annex(ud, d, ud.clonedir): |
| 51 | self.update_annex(ud, d, ud.clonedir) |
| 52 | |
| 53 | def clone_shallow_local(self, ud, dest, d): |
| 54 | super(GitANNEX, self).clone_shallow_local(ud, dest, d) |
| 55 | |
| 56 | try: |
| 57 | runfetchcmd("%s annex init" % ud.basecmd, d, workdir=dest) |
| 58 | except bb.fetch.FetchError: |
| 59 | pass |
| 60 | |
| 61 | if self.uses_annex(ud, d, dest): |
| 62 | runfetchcmd("%s annex get" % ud.basecmd, d, workdir=dest) |
| 63 | 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] | 64 | |
| 65 | def unpack(self, ud, destdir, d): |
| 66 | Git.unpack(self, ud, destdir, d) |
| 67 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | runfetchcmd("%s annex init" % (ud.basecmd), d, workdir=ud.destdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | except bb.fetch.FetchError: |
| 71 | pass |
| 72 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 73 | annex = self.uses_annex(ud, d, ud.destdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 74 | if annex: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 | runfetchcmd("%s annex get" % (ud.basecmd), d, workdir=ud.destdir) |
| 76 | runfetchcmd("chmod u+w -R %s/.git/annex" % (ud.destdir), d, quiet=True, workdir=ud.destdir) |
| 77 | |