overwrite=True causes unnecessary re-cloning of git repositories

Bug #1694277 reported by Colin Watson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
codetree
Confirmed
Medium
Unassigned

Bug Description

If codetree is asked to fetch a git branch with overwrite=True, then it always removes any existing repository. This makes some Mojo specs very slow to run on slow connections (e.g. doing even simple operations on lp:~ubuntuone-pqm-team/canonical-mojo-specs/mojo-ols-snap-store takes me half an hour), because they keep re-cloning fairly large charm repositories over and over again.

The relevant chunk of code looks like this:

            if options.get("overwrite"):
                shutil.rmtree(dest)
                if not log_failure(clone_command,
                                   "Cloning repository at {} from {}".format(dest, self.source)):
                    return result
            else:
                if not self.check_and_update(dest):
                    return result
                if ref is None: # default to master for the checkout of any updated repo
                    ref = 'master'

This is just one possibility for an improved structure and I haven't tested it, but I think that something like this would work better:

            try:
                updated = self.check_and_update(dest)
            except (NotABranch, NotSameBranch):
                if options.get("overwrite"):
                    updated = False
                else:
                    raise
            if updated:
                if ref is None: # default to master for the checkout of any updated repo
                    ref = 'master'
            elif options.get("overwrite"):
                shutil.rmtree(dest)
                if not log_failure(clone_command,
                                   "Cloning repository at {} from {}".format(dest, self.source)):
                    return result
            else:
                return result

Revision history for this message
Tom Haddon (mthaddon) wrote :

Seems like a reasonable change, would obviously need testing.

Changed in codetree:
status: New → Confirmed
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.