diff options
Diffstat (limited to 'bitbake/lib/bb/fetch/git.py')
-rw-r--r-- | bitbake/lib/bb/fetch/git.py | 95 |
1 files changed, 42 insertions, 53 deletions
diff --git a/bitbake/lib/bb/fetch/git.py b/bitbake/lib/bb/fetch/git.py index 296b926392..439d522188 100644 --- a/bitbake/lib/bb/fetch/git.py +++ b/bitbake/lib/bb/fetch/git.py | |||
@@ -58,6 +58,28 @@ def gettag(parm): | |||
58 | 58 | ||
59 | return tag | 59 | return tag |
60 | 60 | ||
61 | def 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 | |||
71 | def 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 | |||
61 | class Git(Fetch): | 83 | class Git(Fetch): |
62 | """Class to fetch a module or modules from git repositories""" | 84 | """Class to fetch a module or modules from git repositories""" |
63 | def supports(url, d): | 85 | def supports(url, d): |
@@ -69,17 +91,8 @@ class Git(Fetch): | |||
69 | supports = staticmethod(supports) | 91 | supports = staticmethod(supports) |
70 | 92 | ||
71 | def localpath(url, d): | 93 | def localpath(url, d): |
72 | (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(url, d)) | ||
73 | |||
74 | #if user sets localpath for file, use it instead. | ||
75 | if "localpath" in parm: | ||
76 | return parm["localpath"] | ||
77 | 94 | ||
78 | tag = gettag(parm) | 95 | return os.path.join(data.getVar("DL_DIR", d, 1), localfile(url, d)) |
79 | |||
80 | localname = data.expand('git_%s%s_%s.tar.gz' % (host, path.replace('/', '.'), tag), d) | ||
81 | |||
82 | return os.path.join(data.getVar("DL_DIR", d, 1),data.expand('%s' % (localname), d)) | ||
83 | 96 | ||
84 | localpath = staticmethod(localpath) | 97 | localpath = staticmethod(localpath) |
85 | 98 | ||
@@ -92,10 +105,12 @@ class Git(Fetch): | |||
92 | (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, d)) | 105 | (type, host, path, user, pswd, parm) = bb.decodeurl(data.expand(loc, d)) |
93 | 106 | ||
94 | tag = gettag(parm) | 107 | tag = gettag(parm) |
108 | proto = getprotocol(parm) | ||
95 | 109 | ||
96 | gitsrcname = '%s%s' % (host, path.replace('/', '.')) | 110 | gitsrcname = '%s%s' % (host, path.replace('/', '.')) |
97 | 111 | ||
98 | repofile = os.path.join(data.getVar("DL_DIR", d, 1), 'git_%s.tar.gz' % (gitsrcname)) | 112 | repofilename = 'git_%s.tar.gz' % (gitsrcname) |
113 | repofile = os.path.join(data.getVar("DL_DIR", d, 1), repofilename) | ||
99 | repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname) | 114 | repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname) |
100 | 115 | ||
101 | coname = '%s' % (tag) | 116 | coname = '%s' % (tag) |
@@ -103,63 +118,37 @@ class Git(Fetch): | |||
103 | 118 | ||
104 | cofile = self.localpath(loc, d) | 119 | cofile = self.localpath(loc, d) |
105 | 120 | ||
106 | # Always update to current if tag=="master" | 121 | # tag=="master" must always update |
107 | #if os.access(cofile, os.R_OK) and (tag != "master"): | 122 | if (tag != "master") and Fetch.try_mirror(d, localfile(loc, d)): |
108 | if os.access(cofile, os.R_OK): | 123 | bb.debug(1, "%s already exists (or was stashed). Skipping git checkout." % cofile) |
109 | bb.debug(1, "%s already exists, skipping git checkout." % cofile) | ||
110 | continue | 124 | continue |
111 | 125 | ||
112 | # Still Need to add GIT_TARBALL_STASH Support... | 126 | if not os.path.exists(repodir): |
113 | # pn = data.getVar('PN', d, 1) | 127 | if Fetch.try_mirror(d, repofilename): |
114 | # cvs_tarball_stash = None | 128 | bb.mkdirhier(repodir) |
115 | # if pn: | 129 | os.chdir(repodir) |
116 | # cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH_%s' % pn, d, 1) | 130 | rungitcmd("tar -xzf %s" % (repofile),d) |
117 | # if cvs_tarball_stash == None: | 131 | else: |
118 | # cvs_tarball_stash = data.getVar('CVS_TARBALL_STASH', d, 1) | 132 | rungitcmd("git clone %s://%s%s %s" % (proto, host, path, repodir),d) |
119 | # if cvs_tarball_stash: | ||
120 | # fetchcmd = data.getVar("FETCHCOMMAND_wget", d, 1) | ||
121 | # uri = cvs_tarball_stash + tarfn | ||
122 | # bb.note("fetch " + uri) | ||
123 | # fetchcmd = fetchcmd.replace("${URI}", uri) | ||
124 | # ret = os.system(fetchcmd) | ||
125 | # if ret == 0: | ||
126 | # bb.note("Fetched %s from tarball stash, skipping checkout" % tarfn) | ||
127 | # continue | ||
128 | |||
129 | #if os.path.exists(repodir): | ||
130 | #prunedir(repodir) | ||
131 | |||
132 | bb.mkdirhier(repodir) | ||
133 | os.chdir(repodir) | ||
134 | |||
135 | #print("Changing to %s" % repodir) | ||
136 | 133 | ||
137 | if os.access(repofile, os.R_OK): | ||
138 | rungitcmd("tar -xzf %s" % (repofile),d) | ||
139 | else: | ||
140 | rungitcmd("git clone rsync://%s%s %s" % (host, path, repodir),d) | ||
141 | |||
142 | rungitcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (host, path, os.path.join(repodir, ".git", "")),d) | ||
143 | |||
144 | #print("Changing to %s" % repodir) | ||
145 | os.chdir(repodir) | 134 | os.chdir(repodir) |
146 | rungitcmd("git pull rsync://%s%s" % (host, path),d) | 135 | rungitcmd("git pull %s://%s%s" % (proto, host, path),d) |
136 | rungitcmd("git pull --tags %s://%s%s" % (proto, host, path),d) | ||
137 | # old method of downloading tags | ||
138 | #rungitcmd("rsync -a --verbose --stats --progress rsync://%s%s/ %s" % (host, path, os.path.join(repodir, ".git", "")),d) | ||
147 | 139 | ||
148 | #print("Changing to %s" % repodir) | ||
149 | os.chdir(repodir) | 140 | os.chdir(repodir) |
141 | bb.note("Creating tarball of git repository") | ||
150 | rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d) | 142 | rungitcmd("tar -czf %s %s" % (repofile, os.path.join(".", ".git", "*") ),d) |
151 | 143 | ||
152 | if os.path.exists(codir): | 144 | if os.path.exists(codir): |
153 | prunedir(codir) | 145 | prunedir(codir) |
154 | 146 | ||
155 | #print("Changing to %s" % repodir) | ||
156 | bb.mkdirhier(codir) | 147 | bb.mkdirhier(codir) |
157 | os.chdir(repodir) | 148 | os.chdir(repodir) |
158 | rungitcmd("git read-tree %s" % (tag),d) | 149 | rungitcmd("git read-tree %s" % (tag),d) |
159 | |||
160 | rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d) | 150 | rungitcmd("git checkout-index -q -f --prefix=%s -a" % (os.path.join(codir, "git", "")),d) |
161 | 151 | ||
162 | #print("Changing to %s" % codir) | ||
163 | os.chdir(codir) | 152 | os.chdir(codir) |
153 | bb.note("Creating tarball of git checkout") | ||
164 | rungitcmd("tar -czf %s %s" % (cofile, os.path.join(".", "*") ),d) | 154 | rungitcmd("tar -czf %s %s" % (cofile, os.path.join(".", "*") ),d) |
165 | |||