Only reset working copy when needed

We perform a repo reset before each operation we do on the merger or
executor. This currently consists of fetch, reset the references,
reset and clean the working copy. The reset and clean of the working
copy in this case just picks the first found reference to reset the
repo to. While this is the wrong reference almost all the time we even
don't need a clean working copy for operations like cat, fileschanges
or repostate. Thus everything that operates on the working copy
performs a checkout first.

Especially with large repos this can take quite some time and
increases the IO load on the merger/executor. Instead we can just skip
that and ensure that the reset and clean is done properly in checkout.

Change-Id: I605b3518de2237da60f0b326c6a647a4c7ce289c
This commit is contained in:
Tobias Henkel 2018-12-11 10:57:41 +01:00
parent 6497fa3662
commit bd6c60b369
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
1 changed files with 5 additions and 4 deletions

View File

@ -268,8 +268,6 @@ class Repo(object):
head = ref.remote_head
self.log.debug("Reset to %s", head)
repo.head.reference = head
reset_repo_to_head(repo)
repo.git.clean('-x', '-f', '-d')
for ref in stale_refs:
self.log.debug("Delete stale ref %s", ref.remote_head)
# A stale ref means the upstream branch (e.g. foobar) was deleted
@ -360,9 +358,12 @@ class Repo(object):
def checkout(self, ref):
repo = self.createRepoObject()
self.log.debug("Checking out %s" % ref)
# Perform a hard reset before checking out so that we clean up
# anything that might be left over from a merge.
# Perform a hard reset to the correct ref before checking out so that
# we clean up anything that might be left over from a merge while still
# only preparing the working copy once.
repo.head.reference = ref
reset_repo_to_head(repo)
repo.git.clean('-x', '-f', '-d')
repo.git.checkout(ref)
return repo.head.commit