diff options
Diffstat (limited to 'bitbake/lib/bb/fetch/git.py')
-rw-r--r-- | bitbake/lib/bb/fetch/git.py | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/bitbake/lib/bb/fetch/git.py b/bitbake/lib/bb/fetch/git.py index c0cd27df09..7d55ee9138 100644 --- a/bitbake/lib/bb/fetch/git.py +++ b/bitbake/lib/bb/fetch/git.py | |||
@@ -25,6 +25,7 @@ import bb | |||
25 | from bb import data | 25 | from bb import data |
26 | from bb.fetch import Fetch | 26 | from bb.fetch import Fetch |
27 | from bb.fetch import FetchError | 27 | from bb.fetch import FetchError |
28 | from bb.fetch import runfetchcmd | ||
28 | 29 | ||
29 | def prunedir(topdir): | 30 | def prunedir(topdir): |
30 | # Delete everything reachable from the directory named in 'topdir'. | 31 | # Delete everything reachable from the directory named in 'topdir'. |
@@ -35,19 +36,6 @@ def prunedir(topdir): | |||
35 | for name in dirs: | 36 | for name in dirs: |
36 | os.rmdir(os.path.join(root, name)) | 37 | os.rmdir(os.path.join(root, name)) |
37 | 38 | ||
38 | def rungitcmd(cmd,d): | ||
39 | |||
40 | bb.msg.debug(1, bb.msg.domain.Fetcher, "Running %s" % cmd) | ||
41 | |||
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) | ||
45 | |||
46 | myret = os.system(pathcmd) | ||
47 | |||
48 | if myret != 0: | ||
49 | raise FetchError("Git: %s failed" % pathcmd) | ||
50 | |||
51 | class Git(Fetch): | 39 | class Git(Fetch): |
52 | """Class to fetch a module or modules from git repositories""" | 40 | """Class to fetch a module or modules from git repositories""" |
53 | def supports(self, url, ud, d): | 41 | def supports(self, url, ud, d): |
@@ -62,24 +50,22 @@ class Git(Fetch): | |||
62 | if 'protocol' in ud.parm: | 50 | if 'protocol' in ud.parm: |
63 | ud.proto = ud.parm['protocol'] | 51 | ud.proto = ud.parm['protocol'] |
64 | 52 | ||
65 | ud.tag = "master" | 53 | tag = data.getVar("SRCREV", d, 0) |
66 | if 'tag' in ud.parm: | 54 | if 'tag' in ud.parm: |
67 | ud.tag = ud.parm['tag'] | 55 | ud.tag = ud.parm['tag'] |
56 | elif tag and "get_srcrev" not in tag and len(tag) == 40: | ||
57 | ud.tag = tag | ||
58 | else: | ||
59 | ud.tag = self.latest_revision(url, ud, d) | ||
68 | 60 | ||
69 | ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.tag), d) | 61 | ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.tag), d) |
70 | 62 | ||
71 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) | 63 | return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile) |
72 | 64 | ||
73 | def forcefetch(self, url, ud, d): | ||
74 | # tag=="master" must always update | ||
75 | if (ud.tag == "master"): | ||
76 | return True | ||
77 | return False | ||
78 | |||
79 | def go(self, loc, ud, d): | 65 | def go(self, loc, ud, d): |
80 | """Fetch url""" | 66 | """Fetch url""" |
81 | 67 | ||
82 | if not self.forcefetch(loc, ud, d) and Fetch.try_mirror(d, ud.localfile): | 68 | if Fetch.try_mirror(d, ud.localfile): |
83 | bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % ud.localpath) | 69 | bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % ud.localpath) |
84 | return | 70 | return |
85 | 71 | ||
@@ -96,32 +82,50 @@ class Git(Fetch): | |||
96 | if Fetch.try_mirror(d, repofilename): | 82 | if Fetch.try_mirror(d, repofilename): |
97 | bb.mkdirhier(repodir) | 83 | bb.mkdirhier(repodir) |
98 | os.chdir(repodir) | 84 | os.chdir(repodir) |
99 | rungitcmd("tar -xzf %s" % (repofile),d) | 85 | runfetchcmd("tar -xzf %s" % (repofile), d) |
100 | else: | 86 | else: |
101 | rungitcmd("git clone -n %s://%s%s %s" % (ud.proto, ud.host, ud.path, repodir),d) | 87 | runfetchcmd("git clone -n %s://%s%s %s" % (ud.proto, ud.host, ud.path, repodir), d) |
102 | 88 | ||
103 | os.chdir(repodir) | 89 | os.chdir(repodir) |
104 | rungitcmd("git pull %s://%s%s" % (ud.proto, ud.host, ud.path),d) | ||
105 | rungitcmd("git pull --tags %s://%s%s" % (ud.proto, ud.host, ud.path),d) | ||
106 | rungitcmd("git prune-packed", d) | ||
107 | rungitcmd("git pack-redundant --all | xargs -r rm", d) | ||
108 | # Remove all but the .git directory | 90 | # Remove all but the .git directory |
109 | rungitcmd("rm * -Rf", d) | 91 | runfetchcmd("rm * -Rf", d) |
92 | runfetchcmd("git pull %s://%s%s" % (ud.proto, ud.host, ud.path), d) | ||
93 | runfetchcmd("git pull --tags %s://%s%s" % (ud.proto, ud.host, ud.path), d) | ||
94 | runfetchcmd("git prune-packed", d) | ||
95 | runfetchcmd("git pack-redundant --all | xargs -r rm", d) | ||
110 | # old method of downloading tags | 96 | # 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) | 97 | #runfetchcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (ud.host, ud.path, os.path.join(repodir, ".git", "")), d) |
112 | 98 | ||
113 | os.chdir(repodir) | 99 | os.chdir(repodir) |
114 | bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git repository") | 100 | bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git repository") |
115 | rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d) | 101 | runfetchcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ), d) |
116 | 102 | ||
117 | if os.path.exists(codir): | 103 | if os.path.exists(codir): |
118 | prunedir(codir) | 104 | prunedir(codir) |
119 | 105 | ||
120 | bb.mkdirhier(codir) | 106 | bb.mkdirhier(codir) |
121 | os.chdir(repodir) | 107 | os.chdir(repodir) |
122 | rungitcmd("git read-tree %s" % (ud.tag),d) | 108 | runfetchcmd("git read-tree %s" % (ud.tag), d) |
123 | rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d) | 109 | runfetchcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")), d) |
124 | 110 | ||
125 | os.chdir(codir) | 111 | os.chdir(codir) |
126 | bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout") | 112 | bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout") |
127 | rungitcmd("tar -czf %s %s" % (ud.localpath, os.path.join(".", "*") ),d) | 113 | runfetchcmd("tar -czf %s %s" % (ud.localpath, os.path.join(".", "*") ), d) |
114 | |||
115 | os.chdir(repodir) | ||
116 | prunedir(codir) | ||
117 | |||
118 | def suppports_srcrev(self): | ||
119 | return True | ||
120 | |||
121 | def _revision_key(self, url, ud, d): | ||
122 | """ | ||
123 | Return a unique key for the url | ||
124 | """ | ||
125 | return "git:" + ud.host + ud.path.replace('/', '.') | ||
126 | |||
127 | def _latest_revision(self, url, ud, d): | ||
128 | |||
129 | output = runfetchcmd("git ls-remote %s://%s%s" % (ud.proto, ud.host, ud.path), d, True) | ||
130 | return output.split()[0] | ||
131 | |||