Skip to contentSkip to conversation

kernel-yocto: Simplify no git repo case in do_kernel_checkout

PATCH In review Paul Barker 2 participants 2 messages Aug 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel-yocto: Simplify no git repo case in do_kernel_checkout

If the kernel sources are not fetched via git, a local git repository is created in do_kernel_checkout. In this case we know that there will be no remote branches and we will already be on the correct branch (since only one branch will exist). So we can simplify things by skipping these steps.

This also removes the assumption that the default git branch name will be "master". Prior to this change, the final git checkout command in do_kernel_checkout could fail if a local git repo was created and the user had changed init.defaultBranch in their gitconfig.

---
 meta/classes/kernel-yocto.bbclass | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
meta/classes/kernel-yocto.bbclass +15 -15
index 0df61cdef0..18b77e2b9f 100644
@@ -358,6 +358,21 @@ do_kernel_checkout() {
 			fi
 		fi
 		cd ${S}
+
+		# convert any remote branches to local tracking ones
+		for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
+			b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
+			git show-ref --quiet --verify -- "refs/heads/$b"
+			if [ $? -ne 0 ]; then
+				git branch $b $i > /dev/null
+			fi
+		done
+
+		# Create a working tree copy of the kernel by checking out a branch
+		machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
+
+		# checkout and clobber any unimportant files
+		git checkout -f ${machine_branch}
 	else
 		# case: we have no git repository at all. 
 		# To support low bandwidth options for building the kernel, we'll just 
@@ -379,21 +394,6 @@ do_kernel_checkout() {
 		git commit -q -m "baseline commit: creating repo for ${PN}-${PV}"
 		git clean -d -f
 	fi
-
-	# convert any remote branches to local tracking ones
-	for i in `git branch -a --no-color | grep remotes | grep -v HEAD`; do
-		b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
-		git show-ref --quiet --verify -- "refs/heads/$b"
-		if [ $? -ne 0 ]; then
-			git branch $b $i > /dev/null
-		fi
-	done
-
-	# Create a working tree copy of the kernel by checking out a branch
-	machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
-
-	# checkout and clobber any unimportant files
-	git checkout -f ${machine_branch}
 }
 do_kernel_checkout[dirs] = "${S} ${WORKDIR}"
 
Signature · 1 line
2.31.1
#1 lore raw
Quoted 11 lines · Paul Barker

If the kernel sources are not fetched via git, a local git repository is created in do_kernel_checkout. In this case we know that there will be no remote branches and we will already be on the correct branch (since only one branch will exist). So we can simplify things by skipping these steps.

This also removes the assumption that the default git branch name will be "master". Prior to this change, the final git checkout command in do_kernel_checkout could fail if a local git repo was created and the user had changed init.defaultBranch in their gitconfig.

Looks ok to me. No concerns jumped out.

Richard: I can take this into my queue, or you can grab it directly, either works for me.

Bruce

Quoted 65 lines
---
 meta/classes/kernel-yocto.bbclass | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
meta/classes/kernel-yocto.bbclass +11 -1
index 0df61cdef0..18b77e2b9f 100644
@@ -358,6 +358,21 @@ do_kernel_checkout() {
                        fi
                fi
                cd ${S}
+
+               # convert any remote branches to local tracking ones
+               for i in `git branch -a --no-color | grep remotes | grep
-v HEAD`; do
+                       b=`echo $i | cut -d' ' -f2 | sed
 's%remotes/origin/%%'`;
+                       git show-ref --quiet --verify -- "refs/heads/$b"
+                       if [ $? -ne 0 ]; then
+                               git branch $b $i > /dev/null
+                       fi
+               done
+
+               # Create a working tree copy of the kernel by checking out

a branch

meta/classes/kernel-yocto.bbclass +4 -0
+               machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
+
+               # checkout and clobber any unimportant files
+               git checkout -f ${machine_branch}
        else
                # case: we have no git repository at all.
                # To support low bandwidth options for building the

kernel, we'll just

meta/classes/kernel-yocto.bbclass +0 -0
@@ -379,21 +394,6 @@ do_kernel_checkout() {
                git commit -q -m "baseline commit: creating repo for

${PN}-${PV}"
git clean -d -f
fi

meta/classes/kernel-yocto.bbclass +0 -3
-
-       # convert any remote branches to local tracking ones
-       for i in `git branch -a --no-color | grep remotes | grep -v HEAD`;

do

meta/classes/kernel-yocto.bbclass +0 -13
-               b=`echo $i | cut -d' ' -f2 | sed 's%remotes/origin/%%'`;
-               git show-ref --quiet --verify -- "refs/heads/$b"
-               if [ $? -ne 0 ]; then
-                       git branch $b $i > /dev/null
-               fi
-       done
-
-       # Create a working tree copy of the kernel by checking out a branch
-       machine_branch="${@ get_machine_branch(d, "${KBRANCH}" )}"
-
-       # checkout and clobber any unimportant files
-       git checkout -f ${machine_branch}
 }
 do_kernel_checkout[dirs] = "${S} ${WORKDIR}"
 
--

2.31.1

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await thee
at its end
- "Use the force Harry" - Gandalf, Star Trek II