@@ -18,49 +18,50 @@
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import tempfile
import logging
import rhodecode.lib.helpers as h
from mercurial import archival
from pylons import request, response, session, tmpl_context as c, url
from pylons.i18n.translation import _
from pylons.controllers.util import redirect
from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
from rhodecode.lib.base import BaseController, render
from rhodecode.lib.utils import EmptyChangeset
from rhodecode.model.scm import ScmModel
from vcs.exceptions import RepositoryError, ChangesetError, ChangesetDoesNotExistError
from vcs.exceptions import RepositoryError, ChangesetError, \
ChangesetDoesNotExistError, EmptyRepositoryError
from vcs.nodes import FileNode
from vcs.utils import diffs as differ
log = logging.getLogger(__name__)
class FilesController(BaseController):
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
'repository.admin')
def __before__(self):
super(FilesController, self).__before__()
c.cut_off_limit = self.cut_off_limit
def index(self, repo_name, revision, f_path):
hg_model = ScmModel()
c.repo = hg_model.get_repo(c.repo_name)
try:
#reditect to given revision from form
post_revision = request.POST.get('at_rev', None)
if post_revision:
post_revision = c.repo.get_changeset(post_revision).raw_id
redirect(url('files_home', repo_name=c.repo_name,
@@ -80,48 +81,52 @@ class FilesController(BaseController):
revision=prev_rev, f_path=f_path)
if c.branch:
c.url_prev += '?branch=%s' % c.branch
except ChangesetDoesNotExistError:
c.url_prev = '#'
#next link
next_rev = c.repo.get_changeset(cur_rev).next(c.branch).raw_id
c.url_next = url('files_home', repo_name=c.repo_name,
revision=next_rev, f_path=f_path)
c.url_next += '?branch=%s' % c.branch
c.url_next = '#'
#files
c.files_list = c.changeset.get_node(f_path)
c.file_history = self._get_history(c.repo, c.files_list, f_path)
except RepositoryError, e:
h.flash(str(e), category='warning')
redirect(h.url('files_home', repo_name=repo_name, revision=revision))
except EmptyRepositoryError, e:
h.flash(_('There are no files yet'), category='warning')
redirect(h.url('summary_home', repo_name=repo_name))
redirect(h.url('files_home', repo_name=repo_name, revision='tip'))
return render('files/files.html')
def rawfile(self, repo_name, revision, f_path):
file_node = c.repo.get_changeset(revision).get_node(f_path)
response.content_type = file_node.mimetype
response.content_disposition = 'attachment; filename=%s' \
% f_path.split('/')[-1]
return file_node.content
def raw(self, repo_name, revision, f_path):
response.content_type = 'text/plain'
Status change: