2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 BitBake 'Fetch' git implementation
7 Copyright (C) 2005 Richard Purdie
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place, Suite 330, Boston, MA 02111-1307 USA.
26 from bb.fetch import Fetch
27 from bb.fetch import FetchError
30 # Delete everything reachable from the directory named in 'topdir'.
31 # CAUTION: This is dangerous!
32 for root, dirs, files in os.walk(topdir, topdown=False):
34 os.remove(os.path.join(root, name))
36 os.rmdir(os.path.join(root, name))
40 bb.debug(1, "Running %s" % cmd)
42 # Need to export PATH as git is likely to be in metadata paths
43 # rather than host provided
44 pathcmd = 'export PATH=%s; %s' % (data.expand('${PATH}', d), cmd)
46 myret = os.system(pathcmd)
49 raise FetchError("Git: %s failed" % pathcmd)
62 """Class to fetch a module or modules from git repositories"""
64 """Check to see if a given url can be fetched with cvs.
65 Expects supplied url in list form, as outputted by bb.decodeurl().
67 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
68 return type in ['git']
69 supports = staticmethod(supports)
71 def localpath(url, d):
72 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
74 #if user sets localpath for file, use it instead.
75 if "localpath" in parm:
76 return parm["localpath"]
80 localname = data.expand('git_%s%s_%s.tar.gz' % (host, path.replace('/', '.'), tag), d)
82 return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s' % (localname), d))
84 localpath = staticmethod(localpath)
86 def go(self, d, urls = []):
92 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, d))
96 gitsrcname = '%s%s' % (host, path.replace('/', '.'))
98 repofile = os.path.join(data.getVar("DL_DIR", d, 1), 'git_%s.tar.gz' % (gitsrcname))
99 repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname)
101 coname = '%s' % (tag)
102 codir = os.path.join(repodir, coname)
104 cofile = self.localpath(loc, d)
106 # Always update to current if tag=="master"
107 #if os.access(cofile, os.R_OK) and (tag != "master"):
108 if os.access(cofile, os.R_OK):
109 bb.debug(1, "%s already exists, skipping git checkout." % cofile)
112 # Still Need to add GIT_TARBALL_STASH Support...
113 # if Fetch.try_mirror(d, tarfn):
116 #if os.path.exists(repodir):
119 bb.mkdirhier(repodir)
122 #print("Changing to %s" % repodir)
124 if os.access(repofile, os.R_OK):
125 rungitcmd("tar -xzf %s" % (repofile),d)
127 rungitcmd("git clone rsync://%s%s %s" % (host, path, repodir),d)
129 rungitcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (host, path, os.path.join(repodir, ".git", "")),d)
131 #print("Changing to %s" % repodir)
133 rungitcmd("git pull rsync://%s%s" % (host, path),d)
135 #print("Changing to %s" % repodir)
137 rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d)
139 if os.path.exists(codir):
142 #print("Changing to %s" % repodir)
145 rungitcmd("git read-tree %s" % (tag),d)
147 rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d)
149 #print("Changing to %s" % codir)
151 rungitcmd("tar -czf %s %s" % (cofile, os.path.join(".", "*") ),d)