summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorYu Ke <ke.yu@intel.com>2011-01-26 20:14:06 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-02-02 17:19:18 +0000
commit0e837e6844be449659bb96a1498e54a8b9442d13 (patch)
tree79c3f4dada68ff4c4d2d4d2d37d17eced8846f47 /bitbake/lib/bb/fetch2/git.py
parentaffcfe468a0c2993c0c4ace446248f85aee4315f (diff)
downloadpoky-0e837e6844be449659bb96a1498e54a8b9442d13.tar.gz
fetch2: Allow multiple src rev to be used in one src_uri
* SRC_URI format: the SRC_URI are extended to allow multiple src rev: name=<name1>,<name2>,...<name-n> branch=<branch1>,<branch2>,...,<branch-n> also SRCREV can be defined with SRCREV_<name1> = xxxxx SRCREV_<name2> = xxxxx * FetchData extention to support multiple src rev, several FetchData data are added: - FetchData.names: list of name in SRC_URI, one name per srcrev. name is the index of revision and branch - FetchData.revisions: dictionary of name->revision. - FetchData.branches: dictionary of name->branch. For example, linux-yocto recipes becomes: SRC_URI = "git://git.pokylinux.org/linux-yocto-2.6.37;protocol=git;branch=${KBRANCH},meta;name=machine,meta" FetchData.names = ['machine', 'meta'] FetchData.revisions = { 'machine':xxxxx, 'meta':xxxxxx } FetchData.branches = { 'machine':${KBRANCH}, 'meta':'meta'} * generic revision handling extension the related revision handling code in fetch2.__init__.py are changed accordingly. the major change is add name parameter to indicate which src rev to handling. originally there is one src rev per FetchData, so FetchData parameter is enough. now since one FetchData has multiple src rev, it is necessary to use FetchData + name to specifiy src rev. * git extension git fetcher are also revised to take advantage of the multiple src rev in FetchData. especially the download() method are enhanced to fetch multiple src rev. * other fetcher (svn, hg, ...) does not support multiple src rev. they just sync the API to add name, and then simply ignore the name. no actually functional change Signed-off-by: Yu Ke <ke.yu@intel.com>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r--bitbake/lib/bb/fetch2/git.py66
1 files changed, 31 insertions, 35 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 07af02f061..c54d826a01 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -57,7 +57,13 @@ class Git(Fetch):
57 if 'nocheckout' in ud.parm: 57 if 'nocheckout' in ud.parm:
58 ud.nocheckout = True 58 ud.nocheckout = True
59 59
60 ud.branch = ud.parm.get("branch", "master") 60 branches = ud.parm.get("branch", "master").split(',')
61 if len(branches) != len(ud.names):
62 raise bb.fetch2.ParameterError("SRC_URI (%) name and branch number mismatch" % ud.url)
63 ud.branches = {}
64 for name in ud.names:
65 branch = branches[ud.names.index(name)]
66 ud.branches[name] = branch
61 67
62 gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.')) 68 gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.'))
63 ud.mirrortarball = 'git_%s.tar.gz' % (gitsrcname) 69 ud.mirrortarball = 'git_%s.tar.gz' % (gitsrcname)
@@ -66,25 +72,18 @@ class Git(Fetch):
66 ud.basecmd = data.getVar("FETCHCMD_git", d, True) or "git" 72 ud.basecmd = data.getVar("FETCHCMD_git", d, True) or "git"
67 73
68 def localpath(self, url, ud, d): 74 def localpath(self, url, ud, d):
69 ud.tag = ud.revision 75 for name in ud.names:
70 if not ud.tag or ud.tag == "master": 76 if not ud.revisions[name] or ud.revisions[name] == "master":
71 ud.tag = self.latest_revision(url, ud, d) 77 ud.revisions[name] = self.latest_revision(url, ud, d, name)
72 78
73 ud.localfile = ud.mirrortarball 79 ud.localfile = ud.mirrortarball
74 80
75 if 'noclone' in ud.parm:
76 ud.localfile = None
77 return None
78
79 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) 81 return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
80 82
81 def forcefetch(self, url, ud, d): 83 def forcefetch(self, url, ud, d):
82 if 'fullclone' in ud.parm: 84 for name in ud.names:
83 return True 85 if not self._contains_ref(ud.revisions[name], d):
84 if 'noclone' in ud.parm: 86 return True
85 return False
86 if not self._contains_ref(ud.tag, d):
87 return True
88 return False 87 return False
89 88
90 def try_premirror(self, u, ud, d): 89 def try_premirror(self, u, ud, d):
@@ -122,18 +121,15 @@ class Git(Fetch):
122 121
123 os.chdir(ud.clonedir) 122 os.chdir(ud.clonedir)
124 # Update the checkout if needed 123 # Update the checkout if needed
125 if not self._contains_ref(ud.tag, d) or 'fullclone' in ud.parm: 124 for name in ud.names:
126 # Remove all but the .git directory 125 if not self._contains_ref(ud.revisions[name], d):
127 bb.fetch2.check_network_access(d, "git fetch %s%s" %(ud.host, ud.path)) 126 # Remove all but the .git directory
128 runfetchcmd("rm * -Rf", d) 127 bb.fetch2.check_network_access(d, "git fetch %s%s" %(ud.host, ud.path))
129 if 'fullclone' in ud.parm: 128 runfetchcmd("%s fetch %s://%s%s%s %s" % (ud.basecmd, ud.proto, username, ud.host, ud.path, ud.branches[name]), d)
130 runfetchcmd("%s fetch --all" % (ud.basecmd), d) 129 runfetchcmd("%s fetch --tags %s://%s%s%s" % (ud.basecmd, ud.proto, username, ud.host, ud.path), d)
131 else: 130 runfetchcmd("%s prune-packed" % ud.basecmd, d)
132 runfetchcmd("%s fetch %s://%s%s%s %s" % (ud.basecmd, ud.proto, username, ud.host, ud.path, ud.branch), d) 131 runfetchcmd("%s pack-redundant --all | xargs -r rm" % ud.basecmd, d)
133 runfetchcmd("%s fetch --tags %s://%s%s%s" % (ud.basecmd, ud.proto, username, ud.host, ud.path), d) 132 ud.repochanged = True
134 runfetchcmd("%s prune-packed" % ud.basecmd, d)
135 runfetchcmd("%s pack-redundant --all | xargs -r rm" % ud.basecmd, d)
136 ud.repochanged = True
137 133
138 def build_mirror_data(self, url, ud, d): 134 def build_mirror_data(self, url, ud, d):
139 # Generate a mirror tarball if needed 135 # Generate a mirror tarball if needed
@@ -141,7 +137,7 @@ class Git(Fetch):
141 137
142 os.chdir(ud.clonedir) 138 os.chdir(ud.clonedir)
143 mirror_tarballs = data.getVar("BB_GENERATE_MIRROR_TARBALLS", d, True) 139 mirror_tarballs = data.getVar("BB_GENERATE_MIRROR_TARBALLS", d, True)
144 if (mirror_tarballs != "0" or 'fullclone' in ud.parm) and ud.repochanged: 140 if mirror_tarballs != "0" and ud.repochanged:
145 logger.info("Creating tarball of git repository") 141 logger.info("Creating tarball of git repository")
146 runfetchcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ), d) 142 runfetchcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ), d)
147 143
@@ -165,7 +161,7 @@ class Git(Fetch):
165 runfetchcmd("cp -af %s/.git/packed-refs %s/.git/" %(ud.clonedir, destdir), d) 161 runfetchcmd("cp -af %s/.git/packed-refs %s/.git/" %(ud.clonedir, destdir), d)
166 if not ud.nocheckout: 162 if not ud.nocheckout:
167 os.chdir(destdir) 163 os.chdir(destdir)
168 runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.tag, readpathspec), d) 164 runfetchcmd("%s read-tree %s%s" % (ud.basecmd, ud.revisions[ud.names[0]], readpathspec), d)
169 runfetchcmd("%s checkout-index -q -f -a" % ud.basecmd, d) 165 runfetchcmd("%s checkout-index -q -f -a" % ud.basecmd, d)
170 return True 166 return True
171 167
@@ -177,13 +173,13 @@ class Git(Fetch):
177 output = runfetchcmd("%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % (basecmd, tag), d, quiet=True) 173 output = runfetchcmd("%s log --pretty=oneline -n 1 %s -- 2> /dev/null | wc -l" % (basecmd, tag), d, quiet=True)
178 return output.split()[0] != "0" 174 return output.split()[0] != "0"
179 175
180 def _revision_key(self, url, ud, d): 176 def _revision_key(self, url, ud, d, name):
181 """ 177 """
182 Return a unique key for the url 178 Return a unique key for the url
183 """ 179 """
184 return "git:" + ud.host + ud.path.replace('/', '.') + ud.branch 180 return "git:" + ud.host + ud.path.replace('/', '.') + ud.branches[name]
185 181
186 def _latest_revision(self, url, ud, d): 182 def _latest_revision(self, url, ud, d, name):
187 """ 183 """
188 Compute the HEAD revision for the url 184 Compute the HEAD revision for the url
189 """ 185 """
@@ -192,16 +188,16 @@ class Git(Fetch):
192 else: 188 else:
193 username = "" 189 username = ""
194 190
195 bb.fetch2.check_network_access(d, "git ls-remote %s%s %s" % (ud.host, ud.path, ud.branch)) 191 bb.fetch2.check_network_access(d, "git ls-remote %s%s %s" % (ud.host, ud.path, ud.branches[name]))
196 basecmd = data.getVar("FETCHCMD_git", d, True) or "git" 192 basecmd = data.getVar("FETCHCMD_git", d, True) or "git"
197 cmd = "%s ls-remote %s://%s%s%s %s" % (basecmd, ud.proto, username, ud.host, ud.path, ud.branch) 193 cmd = "%s ls-remote %s://%s%s%s %s" % (basecmd, ud.proto, username, ud.host, ud.path, ud.branches[name])
198 output = runfetchcmd(cmd, d, True) 194 output = runfetchcmd(cmd, d, True)
199 if not output: 195 if not output:
200 raise bb.fetch2.FetchError("Fetch command %s gave empty output\n" % (cmd)) 196 raise bb.fetch2.FetchError("Fetch command %s gave empty output\n" % (cmd))
201 return output.split()[0] 197 return output.split()[0]
202 198
203 def _build_revision(self, url, ud, d): 199 def _build_revision(self, url, ud, d, name):
204 return ud.tag 200 return ud.revisions[name]
205 201
206 def _sortable_buildindex_disabled(self, url, ud, d, rev): 202 def _sortable_buildindex_disabled(self, url, ud, d, rev):
207 """ 203 """