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.py73
1 files changed, 47 insertions, 26 deletions
diff --git a/bitbake/lib/bb/fetch/git.py b/bitbake/lib/bb/fetch/git.py
index 3016f0f00d..0e68325db9 100644
--- a/bitbake/lib/bb/fetch/git.py
+++ b/bitbake/lib/bb/fetch/git.py
@@ -28,6 +28,12 @@ from bb.fetch import runfetchcmd
28 28
29class Git(Fetch): 29class Git(Fetch):
30 """Class to fetch a module or modules from git repositories""" 30 """Class to fetch a module or modules from git repositories"""
31 def init(self, d):
32 #
33 # Only enable _sortable revision if the key is set
34 #
35 if bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True):
36 self._sortable_buildindex = self._sortable_buildindex_disabled
31 def supports(self, url, ud, d): 37 def supports(self, url, ud, d):
32 """ 38 """
33 Check to see if a given url can be fetched with git. 39 Check to see if a given url can be fetched with git.
@@ -58,10 +64,18 @@ class Git(Fetch):
58 if not ud.tag or ud.tag == "master": 64 if not ud.tag or ud.tag == "master":
59 ud.tag = self.latest_revision(url, ud, d) 65 ud.tag = self.latest_revision(url, ud, d)
60 66
67 subdir = ud.parm.get("subpath", "")
68 if subdir != "":
69 if subdir.endswith("/"):
70 subdir = subdir[:-1]
71 subdirpath = os.path.join(ud.path, subdir);
72 else:
73 subdirpath = ud.path;
74
61 if 'fullclone' in ud.parm: 75 if 'fullclone' in ud.parm:
62 ud.localfile = ud.mirrortarball 76 ud.localfile = ud.mirrortarball
63 else: 77 else:
64 ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.tag), d) 78 ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, subdirpath.replace('/', '.'), ud.tag), d)
65 79
66 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) 80 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
67 81
@@ -111,10 +125,27 @@ class Git(Fetch):
111 if os.path.exists(codir): 125 if os.path.exists(codir):
112 bb.utils.prunedir(codir) 126 bb.utils.prunedir(codir)
113 127
128 subdir = ud.parm.get("subpath", "")
129 if subdir != "":
130 if subdir.endswith("/"):
131 subdirbase = os.path.basename(subdir[:-1])
132 else:
133 subdirbase = os.path.basename(subdir)
134 else:
135 subdirbase = ""
136
137 if subdir != "":
138 readpathspec = ":%s" % (subdir)
139 codir = os.path.join(codir, "git")
140 coprefix = os.path.join(codir, subdirbase, "")
141 else:
142 readpathspec = ""
143 coprefix = os.path.join(codir, "git", "")
144
114 bb.mkdirhier(codir) 145 bb.mkdirhier(codir)
115 os.chdir(ud.clonedir) 146 os.chdir(ud.clonedir)
116 runfetchcmd("git read-tree %s" % (ud.tag), d) 147 runfetchcmd("git read-tree %s%s" % (ud.tag, readpathspec), d)
117 runfetchcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")), d) 148 runfetchcmd("git checkout-index -q -f --prefix=%s -a" % (coprefix), d)
118 149
119 os.chdir(codir) 150 os.chdir(codir)
120 bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout") 151 bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout")
@@ -154,42 +185,32 @@ class Git(Fetch):
154 def _build_revision(self, url, ud, d): 185 def _build_revision(self, url, ud, d):
155 return ud.tag 186 return ud.tag
156 187
157 def _sortable_revision_valid(self, url, ud, d): 188 def _sortable_buildindex_disabled(self, url, ud, d, rev):
158 return bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True) or False
159
160 def _sortable_revision(self, url, ud, d):
161 """ 189 """
162 This is only called when _sortable_revision_valid called true 190 Return a suitable buildindex for the revision specified. This is done by counting revisions
163 191 using "git rev-list" which may or may not work in different circumstances.
164 We will have to get the updated revision.
165 """ 192 """
166 193
167 key = "GIT_CACHED_REVISION-%s-%s" % (gitsrcname, ud.tag)
168 if bb.data.getVar(key, d):
169 return bb.data.getVar(key, d)
170
171
172 # Runtime warning on wrongly configured sources
173 if ud.tag == "1":
174 bb.msg.error(1, bb.msg.domain.Fetcher, "SRCREV is '1'. This indicates a configuration error of %s" % url)
175 return "0+1"
176
177 cwd = os.getcwd() 194 cwd = os.getcwd()
178 195
179 # Check if we have the rev already 196 # Check if we have the rev already
197
180 if not os.path.exists(ud.clonedir): 198 if not os.path.exists(ud.clonedir):
181 print "no repo" 199 print "no repo"
182 self.go(None, ud, d) 200 self.go(None, ud, d)
201 if not os.path.exists(ud.clonedir):
202 bb.msg.error(bb.msg.domain.Fetcher, "GIT repository for %s doesn't exist in %s, cannot get sortable buildnumber, using old value" % (url, ud.clonedir))
203 return None
204
183 205
184 os.chdir(ud.clonedir) 206 os.chdir(ud.clonedir)
185 if not self._contains_ref(ud.tag, d): 207 if not self._contains_ref(rev, d):
186 self.go(None, ud, d) 208 self.go(None, ud, d)
187 209
188 output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True) 210 output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True)
189 os.chdir(cwd) 211 os.chdir(cwd)
190 212
191 sortable_revision = "%s+%s" % (output.split()[0], ud.tag) 213 buildindex = "%s" % output.split()[0]
192 bb.data.setVar(key, sortable_revision, d) 214 bb.msg.debug(1, bb.msg.domain.Fetcher, "GIT repository for %s in %s is returning %s revisions in rev-list before %s" % (url, repodir, buildindex, rev))
193 return sortable_revision 215 return buildindex
194
195 216