Mercurial > kallithea
annotate kallithea/controllers/files.py @ 4212:24c0d584ba86 kallithea-2.2.5-rebrand
General renaming to Kallithea
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:06:01 -0400 |
parents | 1948ede028ef |
children | 432e86d1e555 |
rev | line source |
---|---|
812
30ad41c76fae
fixes #79 cut off limit was added into .ini config files
Marcin Kuzminski <marcin@python-works.com>
parents:
774
diff
changeset
|
1 # -*- coding: utf-8 -*- |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
5 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1200
diff
changeset
|
6 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
10 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1200
diff
changeset
|
11 # |
252
3782a6d698af
licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
245
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
14 """ |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
15 kallithea.controllers.files |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
17 |
4212
24c0d584ba86
General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4211
diff
changeset
|
18 Files controller for Kallithea |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
19 |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
20 This file was forked by the Kallithea project in July 2014. |
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
21 Original author and date, and relevant copyright and licensing information is below: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
22 :created_on: Apr 21, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
23 :author: marcink |
4211
1948ede028ef
RhodeCode GmbH is not the sole author of this work
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4208
diff
changeset
|
24 :copyright: (c) 2013 RhodeCode GmbH, and others. |
4208
ad38f9f93b3b
Correct licensing information in individual files.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4197
diff
changeset
|
25 :license: GPLv3, see LICENSE.md for more details. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
26 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
27 |
2291
982d8a80e048
archive file fixes for python 2.5
Marcin Kuzminski <marcin@python-works.com>
parents:
2277
diff
changeset
|
28 from __future__ import with_statement |
1200
3ecaa17d9dea
added os.sep for files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1190
diff
changeset
|
29 import os |
812
30ad41c76fae
fixes #79 cut off limit was added into .ini config files
Marcin Kuzminski <marcin@python-works.com>
parents:
774
diff
changeset
|
30 import logging |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
31 import traceback |
2267
b872bc10f4ec
cleanup code of get archive for repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
32 import tempfile |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
33 import shutil |
812
30ad41c76fae
fixes #79 cut off limit was added into .ini config files
Marcin Kuzminski <marcin@python-works.com>
parents:
774
diff
changeset
|
34 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
35 from pylons import request, response, tmpl_context as c, url |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
512
diff
changeset
|
36 from pylons.i18n.translation import _ |
318
fdf9f6ee5217
Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
275
diff
changeset
|
37 from pylons.controllers.util import redirect |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
38 from kallithea.lib.utils import jsonify, action_logger |
812
30ad41c76fae
fixes #79 cut off limit was added into .ini config files
Marcin Kuzminski <marcin@python-works.com>
parents:
774
diff
changeset
|
39 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
40 from kallithea.lib import diffs |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
41 from kallithea.lib import helpers as h |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
1752
diff
changeset
|
42 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
43 from kallithea.lib.compat import OrderedDict |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
44 from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_str,\ |
2931
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
45 str2bool |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
46 from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
47 from kallithea.lib.base import BaseRepoController, render |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
48 from kallithea.lib.vcs.backends.base import EmptyChangeset |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
49 from kallithea.lib.vcs.conf import settings |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
50 from kallithea.lib.vcs.exceptions import RepositoryError, \ |
2109 | 51 ChangesetDoesNotExistError, EmptyRepositoryError, \ |
2977
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
52 ImproperArchiveTypeError, VCSError, NodeAlreadyExistsError,\ |
3037
789f20683559
fix error when diff path is a directory, edge case generated by google bots
Marcin Kuzminski <marcin@python-works.com>
parents:
3009
diff
changeset
|
53 NodeDoesNotExistError, ChangesetError, NodeError |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
54 from kallithea.lib.vcs.nodes import FileNode |
2109 | 55 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
56 from kallithea.model.repo import RepoModel |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
57 from kallithea.model.scm import ScmModel |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
58 from kallithea.model.db import Repository |
2109 | 59 |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
60 from kallithea.controllers.changeset import anchor_url, _ignorews_url,\ |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
61 _context_url, get_line_ctx, get_ignore_ws |
3621
fe012b7df29d
missing files or bad files revisions should return 404s not redirects - ref #808
Marcin Kuzminski <marcin@python-works.com>
parents:
3591
diff
changeset
|
62 from webob.exc import HTTPNotFound |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
63 from kallithea.lib.exceptions import NonRelativePathError, IMCCommitError |
2109 | 64 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
65 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 log = logging.getLogger(__name__) |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 |
1134
1dc5d169e85a
fixed issue with vcs stream
Marcin Kuzminski <marcin@python-works.com>
parents:
1132
diff
changeset
|
68 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
69 class FilesController(BaseRepoController): |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
70 |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
71 def __before__(self): |
191
b68b2246e5a6
Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents:
160
diff
changeset
|
72 super(FilesController, self).__before__() |
813
e8b5be26fb78
fixed small issue made on latest patches
Marcin Kuzminski <marcin@python-works.com>
parents:
812
diff
changeset
|
73 c.cut_off_limit = self.cut_off_limit |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
75 def __get_cs_or_redirect(self, rev, repo_name, redirect_after=True): |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
76 """ |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
77 Safe way to get changeset if error occur it redirects to tip with |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
78 proper message |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1200
diff
changeset
|
79 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
80 :param rev: revision to fetch |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
81 :param repo_name: repo name to redirect after |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
82 """ |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
83 |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
84 try: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
85 return c.db_repo_scm_instance.get_changeset(rev) |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
86 except EmptyRepositoryError, e: |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
87 if not redirect_after: |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
88 return None |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
89 url_ = url('files_add_home', |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
90 repo_name=c.repo_name, |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
91 revision=0, f_path='', anchor='edit') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
92 add_new = h.link_to(_('Click here to add new file'), url_, class_="alert-link") |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
93 h.flash(h.literal(_('There are no files yet. %s') % add_new), |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
94 category='warning') |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
95 redirect(h.url('summary_home', repo_name=repo_name)) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
96 except(ChangesetDoesNotExistError, LookupError), e: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
97 log.error(traceback.format_exc()) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
98 msg = _('Such revision does not exist for this repository') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
99 h.flash(msg, category='error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
100 raise HTTPNotFound() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
101 except RepositoryError, e: |
4077
0e1023147334
Use safe_str on flash messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
4072
diff
changeset
|
102 h.flash(safe_str(e), category='error') |
3621
fe012b7df29d
missing files or bad files revisions should return 404s not redirects - ref #808
Marcin Kuzminski <marcin@python-works.com>
parents:
3591
diff
changeset
|
103 raise HTTPNotFound() |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
104 |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
105 def __get_filenode_or_redirect(self, repo_name, cs, path): |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
106 """ |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
107 Returns file_node, if error occurs or given path is directory, |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
108 it'll redirect to top level path |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1200
diff
changeset
|
109 |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
110 :param repo_name: repo_name |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
111 :param cs: given changeset |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
112 :param path: path to lookup |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
113 """ |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
114 |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
115 try: |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
116 file_node = cs.get_node(path) |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
117 if file_node.is_dir(): |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
118 raise RepositoryError('given path is a directory') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
119 except(ChangesetDoesNotExistError,), e: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
120 log.error(traceback.format_exc()) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
121 msg = _('Such revision does not exist for this repository') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
122 h.flash(msg, category='error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
123 raise HTTPNotFound() |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
124 except RepositoryError, e: |
4077
0e1023147334
Use safe_str on flash messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
4072
diff
changeset
|
125 h.flash(safe_str(e), category='error') |
3621
fe012b7df29d
missing files or bad files revisions should return 404s not redirects - ref #808
Marcin Kuzminski <marcin@python-works.com>
parents:
3591
diff
changeset
|
126 raise HTTPNotFound() |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
127 |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
128 return file_node |
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
129 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
130 @LoginRequired() |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
131 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
132 'repository.admin') |
2177
ee07357d9265
unified annotation view with file source view
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
133 def index(self, repo_name, revision, f_path, annotate=False): |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
134 # redirect to given revision from form if given |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
135 post_revision = request.POST.get('at_rev', None) |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
136 if post_revision: |
1224
e76833cd555a
files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents:
1212
diff
changeset
|
137 cs = self.__get_cs_or_redirect(post_revision, repo_name) |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
138 |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
139 c.changeset = self.__get_cs_or_redirect(revision, repo_name) |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
140 c.branch = request.GET.get('branch', None) |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
141 c.f_path = f_path |
2177
ee07357d9265
unified annotation view with file source view
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
142 c.annotate = annotate |
3237
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
143 c.changeset = self.__get_cs_or_redirect(revision, repo_name) |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
144 cur_rev = c.changeset.revision |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
145 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
146 # prev link |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
147 try: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
148 prev_rev = c.db_repo_scm_instance.get_changeset(cur_rev).prev(c.branch) |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
149 c.url_prev = url('files_home', repo_name=c.repo_name, |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
150 revision=prev_rev.raw_id, f_path=f_path) |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
151 if c.branch: |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
152 c.url_prev += '?branch=%s' % c.branch |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
153 except (ChangesetDoesNotExistError, VCSError): |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
154 c.url_prev = '#' |
883
20ed6f6a6329
Changed prev/next in file browser to new vcs methods
Marcin Kuzminski <marcin@python-works.com>
parents:
872
diff
changeset
|
155 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
156 # next link |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
157 try: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
158 next_rev = c.db_repo_scm_instance.get_changeset(cur_rev).next(c.branch) |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
159 c.url_next = url('files_home', repo_name=c.repo_name, |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
160 revision=next_rev.raw_id, f_path=f_path) |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
161 if c.branch: |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
162 c.url_next += '?branch=%s' % c.branch |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
163 except (ChangesetDoesNotExistError, VCSError): |
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
164 c.url_next = '#' |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
165 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
166 # files or dirs |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
167 try: |
1737
61eda8bf70d0
new files views
Marcin Kuzminski <marcin@python-works.com>
parents:
1664
diff
changeset
|
168 c.file = c.changeset.get_node(f_path) |
1190
0d7a127e6449
use cs get history instead of node.history, node history have to much reference calls
Marcin Kuzminski <marcin@python-works.com>
parents:
1189
diff
changeset
|
169 |
1737
61eda8bf70d0
new files views
Marcin Kuzminski <marcin@python-works.com>
parents:
1664
diff
changeset
|
170 if c.file.is_file(): |
3001
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
171 c.load_full_history = False |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
172 file_last_cs = c.file.last_changeset |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
173 c.file_changeset = (c.changeset |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
174 if c.changeset.revision < file_last_cs.revision |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
175 else file_last_cs) |
3237
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
176 #determine if we're on branch head |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
177 _branches = c.db_repo_scm_instance.branches |
3267
7b74079beec9
coding style: fix trailing and leading spaces and tabs
Mads Kiilerich <madski@unity3d.com>
parents:
3237
diff
changeset
|
178 c.on_branch_head = revision in _branches.keys() + _branches.values() |
3001
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
179 _hist = [] |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
180 c.file_history = [] |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
181 if c.load_full_history: |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
182 c.file_history, _hist = self._get_node_history(c.changeset, f_path) |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
183 |
2456
51b203e44202
Add authors into file view
Marcin Kuzminski <marcin@python-works.com>
parents:
2428
diff
changeset
|
184 c.authors = [] |
51b203e44202
Add authors into file view
Marcin Kuzminski <marcin@python-works.com>
parents:
2428
diff
changeset
|
185 for a in set([x.author for x in _hist]): |
51b203e44202
Add authors into file view
Marcin Kuzminski <marcin@python-works.com>
parents:
2428
diff
changeset
|
186 c.authors.append((h.email(a), h.person(a))) |
1190
0d7a127e6449
use cs get history instead of node.history, node history have to much reference calls
Marcin Kuzminski <marcin@python-works.com>
parents:
1189
diff
changeset
|
187 else: |
2456
51b203e44202
Add authors into file view
Marcin Kuzminski <marcin@python-works.com>
parents:
2428
diff
changeset
|
188 c.authors = c.file_history = [] |
644
c8bd0e6cc3da
some changes for #45.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
189 except RepositoryError, e: |
4077
0e1023147334
Use safe_str on flash messages.
Marcin Kuzminski <marcin@python-works.com>
parents:
4072
diff
changeset
|
190 h.flash(safe_str(e), category='error') |
3621
fe012b7df29d
missing files or bad files revisions should return 404s not redirects - ref #808
Marcin Kuzminski <marcin@python-works.com>
parents:
3591
diff
changeset
|
191 raise HTTPNotFound() |
644
c8bd0e6cc3da
some changes for #45.
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
192 |
2686
269c6e0b54cc
Reimplemented file-browser using partial-ajax
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
193 if request.environ.get('HTTP_X_PARTIAL_XHR'): |
269c6e0b54cc
Reimplemented file-browser using partial-ajax
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
194 return render('files/files_ypjax.html') |
269c6e0b54cc
Reimplemented file-browser using partial-ajax
Marcin Kuzminski <marcin@python-works.com>
parents:
2684
diff
changeset
|
195 |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
196 return render('files/files.html') |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
197 |
3749
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3654
diff
changeset
|
198 @LoginRequired() |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3654
diff
changeset
|
199 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
b950b884ab87
auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents:
3654
diff
changeset
|
200 'repository.admin') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
201 @jsonify |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
202 def history(self, repo_name, revision, f_path): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
203 changeset = self.__get_cs_or_redirect(revision, repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
204 f_path = f_path |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
205 _file = changeset.get_node(f_path) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
206 if _file.is_file(): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
207 file_history, _hist = self._get_node_history(changeset, f_path) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
208 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
209 res = [] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
210 for obj in file_history: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
211 res.append({ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
212 'text': obj[1], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
213 'children': [{'id': o[0], 'text': o[1]} for o in obj[0]] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
214 }) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
215 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
216 data = { |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
217 'more': False, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
218 'results': res |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
219 } |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
220 return data |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
221 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
222 @LoginRequired() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
223 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
224 'repository.admin') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
225 def authors(self, repo_name, revision, f_path): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
226 changeset = self.__get_cs_or_redirect(revision, repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
227 f_path = f_path |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
228 _file = changeset.get_node(f_path) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
229 if _file.is_file(): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
230 file_history, _hist = self._get_node_history(changeset, f_path) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
231 c.authors = [] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
232 for a in set([x.author for x in _hist]): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
233 c.authors.append((h.email(a), h.person(a))) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
234 return render('files/files_history_box.html') |
3001
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
235 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
236 @LoginRequired() |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
237 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
238 'repository.admin') |
147
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
239 def rawfile(self, repo_name, revision, f_path): |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
240 cs = self.__get_cs_or_redirect(revision, repo_name) |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
241 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path) |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
242 |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
243 response.content_disposition = 'attachment; filename=%s' % \ |
2255
95800dad44d0
fixes for tests on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2199
diff
changeset
|
244 safe_str(f_path.split(Repository.url_sep())[-1]) |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
245 |
160
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
246 response.content_type = file_node.mimetype |
147
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
247 return file_node.content |
2461
015a42e970a6
whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
2457
diff
changeset
|
248 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
249 @LoginRequired() |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
250 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
251 'repository.admin') |
485
9836541b0509
added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents:
438
diff
changeset
|
252 def raw(self, repo_name, revision, f_path): |
1137
82344ce0a892
clean and fixes in files controller
Marcin Kuzminski <marcin@python-works.com>
parents:
1134
diff
changeset
|
253 cs = self.__get_cs_or_redirect(revision, repo_name) |
1189
a4e1b955fe07
fixes for rawfile, annotation, download. It will check now if it's a filenode.
Marcin Kuzminski <marcin@python-works.com>
parents:
1151
diff
changeset
|
254 file_node = self.__get_filenode_or_redirect(repo_name, cs, f_path) |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
255 |
1241
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
256 raw_mimetype_mapping = { |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
257 # map original mimetype to a mimetype used for "show as raw" |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
258 # you can also provide a content-disposition to override the |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
259 # default "attachment" disposition. |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
260 # orig_type: (new_type, new_dispo) |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
261 |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
262 # show images inline: |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
263 'image/x-icon': ('image/x-icon', 'inline'), |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
264 'image/png': ('image/png', 'inline'), |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
265 'image/gif': ('image/gif', 'inline'), |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
266 'image/jpeg': ('image/jpeg', 'inline'), |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
267 'image/svg+xml': ('image/svg+xml', 'inline'), |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
268 } |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
269 |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
270 mimetype = file_node.mimetype |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
271 try: |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
272 mimetype, dispo = raw_mimetype_mapping[mimetype] |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
273 except KeyError: |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
274 # we don't know anything special about this, handle it safely |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
275 if file_node.is_binary: |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
276 # do same as download raw for binary files |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
277 mimetype, dispo = 'application/octet-stream', 'attachment' |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
278 else: |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
279 # do not just use the original mimetype, but force text/plain, |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
280 # otherwise it would serve text/html and that might be unsafe. |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
281 # Note: underlying vcs library fakes text/plain mimetype if the |
1245
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1241
diff
changeset
|
282 # mimetype can not be determined and it thinks it is not |
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1241
diff
changeset
|
283 # binary.This might lead to erroneous text display in some |
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1241
diff
changeset
|
284 # cases, but helps in other cases, like with text files |
5f2fbab7c429
PEP8ify - controllers
Marcin Kuzminski <marcin@python-works.com>
parents:
1241
diff
changeset
|
285 # without extension. |
1241
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
286 mimetype, dispo = 'text/plain', 'inline' |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
287 |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
288 if dispo == 'attachment': |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
289 dispo = 'attachment; filename=%s' % \ |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1313
diff
changeset
|
290 safe_str(f_path.split(os.sep)[-1]) |
1241
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
291 |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
292 response.content_disposition = dispo |
ed5270522724
changed raw action to show images instead of saying about binary file
Marcin Kuzminski <marcin@python-works.com>
parents:
1224
diff
changeset
|
293 response.content_type = mimetype |
485
9836541b0509
added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents:
438
diff
changeset
|
294 return file_node.content |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
295 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
296 @LoginRequired() |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
297 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
298 def delete(self, repo_name, revision, f_path): |
4195
9581233e9275
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
299 repo = c.db_repo |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
300 if repo.enable_locking and repo.locked[0]: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
301 h.flash(_('This repository is has been locked by %s on %s') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
302 % (h.person_by_id(repo.locked[0]), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
303 h.fmt_date(h.time_to_datetime(repo.locked[1]))), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
304 'warning') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
305 return redirect(h.url('files_home', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
306 repo_name=repo_name, revision='tip')) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
307 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
308 # check if revision is a branch identifier- basically we cannot |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
309 # create multiple heads via file editing |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
310 _branches = repo.scm_instance.branches |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
311 # check if revision is a branch name or branch hash |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
312 if revision not in _branches.keys() + _branches.values(): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
313 h.flash(_('You can only delete files with revision ' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
314 'being a valid branch '), category='warning') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
315 return redirect(h.url('files_home', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
316 repo_name=repo_name, revision='tip', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
317 f_path=f_path)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
318 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
319 r_post = request.POST |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
320 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
321 c.cs = self.__get_cs_or_redirect(revision, repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
322 c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
323 |
4212
24c0d584ba86
General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4211
diff
changeset
|
324 c.default_message = _('Deleted file %s via Kallithea') % (f_path) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
325 c.f_path = f_path |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
326 node_path = f_path |
4197
d208416c84c6
Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4196
diff
changeset
|
327 author = self.authuser.full_contact |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
328 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
329 if r_post: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
330 message = r_post.get('message') or c.default_message |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
331 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
332 try: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
333 nodes = { |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
334 node_path: { |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
335 'content': '' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
336 } |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
337 } |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
338 self.scm_model.delete_nodes( |
4197
d208416c84c6
Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4196
diff
changeset
|
339 user=c.authuser.user_id, repo=c.db_repo, |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
340 message=message, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
341 nodes=nodes, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
342 parent_cs=c.cs, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
343 author=author, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
344 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
345 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
346 h.flash(_('Successfully deleted file %s') % f_path, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
347 category='success') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
348 except Exception: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
349 log.error(traceback.format_exc()) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
350 h.flash(_('Error occurred during commit'), category='error') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
351 return redirect(url('changeset_home', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
352 repo_name=c.repo_name, revision='tip')) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
353 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
354 return render('files/files_delete.html') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
355 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
356 @LoginRequired() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
357 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin') |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
358 def edit(self, repo_name, revision, f_path): |
4195
9581233e9275
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
359 repo = c.db_repo |
2727
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
360 if repo.enable_locking and repo.locked[0]: |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
361 h.flash(_('This repository is has been locked by %s on %s') |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
362 % (h.person_by_id(repo.locked[0]), |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
363 h.fmt_date(h.time_to_datetime(repo.locked[1]))), |
4070
008e460c5b9d
fixes issue #860.
Marcin Kuzminski <marcin@python-works.com>
parents:
4060
diff
changeset
|
364 'warning') |
2727
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
365 return redirect(h.url('files_home', |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
366 repo_name=repo_name, revision='tip')) |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
367 |
3237
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
368 # check if revision is a branch identifier- basically we cannot |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
369 # create multiple heads via file editing |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
370 _branches = repo.scm_instance.branches |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
371 # check if revision is a branch name or branch hash |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
372 if revision not in _branches.keys() + _branches.values(): |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
373 h.flash(_('You can only edit files with revision ' |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
374 'being a valid branch '), category='warning') |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
375 return redirect(h.url('files_home', |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
376 repo_name=repo_name, revision='tip', |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
377 f_path=f_path)) |
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
378 |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
379 r_post = request.POST |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
380 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
381 c.cs = self.__get_cs_or_redirect(revision, repo_name) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
382 c.file = self.__get_filenode_or_redirect(repo_name, c.cs, f_path) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
383 |
1313
856be614d9a4
disabled edition of binary files
Marcin Kuzminski <marcin@python-works.com>
parents:
1312
diff
changeset
|
384 if c.file.is_binary: |
856be614d9a4
disabled edition of binary files
Marcin Kuzminski <marcin@python-works.com>
parents:
1312
diff
changeset
|
385 return redirect(url('files_home', repo_name=c.repo_name, |
4070
008e460c5b9d
fixes issue #860.
Marcin Kuzminski <marcin@python-works.com>
parents:
4060
diff
changeset
|
386 revision=c.cs.raw_id, f_path=f_path)) |
4212
24c0d584ba86
General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4211
diff
changeset
|
387 c.default_message = _('Edited file %s via Kallithea') % (f_path) |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
388 c.f_path = f_path |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
389 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
390 if r_post: |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
391 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
392 old_content = c.file.content |
1306
6e1d24503383
Added support for ascendent characters for inMemoryCommit
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
393 sl = old_content.splitlines(1) |
6e1d24503383
Added support for ascendent characters for inMemoryCommit
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
394 first_line = sl[0] if sl else '' |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
395 # modes: 0 - Unix, 1 - Mac, 2 - DOS |
1306
6e1d24503383
Added support for ascendent characters for inMemoryCommit
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
396 mode = detect_mode(first_line, 0) |
3839
9dec870411e0
Added more tests for web based file edit and add
Marcin Kuzminski <marcin@python-works.com>
parents:
3749
diff
changeset
|
397 content = convert_line_endings(r_post.get('content', ''), mode) |
1306
6e1d24503383
Added support for ascendent characters for inMemoryCommit
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
398 |
3237
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
399 message = r_post.get('message') or c.default_message |
4197
d208416c84c6
Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4196
diff
changeset
|
400 author = self.authuser.full_contact |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
401 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
402 if content == old_content: |
3621
fe012b7df29d
missing files or bad files revisions should return 404s not redirects - ref #808
Marcin Kuzminski <marcin@python-works.com>
parents:
3591
diff
changeset
|
403 h.flash(_('No changes'), category='warning') |
1306
6e1d24503383
Added support for ascendent characters for inMemoryCommit
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
404 return redirect(url('changeset_home', repo_name=c.repo_name, |
6e1d24503383
Added support for ascendent characters for inMemoryCommit
Marcin Kuzminski <marcin@python-works.com>
parents:
1305
diff
changeset
|
405 revision='tip')) |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
406 try: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
407 self.scm_model.commit_change(repo=c.db_repo_scm_instance, |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1308
diff
changeset
|
408 repo_name=repo_name, cs=c.cs, |
4197
d208416c84c6
Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4196
diff
changeset
|
409 user=self.authuser.user_id, |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1308
diff
changeset
|
410 author=author, message=message, |
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1308
diff
changeset
|
411 content=content, f_path=f_path) |
2570 | 412 h.flash(_('Successfully committed to %s') % f_path, |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
413 category='success') |
1311
6705eeebc41b
moved out commit into scm model, and added cache invalidation after commit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1308
diff
changeset
|
414 except Exception: |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
415 log.error(traceback.format_exc()) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
416 h.flash(_('Error occurred during commit'), category='error') |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
417 return redirect(url('changeset_home', |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
418 repo_name=c.repo_name, revision='tip')) |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
419 |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
420 return render('files/files_edit.html') |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
421 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
422 @LoginRequired() |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
423 @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin') |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
424 def add(self, repo_name, revision, f_path): |
2727
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
425 |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
426 repo = Repository.get_by_repo_name(repo_name) |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
427 if repo.enable_locking and repo.locked[0]: |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
428 h.flash(_('This repository is has been locked by %s on %s') |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
429 % (h.person_by_id(repo.locked[0]), |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
430 h.fmt_date(h.time_to_datetime(repo.locked[1]))), |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
431 'warning') |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
432 return redirect(h.url('files_home', |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
433 repo_name=repo_name, revision='tip')) |
5899fe08f063
Forbid adding files and editing from web interface while repo is locked
Marcin Kuzminski <marcin@python-works.com>
parents:
2688
diff
changeset
|
434 |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
435 r_post = request.POST |
1485
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
436 c.cs = self.__get_cs_or_redirect(revision, repo_name, |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
437 redirect_after=False) |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
438 if c.cs is None: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
439 c.cs = EmptyChangeset(alias=c.db_repo_scm_instance.alias) |
4212
24c0d584ba86
General renaming to Kallithea
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4211
diff
changeset
|
440 c.default_message = (_('Added file via Kallithea')) |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
441 c.f_path = f_path |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
442 |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
443 if r_post: |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
444 unix_mode = 0 |
3839
9dec870411e0
Added more tests for web based file edit and add
Marcin Kuzminski <marcin@python-works.com>
parents:
3749
diff
changeset
|
445 content = convert_line_endings(r_post.get('content', ''), unix_mode) |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
446 |
3237
f5dd76e2a7af
disable file editing when not on branch head fixes issue #462
Marcin Kuzminski <marcin@python-works.com>
parents:
3061
diff
changeset
|
447 message = r_post.get('message') or c.default_message |
3559
328eb707fe3f
added more strict checks for file path in add file controller
Marcin Kuzminski <marcin@python-works.com>
parents:
3547
diff
changeset
|
448 filename = r_post.get('filename') |
3839
9dec870411e0
Added more tests for web based file edit and add
Marcin Kuzminski <marcin@python-works.com>
parents:
3749
diff
changeset
|
449 location = r_post.get('location', '') |
1485
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
450 file_obj = r_post.get('upload_file', None) |
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
451 |
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
452 if file_obj is not None and hasattr(file_obj, 'filename'): |
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
453 filename = file_obj.filename |
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
454 content = file_obj.file |
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
455 |
4072
bf5c2c75c976
fixes issue #856 file upload >1000 bytes on windows throws exception.
Marcin Kuzminski <marcin@python-works.com>
parents:
4070
diff
changeset
|
456 if hasattr(content, 'file'): |
bf5c2c75c976
fixes issue #856 file upload >1000 bytes on windows throws exception.
Marcin Kuzminski <marcin@python-works.com>
parents:
4070
diff
changeset
|
457 # non posix systems store real file under file attr |
bf5c2c75c976
fixes issue #856 file upload >1000 bytes on windows throws exception.
Marcin Kuzminski <marcin@python-works.com>
parents:
4070
diff
changeset
|
458 content = content.file |
bf5c2c75c976
fixes issue #856 file upload >1000 bytes on windows throws exception.
Marcin Kuzminski <marcin@python-works.com>
parents:
4070
diff
changeset
|
459 |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
460 if not content: |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
461 h.flash(_('No content'), category='warning') |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
462 return redirect(url('changeset_home', repo_name=c.repo_name, |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
463 revision='tip')) |
1484
1db451a44504
fixed small issues with adding new filenodes
Marcin Kuzminski <marcin@python-works.com>
parents:
1483
diff
changeset
|
464 if not filename: |
1db451a44504
fixed small issues with adding new filenodes
Marcin Kuzminski <marcin@python-works.com>
parents:
1483
diff
changeset
|
465 h.flash(_('No filename'), category='warning') |
1db451a44504
fixed small issues with adding new filenodes
Marcin Kuzminski <marcin@python-works.com>
parents:
1483
diff
changeset
|
466 return redirect(url('changeset_home', repo_name=c.repo_name, |
1485
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
467 revision='tip')) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
468 #strip all crap out of file, just leave the basename |
3559
328eb707fe3f
added more strict checks for file path in add file controller
Marcin Kuzminski <marcin@python-works.com>
parents:
3547
diff
changeset
|
469 filename = os.path.basename(filename) |
328eb707fe3f
added more strict checks for file path in add file controller
Marcin Kuzminski <marcin@python-works.com>
parents:
3547
diff
changeset
|
470 node_path = os.path.join(location, filename) |
4197
d208416c84c6
Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4196
diff
changeset
|
471 author = self.authuser.full_contact |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
472 |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
473 try: |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
474 nodes = { |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
475 node_path: { |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
476 'content': content |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
477 } |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
478 } |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
479 self.scm_model.create_nodes( |
4197
d208416c84c6
Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4196
diff
changeset
|
480 user=c.authuser.user_id, repo=c.db_repo, |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
481 message=message, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
482 nodes=nodes, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
483 parent_cs=c.cs, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
484 author=author, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
485 ) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
486 |
2570 | 487 h.flash(_('Successfully committed to %s') % node_path, |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
488 category='success') |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
489 except NonRelativePathError, e: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
490 h.flash(_('Location must be relative path and must not ' |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
491 'contain .. in path'), category='warning') |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
492 return redirect(url('changeset_home', repo_name=c.repo_name, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3839
diff
changeset
|
493 revision='tip')) |
3559
328eb707fe3f
added more strict checks for file path in add file controller
Marcin Kuzminski <marcin@python-works.com>
parents:
3547
diff
changeset
|
494 except (NodeError, NodeAlreadyExistsError), e: |
1485
269905fac50a
added uploading of files from web interface directly into repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1484
diff
changeset
|
495 h.flash(_(e), category='error') |
1483
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
496 except Exception: |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
497 log.error(traceback.format_exc()) |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
498 h.flash(_('Error occurred during commit'), category='error') |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
499 return redirect(url('changeset_home', |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
500 repo_name=c.repo_name, revision='tip')) |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
501 |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
502 return render('files/files_add.html') |
7b67b0dcad6d
Added initial support for creating new nodes in repos
Marcin Kuzminski <marcin@python-works.com>
parents:
1480
diff
changeset
|
503 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
504 @LoginRequired() |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
505 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
506 'repository.admin') |
872
b956e6f415a2
implemented #91,
Marcin Kuzminski <marcin@python-works.com>
parents:
813
diff
changeset
|
507 def archivefile(self, repo_name, fname): |
945
05b59c48556f
fixed error when trying to make download on empty repository
Marcin Kuzminski <marcin@python-works.com>
parents:
942
diff
changeset
|
508 |
942
32318ec7bfc1
added branch/tag options to download links in summary
Marcin Kuzminski <marcin@python-works.com>
parents:
915
diff
changeset
|
509 fileformat = None |
32318ec7bfc1
added branch/tag options to download links in summary
Marcin Kuzminski <marcin@python-works.com>
parents:
915
diff
changeset
|
510 revision = None |
948
85ee0ea183e7
fixed archival in rhodecode to use new functions from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
945
diff
changeset
|
511 ext = None |
1450
2a8bf2a3da98
fixes #214 added support for downloading subrepos in download menu.
Marcin Kuzminski <marcin@python-works.com>
parents:
1401
diff
changeset
|
512 subrepos = request.GET.get('subrepos') == 'true' |
945
05b59c48556f
fixed error when trying to make download on empty repository
Marcin Kuzminski <marcin@python-works.com>
parents:
942
diff
changeset
|
513 |
1480
daa29da0f783
fixes for vcs settings module
Marcin Kuzminski <marcin@python-works.com>
parents:
1452
diff
changeset
|
514 for a_type, ext_data in settings.ARCHIVE_SPECS.items(): |
948
85ee0ea183e7
fixed archival in rhodecode to use new functions from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
945
diff
changeset
|
515 archive_spec = fname.split(ext_data[1]) |
85ee0ea183e7
fixed archival in rhodecode to use new functions from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
945
diff
changeset
|
516 if len(archive_spec) == 2 and archive_spec[1] == '': |
85ee0ea183e7
fixed archival in rhodecode to use new functions from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
945
diff
changeset
|
517 fileformat = a_type or ext_data[1] |
942
32318ec7bfc1
added branch/tag options to download links in summary
Marcin Kuzminski <marcin@python-works.com>
parents:
915
diff
changeset
|
518 revision = archive_spec[0] |
948
85ee0ea183e7
fixed archival in rhodecode to use new functions from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
945
diff
changeset
|
519 ext = ext_data[1] |
872
b956e6f415a2
implemented #91,
Marcin Kuzminski <marcin@python-works.com>
parents:
813
diff
changeset
|
520 |
b956e6f415a2
implemented #91,
Marcin Kuzminski <marcin@python-works.com>
parents:
813
diff
changeset
|
521 try: |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1044
diff
changeset
|
522 dbrepo = RepoModel().get_by_repo_name(repo_name) |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3621
diff
changeset
|
523 if not dbrepo.enable_downloads: |
3654
ec6354949623
Fix a lot of casings - use standard casing in most places
Mads Kiilerich <madski@unity3d.com>
parents:
3625
diff
changeset
|
524 return _('Downloads disabled') |
962
72f008ed9b18
implemented #84 downloads can be enabled/disabled per each repository from now.
Marcin Kuzminski <marcin@python-works.com>
parents:
961
diff
changeset
|
525 |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
526 if c.db_repo_scm_instance.alias == 'hg': |
1809
ef0066e95be5
fix archive download for git
Marcin Kuzminski <marcin@python-works.com>
parents:
1789
diff
changeset
|
527 # patch and reset hooks section of UI config to not run any |
ef0066e95be5
fix archive download for git
Marcin Kuzminski <marcin@python-works.com>
parents:
1789
diff
changeset
|
528 # hooks on fetching archives with subrepos |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
529 for k, v in c.db_repo_scm_instance._repo.ui.configitems('hooks'): |
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
530 c.db_repo_scm_instance._repo.ui.setconfig('hooks', k, None) |
1664
65386911df2a
fixes issue with mercurial 2.0 and archival of subrepos.
Marcin Kuzminski <marcin@python-works.com>
parents:
1568
diff
changeset
|
531 |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
532 cs = c.db_repo_scm_instance.get_changeset(revision) |
1480
daa29da0f783
fixes for vcs settings module
Marcin Kuzminski <marcin@python-works.com>
parents:
1452
diff
changeset
|
533 content_type = settings.ARCHIVE_SPECS[fileformat][0] |
872
b956e6f415a2
implemented #91,
Marcin Kuzminski <marcin@python-works.com>
parents:
813
diff
changeset
|
534 except ChangesetDoesNotExistError: |
b956e6f415a2
implemented #91,
Marcin Kuzminski <marcin@python-works.com>
parents:
813
diff
changeset
|
535 return _('Unknown revision %s') % revision |
945
05b59c48556f
fixed error when trying to make download on empty repository
Marcin Kuzminski <marcin@python-works.com>
parents:
942
diff
changeset
|
536 except EmptyRepositoryError: |
05b59c48556f
fixed error when trying to make download on empty repository
Marcin Kuzminski <marcin@python-works.com>
parents:
942
diff
changeset
|
537 return _('Empty repository') |
961
840ca7492dbe
fixed typo in exception
Marcin Kuzminski <marcin@python-works.com>
parents:
953
diff
changeset
|
538 except (ImproperArchiveTypeError, KeyError): |
948
85ee0ea183e7
fixed archival in rhodecode to use new functions from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
945
diff
changeset
|
539 return _('Unknown archive type') |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
540 # archive cache |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
541 from kallithea import CONFIG |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
542 rev_name = cs.raw_id[:12] |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
543 archive_name = '%s-%s%s' % (safe_str(repo_name.replace('/', '_')), |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
544 safe_str(rev_name), ext) |
872
b956e6f415a2
implemented #91,
Marcin Kuzminski <marcin@python-works.com>
parents:
813
diff
changeset
|
545 |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
546 use_cached_archive = False # defines if we use cached version of archive |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
547 archive_cache_enabled = CONFIG.get('archive_cache_dir') |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
548 if not subrepos and archive_cache_enabled: |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
549 #check if we it's ok to write |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
550 if not os.path.isdir(CONFIG['archive_cache_dir']): |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
551 os.makedirs(CONFIG['archive_cache_dir']) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
552 cached_archive_path = os.path.join(CONFIG['archive_cache_dir'], archive_name) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
553 if os.path.isfile(cached_archive_path): |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
554 log.debug('Found cached archive in %s' % cached_archive_path) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
555 fd, archive = None, cached_archive_path |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
556 use_cached_archive = True |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
557 else: |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
558 log.debug('Archive %s is not yet cached' % (archive_name)) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
559 |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
560 if not use_cached_archive: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
561 # generate new archive |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
562 temp_stream = None |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
563 try: |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
564 fd, archive = tempfile.mkstemp() |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
565 temp_stream = open(archive, 'wb') |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
566 log.debug('Creating new temp archive in %s' % archive) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
567 cs.fill_archive(stream=temp_stream, kind=fileformat, subrepos=subrepos) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
568 if not subrepos and archive_cache_enabled: |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
569 #if we generated the archive and use cache rename that |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
570 log.debug('Storing new archive in %s' % cached_archive_path) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
571 shutil.move(archive, cached_archive_path) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
572 archive = cached_archive_path |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
573 finally: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
574 if temp_stream: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4077
diff
changeset
|
575 temp_stream.close() |
2294
3c1d991755df
Use paste fileapp to properly send the archive size
Marcin Kuzminski <marcin@python-works.com>
parents:
2291
diff
changeset
|
576 |
2318
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
577 def get_chunked_archive(archive): |
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
578 stream = open(archive, 'rb') |
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
579 while True: |
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
580 data = stream.read(16 * 1024) |
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
581 if not data: |
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
582 stream.close() |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
583 if fd: # fd means we used temporary file |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
584 os.close(fd) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
585 if not archive_cache_enabled: |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
586 log.debug('Destroing temp archive %s' % archive) |
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
587 os.remove(archive) |
2318
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
588 break |
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
589 yield data |
3868
e262494ca099
store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
590 # store download action |
4197
d208416c84c6
Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4196
diff
changeset
|
591 action_logger(user=c.authuser, |
3868
e262494ca099
store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
592 action='user_downloaded_archive:%s' % (archive_name), |
e262494ca099
store download archive actions in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
3840
diff
changeset
|
593 repo=repo_name, ipaddr=self.ip_addr, commit=True) |
3490
c0ac34b8eb07
initial version of #788 tarball cache
Marcin Kuzminski <marcin@python-works.com>
parents:
3488
diff
changeset
|
594 response.content_disposition = str('attachment; filename=%s' % (archive_name)) |
2318
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
595 response.content_type = str(content_type) |
058e2743e7b7
fixes issue #455 Creating an archive generates an exception on Windows
Marcin Kuzminski <marcin@python-works.com>
parents:
2294
diff
changeset
|
596 return get_chunked_archive(archive) |
948
85ee0ea183e7
fixed archival in rhodecode to use new functions from vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
945
diff
changeset
|
597 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
598 @LoginRequired() |
1305
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
599 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
166317d464f3
Added server side file editing with commit
Marcin Kuzminski <marcin@python-works.com>
parents:
1273
diff
changeset
|
600 'repository.admin') |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
601 def diff(self, repo_name, f_path): |
1752
f28dc032adf0
Added handling of ignore whitespace flag in changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
1737
diff
changeset
|
602 ignore_whitespace = request.GET.get('ignorews') == '1' |
1768
5610fd9b6803
added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
1753
diff
changeset
|
603 line_context = request.GET.get('context', 3) |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
604 diff1 = request.GET.get('diff1', '') |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
605 diff2 = request.GET.get('diff2', '') |
337
fa3835d34fc1
fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents:
335
diff
changeset
|
606 c.action = request.GET.get('diff') |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
607 c.no_changes = diff1 == diff2 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
608 c.f_path = f_path |
1273
64cb9612f9aa
Added show as raw into big diff
Marcin Kuzminski <marcin@python-works.com>
parents:
1245
diff
changeset
|
609 c.big_diff = False |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
610 c.anchor_url = anchor_url |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
611 c.ignorews_url = _ignorews_url |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
612 c.context_url = _context_url |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
613 c.changes = OrderedDict() |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
614 c.changes[diff2] = [] |
2931
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
615 |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
616 #special case if we want a show rev only, it's impl here |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
617 #to reduce JS and callbacks |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
618 |
2931
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
619 if request.GET.get('show_rev'): |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
620 if str2bool(request.GET.get('annotate', 'False')): |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
621 _url = url('files_annotate_home', repo_name=c.repo_name, |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
622 revision=diff1, f_path=c.f_path) |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
623 else: |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
624 _url = url('files_home', repo_name=c.repo_name, |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
625 revision=diff1, f_path=c.f_path) |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
626 |
4c7cc3a4c330
fixed issue with show at revision button. Some JS were not properly loaded due to ajaxified files view.
Marcin Kuzminski <marcin@python-works.com>
parents:
2930
diff
changeset
|
627 return redirect(_url) |
275
2d61aa00e855
fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents:
272
diff
changeset
|
628 try: |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
512
diff
changeset
|
629 if diff1 not in ['', None, 'None', '0' * 12, '0' * 40]: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
630 c.changeset_1 = c.db_repo_scm_instance.get_changeset(diff1) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
631 try: |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
632 node1 = c.changeset_1.get_node(f_path) |
3440
4725d097c3c0
check if given f_path in diff is not a dir by any chance
Marcin Kuzminski <marcin@python-works.com>
parents:
3267
diff
changeset
|
633 if node1.is_dir(): |
3563
8d8c4dddd174
fixed bad raise statement
Marcin Kuzminski <marcin@python-works.com>
parents:
3559
diff
changeset
|
634 raise NodeError('%s path is a %s not a file' |
8d8c4dddd174
fixed bad raise statement
Marcin Kuzminski <marcin@python-works.com>
parents:
3559
diff
changeset
|
635 % (node1, type(node1))) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
636 except NodeDoesNotExistError: |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
637 c.changeset_1 = EmptyChangeset(cs=diff1, |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
638 revision=c.changeset_1.revision, |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
639 repo=c.db_repo_scm_instance) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
640 node1 = FileNode(f_path, '', changeset=c.changeset_1) |
275
2d61aa00e855
fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents:
272
diff
changeset
|
641 else: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
642 c.changeset_1 = EmptyChangeset(repo=c.db_repo_scm_instance) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
643 node1 = FileNode(f_path, '', changeset=c.changeset_1) |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
644 |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
512
diff
changeset
|
645 if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
646 c.changeset_2 = c.db_repo_scm_instance.get_changeset(diff2) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
647 try: |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
648 node2 = c.changeset_2.get_node(f_path) |
3563
8d8c4dddd174
fixed bad raise statement
Marcin Kuzminski <marcin@python-works.com>
parents:
3559
diff
changeset
|
649 if node2.is_dir(): |
8d8c4dddd174
fixed bad raise statement
Marcin Kuzminski <marcin@python-works.com>
parents:
3559
diff
changeset
|
650 raise NodeError('%s path is a %s not a file' |
8d8c4dddd174
fixed bad raise statement
Marcin Kuzminski <marcin@python-works.com>
parents:
3559
diff
changeset
|
651 % (node2, type(node2))) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
652 except NodeDoesNotExistError: |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
653 c.changeset_2 = EmptyChangeset(cs=diff2, |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
654 revision=c.changeset_2.revision, |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
655 repo=c.db_repo_scm_instance) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
656 node2 = FileNode(f_path, '', changeset=c.changeset_2) |
275
2d61aa00e855
fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents:
272
diff
changeset
|
657 else: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
658 c.changeset_2 = EmptyChangeset(repo=c.db_repo_scm_instance) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
659 node2 = FileNode(f_path, '', changeset=c.changeset_2) |
3037
789f20683559
fix error when diff path is a directory, edge case generated by google bots
Marcin Kuzminski <marcin@python-works.com>
parents:
3009
diff
changeset
|
660 except (RepositoryError, NodeError): |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
661 log.error(traceback.format_exc()) |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1810
diff
changeset
|
662 return redirect(url('files_home', repo_name=c.repo_name, |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
663 f_path=f_path)) |
275
2d61aa00e855
fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents:
272
diff
changeset
|
664 |
337
fa3835d34fc1
fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents:
335
diff
changeset
|
665 if c.action == 'download': |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
1752
diff
changeset
|
666 _diff = diffs.get_gitdiff(node1, node2, |
1768
5610fd9b6803
added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
1753
diff
changeset
|
667 ignore_whitespace=ignore_whitespace, |
5610fd9b6803
added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
1753
diff
changeset
|
668 context=line_context) |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
669 diff = diffs.DiffProcessor(_diff, format='gitdiff') |
1044
f3402cb92fdf
changed raw and download diffs to gitdiff
Marcin Kuzminski <marcin@python-works.com>
parents:
1043
diff
changeset
|
670 |
160
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
671 diff_name = '%s_vs_%s.diff' % (diff1, diff2) |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
672 response.content_type = 'text/plain' |
2083
60115135b77e
fixed raw_changeset for git, accidentally it was generated with hg patch headers
Marcin Kuzminski <marcin@python-works.com>
parents:
2046
diff
changeset
|
673 response.content_disposition = ( |
60115135b77e
fixed raw_changeset for git, accidentally it was generated with hg patch headers
Marcin Kuzminski <marcin@python-works.com>
parents:
2046
diff
changeset
|
674 'attachment; filename=%s' % diff_name |
60115135b77e
fixed raw_changeset for git, accidentally it was generated with hg patch headers
Marcin Kuzminski <marcin@python-works.com>
parents:
2046
diff
changeset
|
675 ) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
676 return diff.as_raw() |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
677 |
337
fa3835d34fc1
fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents:
335
diff
changeset
|
678 elif c.action == 'raw': |
1753
1d1ccb873d00
moved soon-to-be-deleted code from vcs to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
1752
diff
changeset
|
679 _diff = diffs.get_gitdiff(node1, node2, |
1768
5610fd9b6803
added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
1753
diff
changeset
|
680 ignore_whitespace=ignore_whitespace, |
5610fd9b6803
added line context control to diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
1753
diff
changeset
|
681 context=line_context) |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
682 diff = diffs.DiffProcessor(_diff, format='gitdiff') |
649
3765f0f479a2
fixed raw diff as purly raw without html
Marcin Kuzminski <marcin@python-works.com>
parents:
644
diff
changeset
|
683 response.content_type = 'text/plain' |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
684 return diff.as_raw() |
662
373ee7031003
fixed annotation bug, added history to annotation.
Marcin Kuzminski <marcin@python-works.com>
parents:
649
diff
changeset
|
685 |
337
fa3835d34fc1
fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents:
335
diff
changeset
|
686 else: |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
687 fid = h.FID(diff2, node2.path) |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
688 line_context_lcl = get_line_ctx(fid, request.GET) |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
689 ign_whitespace_lcl = get_ignore_ws(fid, request.GET) |
1149
d162de13caec
memory optimizations, call diffs only when needed ie. after checking for binary, and cutoff limit.
Marcin Kuzminski <marcin@python-works.com>
parents:
1137
diff
changeset
|
690 |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
691 lim = request.GET.get('fulldiff') or self.cut_off_limit |
2109 | 692 _, cs1, cs2, diff, st = diffs.wrapped_diff(filenode_old=node1, |
1789
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
693 filenode_new=node2, |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
694 cut_off_limit=lim, |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
695 ignore_whitespace=ign_whitespace_lcl, |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
696 line_context=line_context_lcl, |
17caf4efe15c
implements #308 rewrote diffs to enable displaying full diff on each file
Marcin Kuzminski <marcin@python-works.com>
parents:
1768
diff
changeset
|
697 enable_comments=False) |
2995
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
698 op = '' |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
699 filename = node1.path |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
700 cs_changes = { |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
701 'fid': [cs1, cs2, op, filename, diff, st] |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
702 } |
32471bd1f4ee
Implemented generation of changesets based
Marcin Kuzminski <marcin@python-works.com>
parents:
2981
diff
changeset
|
703 c.changes = cs_changes |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
704 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
705 return render('files/file_diff.html') |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
706 |
4043
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
707 @LoginRequired() |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
708 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
709 'repository.admin') |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
710 def diff_2way(self, repo_name, f_path): |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
711 diff1 = request.GET.get('diff1', '') |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
712 diff2 = request.GET.get('diff2', '') |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
713 try: |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
714 if diff1 not in ['', None, 'None', '0' * 12, '0' * 40]: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
715 c.changeset_1 = c.db_repo_scm_instance.get_changeset(diff1) |
4043
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
716 try: |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
717 node1 = c.changeset_1.get_node(f_path) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
718 if node1.is_dir(): |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
719 raise NodeError('%s path is a %s not a file' |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
720 % (node1, type(node1))) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
721 except NodeDoesNotExistError: |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
722 c.changeset_1 = EmptyChangeset(cs=diff1, |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
723 revision=c.changeset_1.revision, |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
724 repo=c.db_repo_scm_instance) |
4043
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
725 node1 = FileNode(f_path, '', changeset=c.changeset_1) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
726 else: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
727 c.changeset_1 = EmptyChangeset(repo=c.db_repo_scm_instance) |
4043
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
728 node1 = FileNode(f_path, '', changeset=c.changeset_1) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
729 |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
730 if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
731 c.changeset_2 = c.db_repo_scm_instance.get_changeset(diff2) |
4043
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
732 try: |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
733 node2 = c.changeset_2.get_node(f_path) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
734 if node2.is_dir(): |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
735 raise NodeError('%s path is a %s not a file' |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
736 % (node2, type(node2))) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
737 except NodeDoesNotExistError: |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
738 c.changeset_2 = EmptyChangeset(cs=diff2, |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
739 revision=c.changeset_2.revision, |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
740 repo=c.db_repo_scm_instance) |
4043
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
741 node2 = FileNode(f_path, '', changeset=c.changeset_2) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
742 else: |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
743 c.changeset_2 = EmptyChangeset(repo=c.db_repo_scm_instance) |
4043
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
744 node2 = FileNode(f_path, '', changeset=c.changeset_2) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
745 except (RepositoryError, NodeError): |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
746 log.error(traceback.format_exc()) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
747 return redirect(url('files_home', repo_name=c.repo_name, |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
748 f_path=f_path)) |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
749 c.node1 = node1 |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
750 c.node2 = node2 |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
751 c.cs1 = c.changeset_1 |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
752 c.cs2 = c.changeset_2 |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
753 |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
754 return render('files/diff_2way.html') |
a1bc4af25ec5
Implemented issue #387 side-by-side diffs view
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
755 |
2456
51b203e44202
Add authors into file view
Marcin Kuzminski <marcin@python-works.com>
parents:
2428
diff
changeset
|
756 def _get_node_history(self, cs, f_path, changesets=None): |
2977
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
757 """ |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
758 get changesets history for given node |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
759 |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
760 :param cs: changeset to calculate history |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
761 :param f_path: path for node to calculate history for |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
762 :param changesets: if passed don't calculate history and take |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
763 changesets defined in this list |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
764 """ |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
765 # calculate history based on tip |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
766 tip_cs = c.db_repo_scm_instance.get_changeset() |
2456
51b203e44202
Add authors into file view
Marcin Kuzminski <marcin@python-works.com>
parents:
2428
diff
changeset
|
767 if changesets is None: |
2977
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
768 try: |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
769 changesets = tip_cs.get_file_history(f_path) |
2981
6cd0f8f8aef1
Let the function calculating changeset history do all the work
Marcin Kuzminski <marcin@python-works.com>
parents:
2977
diff
changeset
|
770 except (NodeDoesNotExistError, ChangesetError): |
2977
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
771 #this node is not present at tip ! |
cff9d4e1d821
Fixed issue when node didn't exists at 'tip' and we tried calculate history based on that assumption.
Marcin Kuzminski <marcin@python-works.com>
parents:
2973
diff
changeset
|
772 changesets = cs.get_file_history(f_path) |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
773 hist_l = [] |
774
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
774 |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
775 changesets_group = ([], _("Changesets")) |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
776 branches_group = ([], _("Branches")) |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
777 tags_group = ([], _("Tags")) |
2046
4e1e265af5ca
remove branch from git filenode history drop-down
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
778 _hg = cs.repository.alias == 'hg' |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
779 for chs in changesets: |
3001
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
780 #_branch = '(%s)' % chs.branch if _hg else '' |
37c7abd34d44
implements #636, lazy loading of history and authors to speed up page responsiveness.
Marcin Kuzminski <marcin@python-works.com>
parents:
2995
diff
changeset
|
781 _branch = chs.branch |
3009
f0e19116f154
fixed file history tests
Marcin Kuzminski <marcin@python-works.com>
parents:
3001
diff
changeset
|
782 n_desc = 'r%s:%s (%s)' % (chs.revision, chs.short_id, _branch) |
774
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
783 changesets_group[0].append((chs.raw_id, n_desc,)) |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
784 hist_l.append(changesets_group) |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
785 |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
786 for name, chs in c.db_repo_scm_instance.branches.items(): |
774
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
787 branches_group[0].append((chs, name),) |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
788 hist_l.append(branches_group) |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
789 |
4196
06e49be38d78
Rename rhodecode_repo to db_repo_scm_instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4195
diff
changeset
|
790 for name, chs in c.db_repo_scm_instance.tags.items(): |
774
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
791 tags_group[0].append((chs, name),) |
c47152c5fe01
added tags, and branches to file history select box, fixed annotation changeset errors crash on wrongly given revions
Marcin Kuzminski <marcin@python-works.com>
parents:
691
diff
changeset
|
792 hist_l.append(tags_group) |
3009
f0e19116f154
fixed file history tests
Marcin Kuzminski <marcin@python-works.com>
parents:
3001
diff
changeset
|
793 |
2981
6cd0f8f8aef1
Let the function calculating changeset history do all the work
Marcin Kuzminski <marcin@python-works.com>
parents:
2977
diff
changeset
|
794 return hist_l, changesets |
1452
8585fbf3ed06
Implemented #111 copy github node finder solution
Marcin Kuzminski <marcin@python-works.com>
parents:
1450
diff
changeset
|
795 |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
796 @LoginRequired() |
1452
8585fbf3ed06
Implemented #111 copy github node finder solution
Marcin Kuzminski <marcin@python-works.com>
parents:
1450
diff
changeset
|
797 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
8585fbf3ed06
Implemented #111 copy github node finder solution
Marcin Kuzminski <marcin@python-works.com>
parents:
1450
diff
changeset
|
798 'repository.admin') |
2457
01e005cabd4d
moved login required into seperate calls for files due to optional API access option
Marcin Kuzminski <marcin@python-works.com>
parents:
2456
diff
changeset
|
799 @jsonify |
1452
8585fbf3ed06
Implemented #111 copy github node finder solution
Marcin Kuzminski <marcin@python-works.com>
parents:
1450
diff
changeset
|
800 def nodelist(self, repo_name, revision, f_path): |
8585fbf3ed06
Implemented #111 copy github node finder solution
Marcin Kuzminski <marcin@python-works.com>
parents:
1450
diff
changeset
|
801 if request.environ.get('HTTP_X_PARTIAL_XHR'): |
8585fbf3ed06
Implemented #111 copy github node finder solution
Marcin Kuzminski <marcin@python-works.com>
parents:
1450
diff
changeset
|
802 cs = self.__get_cs_or_redirect(revision, repo_name) |
1810
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1809
diff
changeset
|
803 _d, _f = ScmModel().get_nodes(repo_name, cs.raw_id, f_path, |
203af05539e0
implements #330 api method for listing nodes at particular revision
Marcin Kuzminski <marcin@python-works.com>
parents:
1809
diff
changeset
|
804 flat=False) |
2428
530bd12fc18a
removed JSON array envelope from filter files function
Marcin Kuzminski <marcin@python-works.com>
parents:
2318
diff
changeset
|
805 return {'nodes': _d + _f} |