summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch/git.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch/git.py')
-rw-r--r--bitbake/lib/bb/fetch/git.py144
1 files changed, 58 insertions, 86 deletions
diff --git a/bitbake/lib/bb/fetch/git.py b/bitbake/lib/bb/fetch/git.py
index 49235c141e..75a7629223 100644
--- a/bitbake/lib/bb/fetch/git.py
+++ b/bitbake/lib/bb/fetch/git.py
@@ -37,7 +37,7 @@ def prunedir(topdir):
37 37
38def rungitcmd(cmd,d): 38def rungitcmd(cmd,d):
39 39
40 bb.debug(1, "Running %s" % cmd) 40 bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % cmd)
41 41
42 # Need to export PATH as git is likely to be in metadata paths 42 # Need to export PATH as git is likely to be in metadata paths
43 # rather than host provided 43 # rather than host provided
@@ -48,108 +48,80 @@ def rungitcmd(cmd,d):
48 if myret != 0: 48 if myret != 0:
49 raise FetchError("Git: %s failed" % pathcmd) 49 raise FetchError("Git: %s failed" % pathcmd)
50 50
51def gettag(parm):
52 if 'tag' in parm:
53 tag = parm['tag']
54 else:
55 tag = ""
56 if not tag:
57 tag = "master"
58
59 return tag
60
61def getprotocol(parm):
62 if 'protocol' in parm:
63 proto = parm['protocol']
64 else:
65 proto = ""
66 if not proto:
67 proto = "rsync"
68
69 return proto
70
71def localfile(url, d):
72 """Return the filename to cache the checkout in"""
73 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d))
74
75 #if user sets localpath for file, use it instead.
76 if "localpath" in parm:
77 return parm["localpath"]
78
79 tag = gettag(parm)
80
81 return data.expand('git_%s%s_%s.tar.gz' % (host, path.replace('/', '.'), tag), d)
82
83class Git(Fetch): 51class Git(Fetch):
84 """Class to fetch a module or modules from git repositories""" 52 """Class to fetch a module or modules from git repositories"""
85 def supports(url, d): 53 def supports(self, url, ud, d):
86 """Check to see if a given url can be fetched with cvs. 54 """
87 Expects supplied url in list form, as outputted by bb.decodeurl(). 55 Check to see if a given url can be fetched with cvs.
88 """ 56 """
89 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d)) 57 return ud.type in ['git']
90 return type in ['git']
91 supports = staticmethod(supports)
92 58
93 def localpath(url, d): 59 def localpath(self, url, ud, d):
94 60
95 return os.path.join(data.getVar("DL_DIR", d, 1), localfile(url, d)) 61 ud.proto = "rsync"
62 if 'protocol' in ud.parm:
63 ud.proto = ud.parm['protocol']
96 64
97 localpath = staticmethod(localpath) 65 ud.tag = "master"
66 if 'tag' in ud.parm:
67 ud.tag = ud.parm['tag']
98 68
99 def go(self, d, urls = []): 69 ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.tag), d)
100 """Fetch urls"""
101 if not urls:
102 urls = self.urls
103 70
104 for loc in urls: 71 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
105 (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, d))
106 72
107 tag = gettag(parm) 73 def forcefetch(self, url, ud, d):
108 proto = getprotocol(parm) 74 # tag=="master" must always update
75 if (ud.tag == "master"):
76 return True
77 return False
109 78
110 gitsrcname = '%s%s' % (host, path.replace('/', '.')) 79 def go(self, loc, ud, d):
80 """Fetch url"""
111 81
112 repofilename = 'git_%s.tar.gz' % (gitsrcname) 82 if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile):
113 repofile = os.path.join(data.getVar("DL_DIR", d, 1), repofilename) 83 bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % ud.localpath)
114 repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname) 84 return
115 85
116 coname = '%s' % (tag) 86 gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.'))
117 codir = os.path.join(repodir, coname)
118 87
119 cofile = self.localpath(loc, d) 88 repofilename = 'git_%s.tar.gz' % (gitsrcname)
89 repofile = os.path.join(data.getVar("DL_DIR", d, 1), repofilename)
90 repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname)
120 91
121 # tag=="master" must always update 92 coname = '%s' % (ud.tag)
122 if (tag != "master") and Fetch.try_mirror(d, localfile(loc, d)): 93 codir = os.path.join(repodir, coname)
123 bb.debug(1, "%s already exists (or was stashed). Skipping git checkout." % cofile)
124 continue
125 94
126 if not os.path.exists(repodir): 95 if not os.path.exists(repodir):
127 if Fetch.try_mirror(d, repofilename): 96 if Fetch.try_mirror(d, repofilename):
128 bb.mkdirhier(repodir) 97 bb.mkdirhier(repodir)
129 os.chdir(repodir) 98 os.chdir(repodir)
130 rungitcmd("tar -xzf %s" % (repofile),d) 99 rungitcmd("tar -xzf %s" % (repofile),d)
131 else: 100 else:
132 rungitcmd("git clone -n %s://%s%s %s" % (proto, host, path, repodir),d) 101 rungitcmd("git clone -n %s://%s%s %s" % (ud.proto, ud.host, ud.path, repodir),d)
133 102
134 os.chdir(repodir) 103 os.chdir(repodir)
135 rungitcmd("git pull %s://%s%s" % (proto, host, path),d) 104 rungitcmd("git pull %s://%s%s" % (ud.proto, ud.host, ud.path),d)
136 rungitcmd("git pull --tags %s://%s%s" % (proto, host, path),d) 105 rungitcmd("git pull --tags %s://%s%s" % (ud.proto, ud.host, ud.path),d)
137 rungitcmd("git prune-packed", d) 106 rungitcmd("git prune-packed", d)
138 # old method of downloading tags 107 rungitcmd("git pack-redundant --all | xargs -r rm", d)
139 #rungitcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (host, path, os.path.join(repodir, ".git", "")),d) 108 # Remove all but the .git directory
109 rungitcmd("rm * -Rf", d)
110 # old method of downloading tags
111 #rungitcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (ud.host, ud.path, os.path.join(repodir, ".git", "")),d)
140 112
141 os.chdir(repodir) 113 os.chdir(repodir)
142 bb.note("Creating tarball of git repository") 114 bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git repository")
143 rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d) 115 rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d)
144 116
145 if os.path.exists(codir): 117 if os.path.exists(codir):
146 prunedir(codir) 118 prunedir(codir)
147 119
148 bb.mkdirhier(codir) 120 bb.mkdirhier(codir)
149 os.chdir(repodir) 121 os.chdir(repodir)
150 rungitcmd("git read-tree %s" % (tag),d) 122 rungitcmd("git read-tree %s" % (ud.tag),d)
151 rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d) 123 rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d)
152 124
153 os.chdir(codir) 125 os.chdir(codir)
154 bb.note("Creating tarball of git checkout") 126 bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout")
155 rungitcmd("tar -czf %s %s" % (cofile, os.path.join(".", "*") ),d) 127 rungitcmd("tar -czf %s %s" % (ud.localpath, os.path.join(".", "*") ),d)