Mercurial > public > src > rhodecode
annotate pylons_app/controllers/files.py @ 209:1a18994cdc3b v0.7.2
Added archives support. Version bump
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 23 May 2010 21:26:18 +0200 |
parents | b68b2246e5a6 |
children | a83a1799480c |
rev | line source |
---|---|
209
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
1 import tempfile |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
2 from pylons import request, response, session, tmpl_context as c, url, config, \ |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
3 app_globals as g |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 from pylons.controllers.util import abort, redirect |
209
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
5 from pylons_app.lib.auth import LoginRequired |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 from pylons_app.lib.base import BaseController, render |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
7 from pylons_app.lib.utils import get_repo_slug |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
8 from pylons_app.model.hg_model import HgModel |
209
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
9 from vcs.exceptions import RepositoryError, ChangesetError |
158
f905f45c457e
moved diff libs to vcs. updated htmls and css for diff and source
Marcin Kuzminski <marcin@python-works.com>
parents:
152
diff
changeset
|
10 from vcs.utils import diffs as differ |
209
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
11 import logging |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
12 from mercurial import archival |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
13 |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
14 |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 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
|
16 |
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 class FilesController(BaseController): |
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
|
18 |
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
|
19 @LoginRequired() |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
20 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
|
21 super(FilesController, self).__before__() |
93
aec4c0071cb3
added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
23 def index(self, repo_name, revision, f_path): |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
24 hg_model = HgModel() |
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
25 c.repo = repo = hg_model.get_repo(c.repo_name) |
149
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
26 revision = request.POST.get('at_rev', None) or revision |
145
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
27 |
149
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
28 def get_next_rev(cur): |
145
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
29 max_rev = len(c.repo.revisions) - 1 |
149
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
30 r = cur + 1 |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
31 if r > max_rev: |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
32 r = max_rev |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
33 return r |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
34 |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
35 def get_prev_rev(cur): |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
36 r = cur - 1 |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
37 return r |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
38 |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
39 c.f_path = f_path |
149
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
40 |
147
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
41 |
138
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
42 try: |
149
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
43 cur_rev = repo.get_changeset(revision).revision |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
44 prev_rev = repo.get_changeset(get_prev_rev(cur_rev)).raw_id |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
45 next_rev = repo.get_changeset(get_next_rev(cur_rev)).raw_id |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
46 |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
47 c.url_prev = url('files_home', repo_name=c.repo_name, |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
48 revision=prev_rev, f_path=f_path) |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
49 c.url_next = url('files_home', repo_name=c.repo_name, |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
50 revision=next_rev, f_path=f_path) |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
51 |
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
52 c.changeset = repo.get_changeset(revision) |
147
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
53 try: |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
54 c.file_msg = c.changeset.get_file_message(f_path) |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
55 except: |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
56 c.file_msg = None |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
57 |
142
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
138
diff
changeset
|
58 c.cur_rev = c.changeset.raw_id |
f7218849798a
Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents:
138
diff
changeset
|
59 c.rev_nr = c.changeset.revision |
138
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
60 c.files_list = c.changeset.get_node(f_path) |
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
61 c.file_history = self._get_history(repo, c.files_list, f_path) |
147
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
62 |
145
3f01d02c2cc6
fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents:
142
diff
changeset
|
63 except (RepositoryError, ChangesetError): |
138
5f42d751c719
fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents:
131
diff
changeset
|
64 c.files_list = None |
99
5b57295601b6
Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents:
93
diff
changeset
|
65 |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
66 return render('files/files.html') |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
67 |
147
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
68 def rawfile(self, repo_name, revision, f_path): |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
69 hg_model = HgModel() |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
70 c.repo = hg_model.get_repo(c.repo_name) |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
71 file_node = c.repo.get_changeset(revision).get_node(f_path) |
160
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
72 response.content_type = file_node.mimetype |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
73 response.content_disposition = 'attachment; filename=%s' \ |
147
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
74 % f_path.split('/')[-1] |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
75 return file_node.content |
873fd2dc62c2
Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents:
145
diff
changeset
|
76 |
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
|
77 def annotate(self, repo_name, revision, f_path): |
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
|
78 hg_model = HgModel() |
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
|
79 c.repo = hg_model.get_repo(c.repo_name) |
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
|
80 cs = c.repo.get_changeset(revision) |
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
|
81 c.file = cs.get_node(f_path) |
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
|
82 c.file_msg = cs.get_file_message(f_path) |
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
|
83 c.cur_rev = cs.raw_id |
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
|
84 c.f_path = f_path |
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
|
85 c.annotate = cs.get_file_annotate(f_path) |
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
|
86 return render('files/files_annotate.html') |
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
|
87 |
149
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
88 def archivefile(self, repo_name, revision, fileformat): |
209
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
89 archive_specs = { |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
90 '.tar.bz2': ('application/x-tar', 'tbz2'), |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
91 '.tar.gz': ('application/x-tar', 'tgz'), |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
92 '.zip': ('application/zip', 'zip'), |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
93 } |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
94 if not archive_specs.has_key(fileformat): |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
95 return 'Unknown archive type %s' % fileformat |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
96 |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
97 def read_in_chunks(file_object, chunk_size=1024 * 40): |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
98 """Lazy function (generator) to read a file piece by piece. |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
99 Default chunk size: 40k.""" |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
100 while True: |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
101 data = file_object.read(chunk_size) |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
102 if not data: |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
103 break |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
104 yield data |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
105 |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
106 archive = tempfile.TemporaryFile() |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
107 repo = HgModel().get_repo(repo_name).repo |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
108 fname = '%s-%s%s' % (repo_name, revision, fileformat) |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
109 archival.archive(repo, archive, revision, archive_specs[fileformat][1], |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
110 prefix='%s-%s' % (repo_name, revision)) |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
111 response.content_type = archive_specs[fileformat][0] |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
112 response.content_disposition = 'attachment; filename=%s' % fname |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
113 archive.seek(0) |
1a18994cdc3b
Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents:
191
diff
changeset
|
114 return read_in_chunks(archive) |
149
b3c93efd1c97
Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents:
147
diff
changeset
|
115 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
116 def diff(self, repo_name, f_path): |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
117 hg_model = HgModel() |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
118 diff1 = request.GET.get('diff1') |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
119 diff2 = request.GET.get('diff2') |
160
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
120 c.action = action = request.GET.get('diff') |
131
49c7e191c2cd
Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents:
130
diff
changeset
|
121 c.no_changes = diff1 == diff2 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
122 c.f_path = f_path |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
123 c.repo = hg_model.get_repo(c.repo_name) |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
124 c.changeset_1 = c.repo.get_changeset(diff1) |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
125 c.changeset_2 = c.repo.get_changeset(diff2) |
152
0c00fbaff55a
Fixed differ to properly extract filenames, and dates from diff file. and swaped order of columns with lines nr in diff html
Marcin Kuzminski <marcin@python-works.com>
parents:
149
diff
changeset
|
126 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
127 c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short) |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
128 c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short) |
158
f905f45c457e
moved diff libs to vcs. updated htmls and css for diff and source
Marcin Kuzminski <marcin@python-works.com>
parents:
152
diff
changeset
|
129 f_udiff = differ.get_udiff(c.changeset_1.get_node(f_path), |
f905f45c457e
moved diff libs to vcs. updated htmls and css for diff and source
Marcin Kuzminski <marcin@python-works.com>
parents:
152
diff
changeset
|
130 c.changeset_2.get_node(f_path)) |
160
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
131 |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
132 diff = differ.DiffProcessor(f_udiff) |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
133 |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
134 if action == 'download': |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
135 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
|
136 response.content_type = 'text/plain' |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
137 response.content_disposition = 'attachment; filename=%s' \ |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
138 % diff_name |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
139 return diff.raw_diff() |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
140 |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
141 elif action == 'raw': |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
142 c.cur_diff = '<pre class="raw">%s</pre>' % diff.raw_diff() |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
143 elif action == 'diff': |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
144 c.cur_diff = diff.as_html() |
0f7f93df5802
implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents:
158
diff
changeset
|
145 |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
146 return render('files/file_diff.html') |
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
147 |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
148 def _get_history(self, repo, node, f_path): |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
149 from vcs.nodes import NodeKind |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
150 if not node.kind is NodeKind.FILE: |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
151 return [] |
129
42d46deb124d
implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents:
128
diff
changeset
|
152 changesets = node.history |
128
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
153 hist_l = [] |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
154 for chs in changesets: |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
155 n_desc = 'r%s:%s' % (chs.revision, chs._short) |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
156 hist_l.append((chs._short, n_desc,)) |
9deb6f1d5b90
Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents:
106
diff
changeset
|
157 return hist_l |