fetch2: Remove unecessary code for git submodules
PATCH 1/1 fetch2: Remove unecessary code for git submodules
From: "Felipe F. Tonello" <[email protected]>
Only do git submodule update after upack, otherwise the branch and commit id will be ignored, causing to run git submodules on a wrong ref.
Since .gitmodules file is used to check if there is any submodule, we don't need to worry about copying .git/modules directory into the unpacked source tree.
--- lib/bb/fetch2/gitsm.py | 73 -------------------------------------------------- 1 file changed, 73 deletions(-)
lib/bb/fetch2/gitsm.py +0 -73
@@ -31,10 +31,8 @@ NOTE: Switching a SRC_URI from "git://" to "gitsm://" requires a clean of your r import os import bb -from bb import data from bb.fetch2.git import Git from bb.fetch2 import runfetchcmd -from bb.fetch2 import logger class GitSM(Git): def supports(self, ud, d):
@@ -52,85 +50,14 @@ class GitSM(Git): pass return False - def _set_relative_paths(self, repopath): - """ - Fix submodule paths to be relative instead of absolute, - so that when we move the repo it doesn't break - (In Git 1.7.10+ this is done automatically) - """ - submodules = [] - with open(os.path.join(repopath, '.gitmodules'), 'r') as f: - for line in f.readlines(): - if line.startswith('[submodule'): - submodules.append(line.split('"')[1]) - - for module in submodules: - repo_conf = os.path.join(repopath, module, '.git') - if os.path.exists(repo_conf): - with open(repo_conf, 'r') as f: - lines = f.readlines() - newpath = '' - for i, line in enumerate(lines): - if line.startswith('gitdir:'): - oldpath = line.split(': ')[-1].rstrip() - if oldpath.startswith('/'): - newpath = '../' * (module.count('/') + 1) + '.git/modules/' + module - lines[i] = 'gitdir: %s\n' % newpath - break - if newpath: - with open(repo_conf, 'w') as f: - for line in lines: - f.write(line) - - repo_conf2 = os.path.join(repopath, '.git', 'modules', module, 'config') - if os.path.exists(repo_conf2): - with open(repo_conf2, 'r') as f: - lines = f.readlines() - newpath = '' - for i, line in enumerate(lines): - if line.lstrip().startswith('worktree = '): - oldpath = line.split(' = ')[-1].rstrip() - if oldpath.startswith('/'): - newpath = '../' * (module.count('/') + 3) + module - lines[i] = '\tworktree = %s\n' % newpath - break - if newpath: - with open(repo_conf2, 'w') as f: - for line in lines: - f.write(line) - - def update_submodules(self, ud, d): - # We have to convert bare -> full repo, do the submodule bit, then convert back - tmpclonedir = ud.clonedir + ".tmp" - gitdir = tmpclonedir + os.sep + ".git" - bb.utils.remove(tmpclonedir, True) - os.mkdir(tmpclonedir) - os.rename(ud.clonedir, gitdir) - runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*true/bare = false/'", d) - os.chdir(tmpclonedir) - runfetchcmd(ud.basecmd + " reset --hard", d) - runfetchcmd(ud.basecmd + " submodule init", d) - runfetchcmd(ud.basecmd + " submodule update", d) - self._set_relative_paths(tmpclonedir) - runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*false/bare = true/'", d) - os.rename(gitdir, ud.clonedir,) - bb.utils.remove(tmpclonedir, True) - def download(self, ud, d): Git.download(self, ud, d) - os.chdir(ud.clonedir) - submodules = self.uses_submodules(ud, d) - if submodules: - self.update_submodules(ud, d) - def unpack(self, ud, destdir, d): Git.unpack(self, ud, destdir, d) - os.chdir(ud.destdir) submodules = self.uses_submodules(ud, d) if submodules: - runfetchcmd("cp -r " + ud.clonedir + "/modules " + ud.destdir + "/.git/", d) runfetchcmd(ud.basecmd + " submodule init", d) runfetchcmd(ud.basecmd + " submodule update", d)
Signature · 1 line
2.1.0
Hi Felipe,
Quoted 115 lines · On Monday 06 July 2015 16:13:58 [email protected] wrote:
From: "Felipe F. Tonello" <[email protected]>
Only do git submodule update after upack, otherwise the branch and commit id will be ignored, causing to run git submodules on a wrong ref.
Since .gitmodules file is used to check if there is any submodule, we don't need to worry about copying .git/modules directory into the unpacked source tree.
Signed-off-by Felipe F. Tonello <[email protected]>--- lib/bb/fetch2/gitsm.py | 73-------------------------------------------------- 1 file changed, 73 deletions(-)
lib/bb/fetch2/gitsm.py +0
-0@@ -31,10 +31,8 @@ NOTE: Switching a SRC_URI from "git://" to "gitsm://"requires a clean of your r
import os
import bblib/bb/fetch2/gitsm.py +0
-25-from bb import data from bb.fetch2.git import Git from bb.fetch2 import runfetchcmd -from bb.fetch2 import logger class GitSM(Git): def supports(self, ud, d):@@ -52,85 +50,14 @@ class GitSM(Git): pass return False - def _set_relative_paths(self, repopath): - """ - Fix submodule paths to be relative instead of absolute, - so that when we move the repo it doesn't break - (In Git 1.7.10+ this is done automatically) - """ - submodules = [] - with open(os.path.join(repopath, '.gitmodules'), 'r') as f: - for line in f.readlines(): - if line.startswith('[submodule'): - submodules.append(line.split('"')[1]) - - for module in submodules: - repo_conf = os.path.join(repopath, module, '.git') - if os.path.exists(repo_conf): - with open(repo_conf, 'r') as f: - lines = f.readlines() - newpath = '' - for i, line in enumerate(lines): - if line.startswith('gitdir:'): - oldpath = line.split(': ')[-1].rstrip() - if oldpath.startswith('/'): - newpath = '../' * (module.count('/') + 1) +'.git/modules/' + module - lines[i] = 'gitdir:
%s\n' % newpathlib/bb/fetch2/gitsm.py +0
-7- break - if newpath: - with open(repo_conf, 'w') as f: - for line in lines: - f.write(line) - - repo_conf2 = os.path.join(repopath, '.git', 'modules', module,'config') - if
os.path.exists(repo_conf2):lib/bb/fetch2/gitsm.py +0
-8- with open(repo_conf2, 'r') as f: - lines = f.readlines() - newpath = '' - for i, line in enumerate(lines): - if line.lstrip().startswith('worktree = '): - oldpath = line.split(' = ')[-1].rstrip() - if oldpath.startswith('/'): - newpath = '../' * (module.count('/') + 3) +module - lines[i] = '\tworktree = %s\n' %
newpath - breaklib/bb/fetch2/gitsm.py +0
-7- if newpath: - with open(repo_conf2, 'w') as f: - for line in lines: - f.write(line) - - def update_submodules(self, ud, d): - # We have to convert bare -> full repo, do the submodule bit, thenconvert back - tmpclonedir = ud.clonedir + ".tmp"
lib/bb/fetch2/gitsm.py +0
-5- gitdir = tmpclonedir + os.sep + ".git" - bb.utils.remove(tmpclonedir, True) - os.mkdir(tmpclonedir) - os.rename(ud.clonedir, gitdir) - runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*true/bare= false/'", d) -
os.chdir(tmpclonedir)lib/bb/fetch2/gitsm.py +0
-5- runfetchcmd(ud.basecmd + " reset --hard", d) - runfetchcmd(ud.basecmd + " submodule init", d) - runfetchcmd(ud.basecmd + " submodule update", d) - self._set_relative_paths(tmpclonedir) - runfetchcmd("sed " + gitdir + "/config -i -e 's/bare.*=.*false/bare= true/'", d) -
os.rename(gitdir, ud.clonedir,)lib/bb/fetch2/gitsm.py +0
-9- bb.utils.remove(tmpclonedir, True) - def download(self, ud, d): Git.download(self, ud, d) - os.chdir(ud.clonedir) - submodules = self.uses_submodules(ud, d) - if submodules: - self.update_submodules(ud, d) - def unpack(self, ud, destdir, d): Git.unpack(self, ud, destdir, d) - os.chdir(ud.destdir) submodules = self.uses_submodules(ud, d) if submodules: - runfetchcmd("cp -r " + ud.clonedir + "/modules " + ud.destdir +
Quoted 2 lines
"/.git/", d)
runfetchcmd(ud.basecmd + " submodule init", d)
runfetchcmd(ud.basecmd + " submodule update", d)
So, I might have been the one that implemented the _set_relative_paths() part of this - I don't remember the full details, however the comment suggests that this is necessary for older versions of git. If we wish to remain compatible with those then we still need this code surely?
Here's the commit that added it:
http://cgit.openembedded.org/bitbake/commit/?id=e700d5a41deed4ee837465af526ed30c8a579933
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
Quoted 6 lines · On Mon, Jul 6, 2015 at 8:13 AM, <[email protected]> wrote:
From: "Felipe F. Tonello" <[email protected]>
Only do git submodule update after upack, otherwise the branch and commit id
will be ignored, causing to run git submodules on a wrong ref.
Quoted 6 lines
Since .gitmodules file is used to check if there is any submodule, we don't need to worry about copying .git/modules directory into the unpacked source tree.
Signed-off-by Felipe F. Tonello <[email protected]>
We don’t want to be downloading from remote locations in do_unpack, only do_fetch. This patch will result in the opposite, which means the submodule sources won’t be included in the git mirror tarball, and it’ll be impossible to build with BB_NO_NETWORK=1. Also -c fetchall won’t result in all sources having been fetched, which defeats its purpose.
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
Hi Christopher,
Quoted 14 lines · Christopher Larson
Quoted 13 lines · On Mon, Jul 6, 2015 at 8:13 AM, <[email protected]> wrote:
From: "Felipe F. Tonello" <[email protected]>
Only do git submodule update after upack, otherwise the branch and commit id
will be ignored, causing to run git submodules on a wrong ref.Since .gitmodules file is used to check if there is any submodule, we don't
need to worry about copying .git/modules directory into the unpacked source
tree.
Quoted 8 lines
Quoted 1 line
Signed-off-by Felipe F. Tonello <[email protected]>We don’t want to be downloading from remote locations in
do_unpack, onlydo_fetch. This patch will result in the opposite, which means the submodule sources won’t be included in the git mirror tarball, and it’ll be impossible to build with BB_NO_NETWORK=1. Also -c fetchall won’t result in all sources having been fetched, which defeats its purpose.
I understand. So Ideally we want to checkout to the right ref before doing the git submodule init && update? Because the way it is today it doesn't work if the .gitmodules is in a different branch rather then the default.
The git submodule init && update was previously in the unpack() anyway. Should I remove it?
Felipe
Quoted 29 lines · Felipe Tonello
Quoted 5 lines · Christopher Larson
Quoted 4 lines · On Mon, Jul 6, 2015 at 8:13 AM, <[email protected]> wrote:
From: "Felipe F. Tonello" <[email protected]>
Only do git submodule update after upack, otherwise the branch and
commit
Quoted 9 lines
Quoted 9 lines
id
will be ignored, causing to run git submodules on a wrong ref.Since .gitmodules file is used to check if there is any submodule, we don't
need to worry about copying .git/modules directory into the unpacked source
tree.Quoted 5 lines
Quoted 1 line
Signed-off-by Felipe F. Tonello <[email protected]>We don’t want to be downloading from remote locations in
do_unpack, onlydo_fetch. This patch will result in the opposite, which means thesubmodule
Quoted 1 line
sources won’t be included in the git mirror tarball, and it’ll be
impossible
Quoted 1 line
to build with BB_NO_NETWORK=1. Also -c fetchall won’t result in all
sources
Quoted 1 line
having been fetched, which defeats its purpose.
Quoted 7 lines
I understand. So Ideally we want to checkout to the right ref before doing the git submodule init && update? Because the way it is today it doesn't work if the .gitmodules is in a different branch rather then the default.
The git submodule init && update was previously in the
unpack()anyway. Should I remove it?
The init will set up .git/config, and the update will check out the modules into their appropriate locations in the source tree, so afaik they’re still needed to do that, even though they’re already fetched in .git/modules.
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics