Don't reset the local repo
Instead of "resetting" the local repo (git remote update, git checkout master, git reset --hard, git clean -xfdq) before merging each change, just fetch the remote ref for the branch and check that out (as a detached head). Or, if we are merging a change that depends on another change in the queue, just check that change out. Change-Id: I0a9b839a0c75c04eca7393d7bb58cf89448b6494
This commit is contained in:
parent
bfd5853957
commit
96ee718c4b
|
@ -60,29 +60,18 @@ class Repo(object):
|
||||||
self._ensure_cloned()
|
self._ensure_cloned()
|
||||||
self.repo = git.Repo(self.local_path)
|
self.repo = git.Repo(self.local_path)
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
self._ensure_cloned()
|
|
||||||
self.log.debug("Resetting repository %s" % self.local_path)
|
|
||||||
self.update()
|
|
||||||
origin = self.repo.remotes.origin
|
|
||||||
for ref in origin.refs:
|
|
||||||
if ref.remote_head == 'HEAD':
|
|
||||||
continue
|
|
||||||
self.repo.create_head(ref.remote_head, ref, force=True)
|
|
||||||
|
|
||||||
# Reset to remote HEAD (usually origin/master)
|
|
||||||
self.repo.head.reference = origin.refs['HEAD']
|
|
||||||
self.repo.head.reset(index=True, working_tree=True)
|
|
||||||
self.repo.git.clean('-x', '-f', '-d')
|
|
||||||
|
|
||||||
def getBranchHead(self, branch):
|
|
||||||
return self.repo.heads[branch]
|
|
||||||
|
|
||||||
def checkout(self, ref):
|
def checkout(self, ref):
|
||||||
self._ensure_cloned()
|
self._ensure_cloned()
|
||||||
self.log.debug("Checking out %s" % ref)
|
self.log.debug("Checking out %s" % ref)
|
||||||
self.repo.head.reference = ref
|
self.log.debug(repr(ref))
|
||||||
|
if self.repo.re_hexsha_only.match(ref):
|
||||||
|
self.repo.head.reference = ref
|
||||||
|
else:
|
||||||
|
self.fetch(ref)
|
||||||
|
self.repo.head.reference = \
|
||||||
|
self.repo.remotes.origin.refs[ref].commit.hexsha
|
||||||
self.repo.head.reset(index=True, working_tree=True)
|
self.repo.head.reset(index=True, working_tree=True)
|
||||||
|
self.repo.git.clean('-x', '-f', '-d')
|
||||||
|
|
||||||
def cherryPick(self, ref):
|
def cherryPick(self, ref):
|
||||||
self._ensure_cloned()
|
self._ensure_cloned()
|
||||||
|
@ -107,15 +96,15 @@ class Repo(object):
|
||||||
# data was fetched properly subsequent fetches don't seem to fail.
|
# data was fetched properly subsequent fetches don't seem to fail.
|
||||||
# So try again if an AssertionError is caught.
|
# So try again if an AssertionError is caught.
|
||||||
origin = self.repo.remotes.origin
|
origin = self.repo.remotes.origin
|
||||||
|
self.log.debug("Fetching %s" % ref)
|
||||||
try:
|
try:
|
||||||
origin.fetch(ref)
|
origin.fetch(ref)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
origin.fetch(ref)
|
origin.fetch(ref)
|
||||||
|
|
||||||
# If the repository is packed, and we fetch a change that is
|
# If the repository is packed, and we fetch a change that is
|
||||||
# also entirely packed, the cache may be out of date for the
|
# also entirely packed, the cache may be out of date.
|
||||||
# same reason as reset() above. Avoid these problems by
|
# See the comment in update() and
|
||||||
# recreating the repo object.
|
|
||||||
# https://bugs.launchpad.net/zuul/+bug/1078946
|
# https://bugs.launchpad.net/zuul/+bug/1078946
|
||||||
self.repo = git.Repo(self.local_path)
|
self.repo = git.Repo(self.local_path)
|
||||||
|
|
||||||
|
@ -250,14 +239,8 @@ class Merger(object):
|
||||||
# Only current change to merge against tip of change.branch
|
# Only current change to merge against tip of change.branch
|
||||||
if len(sibling_items) == 1:
|
if len(sibling_items) == 1:
|
||||||
repo = self.getRepo(item.change.project)
|
repo = self.getRepo(item.change.project)
|
||||||
# we need to reset here in order to call getBranchHead
|
|
||||||
try:
|
|
||||||
repo.reset()
|
|
||||||
except:
|
|
||||||
self.log.exception("Unable to reset repo %s" % repo)
|
|
||||||
return False
|
|
||||||
commit = self._mergeChange(item.change,
|
commit = self._mergeChange(item.change,
|
||||||
repo.getBranchHead(item.change.branch),
|
item.change.branch,
|
||||||
target_ref=target_ref)
|
target_ref=target_ref)
|
||||||
# Sibling changes exist. Merge current change against newest sibling.
|
# Sibling changes exist. Merge current change against newest sibling.
|
||||||
elif (len(sibling_items) >= 2 and
|
elif (len(sibling_items) >= 2 and
|
||||||
|
|
Loading…
Reference in New Issue