Merge "Refactor: move getRepo out of the App object"

This commit is contained in:
Jenkins 2015-06-29 18:56:23 +00:00 committed by Gerrit Code Review
commit 877119d32f
5 changed files with 16 additions and 15 deletions

View File

@ -522,13 +522,6 @@ class App(object):
view = view_change_list.ChangeListView(self, d['query'], d['name'])
self.changeScreen(view)
def getRepo(self, project_name):
local_path = os.path.join(self.config.git_root, project_name)
local_root = os.path.abspath(self.config.git_root)
assert os.path.commonprefix((local_root, local_path)) == local_root
return gitrepo.Repo(self.config.url+'p/'+project_name,
local_path)
def openURL(self, url):
self.log.debug("Open URL %s" % url)
webbrowser.open_new_tab(url)
@ -578,7 +571,7 @@ class App(object):
return ret
def localCheckoutCommit(self, project_name, commit_sha):
repo = self.getRepo(project_name)
repo = gitrepo.get_repo(project_name, self.config)
try:
repo.checkout(commit_sha)
dialog = mywid.MessageDialog('Checkout', 'Change checked out in %s' % repo.path)
@ -591,7 +584,7 @@ class App(object):
self.popup(dialog, min_height=min_height)
def localCherryPickCommit(self, project_name, commit_sha):
repo = self.getRepo(project_name)
repo = gitrepo.get_repo(project_name, self.config)
try:
repo.cherryPick(commit_sha)
dialog = mywid.MessageDialog('Cherry-Pick', 'Change cherry-picked in %s' % repo.path)

View File

@ -507,3 +507,9 @@ class Repo(object):
f.addContextLine(line)
f.finalize()
return f
def get_repo(project_name, config):
local_path = os.path.join(config.git_root, project_name)
local_root = os.path.abspath(config.git_root)
assert os.path.commonprefix((local_root, local_path)) == local_root
return Repo(config.url+'p/'+project_name, local_path)

View File

@ -567,7 +567,7 @@ class SyncChangeTask(Task):
change.subject = remote_change['subject']
change.updated = dateutil.parser.parse(remote_change['updated'])
change.topic = remote_change.get('topic')
repo = app.getRepo(change.project.name)
repo = gertty.gitrepo.get_repo(change.project.name, app.config)
new_revision = False
for remote_commit, remote_revision in remote_change.get('revisions', {}).items():
revision = session.getRevisionByCommit(remote_commit)
@ -847,7 +847,7 @@ class CheckReposTask(Task):
try:
missing = False
try:
app.getRepo(project.name)
repo = gertty.gitrepo.get_repo(project.name, app.config)
except gitrepo.GitCloneError:
missing = True
if missing or app.fetch_missing_refs:
@ -878,7 +878,7 @@ class CheckRevisionsTask(Task):
project = session.getProject(self.project_key)
repo = None
try:
repo = app.getRepo(project.name)
repo = gitrepo.get_repo(project.name, app.config)
except gitrepo.GitCloneError:
pass
for change in project.open_changes:

View File

@ -19,6 +19,7 @@ import urlparse
import urwid
from gertty import gitrepo
from gertty import keymap
from gertty import mywid
from gertty import sync
@ -504,7 +505,7 @@ class ChangeView(urwid.WidgetWrap):
change = session.getChange(self.change_key)
change_number = change.number
change_id = change.id
repo = self.app.getRepo(change.project.name)
repo = gitrepo.get_repo(change.project.name, self.app.config)
for revision in change.revisions:
if not repo.hasCommit(revision.parent):
missing_revisions.add(revision.parent)
@ -626,7 +627,7 @@ class ChangeView(urwid.WidgetWrap):
self.refreshDependencies(session, change)
repo = self.app.getRepo(change.project.name)
repo = gitrepo.get_repo(change.project.name, self.app.config)
# The listbox has both revisions and messages in it (and
# may later contain the vote table and change header), so
# keep track of the index separate from the loop.

View File

@ -17,6 +17,7 @@ import logging
import urwid
from gertty import gitrepo
from gertty import keymap
from gertty import mywid
from gertty import gitrepo
@ -252,7 +253,7 @@ class BaseDiffView(urwid.WidgetWrap):
comment_list.append((comment.key, message))
comment_lists[key] = comment_list
comment_filenames.add(path)
repo = self.app.getRepo(self.project_name)
repo = gitrepo.get_repo(self.project_name, self.app.config)
self._w.contents.append((self.app.header, ('pack', 1)))
self.file_reminder = self.makeFileReminder()
self._w.contents.append((self.file_reminder, ('pack', 1)))