Message ID | 20230831143032.1463093-1-JPEWhacker@gmail.com |
---|---|
State | New |
Headers | show |
Series | [bitbake-devel] fetch2: git: Remove useless try..else clause | expand |
On 31/08/2023 16:30, Joshua Watt wrote: > There is no reason to have the else clause in this try block, as it can > be moved into the try block, which is clearer. > > Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> > --- > bitbake/lib/bb/fetch2/git.py | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py > index 33895e09b29..e11271b757a 100644 > --- a/bitbake/lib/bb/fetch2/git.py > +++ b/bitbake/lib/bb/fetch2/git.py > @@ -373,10 +373,7 @@ class Git(FetchMethod): > try: > # Since clones can be bare, use --absolute-git-dir instead of --show-toplevel > output = runfetchcmd("LANG=C %s rev-parse --absolute-git-dir" % ud.basecmd, d, workdir=ud.clonedir) > - except bb.fetch2.FetchError as e: > - logger.warning("Unable to get top level for %s (not a git directory?): %s", ud.clonedir, e) > - needs_clone = True > - else: > + > toplevel = os.path.abspath(output.rstrip()) > abs_clonedir = os.path.abspath(ud.clonedir).rstrip('/') > # The top level Git directory must either be the clone directory > @@ -387,6 +384,9 @@ class Git(FetchMethod): > if os.path.commonprefix([abs_clonedir, toplevel]) != abs_clonedir: > logger.warning("Top level directory '%s' doesn't match expected '%s'. Re-cloning", toplevel, ud.clonedir) > needs_clone = True > + except bb.fetch2.FetchError as e: > + logger.warning("Unable to get top level for %s (not a git directory?): %s", ud.clonedir, e) > + needs_clone = True > > if needs_clone: > shutil.rmtree(ud.clonedir) > -- > 2.34.1 > Looks good to me and thank you for submitting a correction :)
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index 33895e09b29..e11271b757a 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py @@ -373,10 +373,7 @@ class Git(FetchMethod): try: # Since clones can be bare, use --absolute-git-dir instead of --show-toplevel output = runfetchcmd("LANG=C %s rev-parse --absolute-git-dir" % ud.basecmd, d, workdir=ud.clonedir) - except bb.fetch2.FetchError as e: - logger.warning("Unable to get top level for %s (not a git directory?): %s", ud.clonedir, e) - needs_clone = True - else: + toplevel = os.path.abspath(output.rstrip()) abs_clonedir = os.path.abspath(ud.clonedir).rstrip('/') # The top level Git directory must either be the clone directory @@ -387,6 +384,9 @@ class Git(FetchMethod): if os.path.commonprefix([abs_clonedir, toplevel]) != abs_clonedir: logger.warning("Top level directory '%s' doesn't match expected '%s'. Re-cloning", toplevel, ud.clonedir) needs_clone = True + except bb.fetch2.FetchError as e: + logger.warning("Unable to get top level for %s (not a git directory?): %s", ud.clonedir, e) + needs_clone = True if needs_clone: shutil.rmtree(ud.clonedir)
There is no reason to have the else clause in this try block, as it can be moved into the try block, which is clearer. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> --- bitbake/lib/bb/fetch2/git.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)