|
a/Allura/allura/model/repo.py |
|
b/Allura/allura/model/repo.py |
|
... |
|
... |
4 |
from hashlib import sha1
|
4 |
from hashlib import sha1
|
5 |
from itertools import izip, chain
|
5 |
from itertools import izip, chain
|
6 |
from datetime import datetime
|
6 |
from datetime import datetime
|
7 |
from collections import defaultdict
|
7 |
from collections import defaultdict
|
8 |
|
8 |
|
9 |
from pylons import g
|
9 |
from pylons import g, c
|
10 |
import pymongo.errors
|
10 |
import pymongo.errors
|
11 |
|
11 |
|
12 |
from ming import Field, Index, collection
|
12 |
from ming import Field, Index, collection
|
13 |
from ming import schema as S
|
13 |
from ming import schema as S
|
14 |
from ming.base import Object
|
14 |
from ming.base import Object
|
|
... |
|
... |
131 |
session(r).expunge(r)
|
131 |
session(r).expunge(r)
|
132 |
r = cls.query.get(_id=id)
|
132 |
r = cls.query.get(_id=id)
|
133 |
return r, isnew
|
133 |
return r, isnew
|
134 |
|
134 |
|
135 |
class Commit(RepoObject):
|
135 |
class Commit(RepoObject):
|
|
|
136 |
type_s = 'Commit'
|
136 |
# Ephemeral attrs
|
137 |
# Ephemeral attrs
|
137 |
repo=None
|
138 |
repo=None
|
138 |
|
139 |
|
139 |
def set_context(self, repo):
|
140 |
def set_context(self, repo):
|
140 |
self.repo = repo
|
141 |
self.repo = repo
|
|
... |
|
... |
167 |
message = h.really_unicode(self.message)
|
168 |
message = h.really_unicode(self.message)
|
168 |
first_line = message.split('\n')[0]
|
169 |
first_line = message.split('\n')[0]
|
169 |
return h.text.truncate(first_line, 50)
|
170 |
return h.text.truncate(first_line, 50)
|
170 |
|
171 |
|
171 |
def shorthand_id(self):
|
172 |
def shorthand_id(self):
|
|
|
173 |
if self.repo is None: self.repo = self.guess_repo()
|
|
|
174 |
if self.repo is None: return repr(self)
|
172 |
return self.repo.shorthand_for_commit(self._id)
|
175 |
return self.repo.shorthand_for_commit(self._id)
|
173 |
|
176 |
|
174 |
@LazyProperty
|
177 |
@LazyProperty
|
175 |
def symbolic_ids(self):
|
178 |
def symbolic_ids(self):
|
176 |
return self.repo.symbolics_for_commit(self.legacy)
|
179 |
return self.repo.symbolics_for_commit(self.legacy)
|
177 |
|
180 |
|
178 |
def url(self):
|
181 |
def url(self):
|
|
|
182 |
if self.repo is None: self.repo = self.guess_repo()
|
|
|
183 |
if self.repo is None: return '#'
|
179 |
return self.repo.url_for_commit(self.legacy)
|
184 |
return self.repo.url_for_commit(self.legacy)
|
|
|
185 |
|
|
|
186 |
def guess_repo(self):
|
|
|
187 |
for ac in c.project.app_configs:
|
|
|
188 |
try:
|
|
|
189 |
app = c.project.app_instance(ac)
|
|
|
190 |
if app.repo._id in self.repo_ids:
|
|
|
191 |
return app.repo
|
|
|
192 |
except AttributeError:
|
|
|
193 |
pass
|
|
|
194 |
return None
|
|
|
195 |
|
|
|
196 |
def link_text(self):
|
|
|
197 |
'''The link text that will be used when a shortlink to this artifact
|
|
|
198 |
is expanded into an <a></a> tag.
|
|
|
199 |
|
|
|
200 |
By default this method returns shorthand_id(). Subclasses should
|
|
|
201 |
override this method to provide more descriptive link text.
|
|
|
202 |
'''
|
|
|
203 |
return self.shorthand_id()
|
180 |
|
204 |
|
181 |
def log_iter(self, skip, count):
|
205 |
def log_iter(self, skip, count):
|
182 |
for oids in utils.chunked_iter(commitlog(self._id), QSIZE):
|
206 |
for oids in utils.chunked_iter(commitlog(self._id), QSIZE):
|
183 |
oids = list(oids)
|
207 |
oids = list(oids)
|
184 |
commits = dict(
|
208 |
commits = dict(
|