Parent: [22f366] (diff)

Child: [514a04] (diff)

Download this file

repo.py    137 lines (115 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from datetime import datetime
from ming import Document, Field
from ming import schema as S
from .session import main_doc_session, project_doc_session
class Commit(Document):
class __mongometa__:
name = 'repo_ci'
session = main_doc_session
indexes = [
('parent_ids',),
('child_ids',),
('repo_ids',)]
User = dict(name=str, email=str, date=datetime)
_id = Field(str)
tree_id = Field(str)
committed = Field(User)
authored = Field(User)
message = Field(str)
parent_ids = Field([str])
child_ids = Field([str])
repo_ids = Field([S.ObjectId()])
def __repr__(self):
return '%s %s' % (
self._id[:7], self.summary)
@property
def summary(self):
if self.message:
summary = []
for line in self.message.splitlines():
line = line.rstrip()
if line: summary.append(line)
else: return ' '.join(summary)
return ' '.join(summary)
return ''
def url(self):
return ''
def shorthand_id(self):
return ''
@property
def author_url(self):
return ''
class Tree(Document):
class __mongometa__:
name = 'repo_tree'
session = main_doc_session
ObjType=S.OneOf('blob', 'tree', 'submodule')
_id = Field(str)
tree_ids = Field([dict(name=str, id=str)])
blob_ids = Field([dict(name=str, id=str)])
other_ids = Field([dict(name=str, id=str, type=ObjType)])
class LastCommit(Document):
class __mongometa__:
name = 'repo_last_commit'
session = project_doc_session
indexes = [
( 'repo_id', 'object_id'),
]
_id = Field(str)
repo_id=Field(S.ObjectId())
object_id=Field(str)
commit_info = Field(dict(
id=str,
date=datetime,
author=str,
author_email=str,
author_url=str,
href=str,
shortlink=str,
summary=str))
@classmethod
def set_last_commit(cls, repo_id, oid, commit):
lc = cls(dict(
_id='%s:%s' % (repo_id, oid),
repo_id=repo_id,
object_id=oid,
commit_info=dict(
id=commit._id,
author=commit.authored.name,
author_email=commit.authored.email,
author_url=commit.author_url,
date=commit.authored.date,
href=commit.url(),
shortlink=commit.shorthand_id(),
summary=commit.summary)))
lc.m.save(safe=False)
return lc
class Trees(Document):
class __mongometa__:
name = 'repo_trees'
session = main_doc_session
_id = Field(str) # commit ID
tree_ids = Field([str]) # tree IDs
class DiffInfo(Document):
class __mongometa__:
name = 'repo_diffinfo'
session = main_doc_session
_id = Field(str)
differences = Field([dict(name=str, lhs_id=str, rhs_id=str)])
class BasicBlock(Document):
class __mongometa__:
name = 'repo_basic_block'
session = main_doc_session
indexes = [
('commit_ids',) ]
_id = Field(str)
parent_commit_ids = Field([str])
commit_ids = Field([str])
commit_times = Field([datetime])
def __repr__(self):
return '%s: (P %s, T %s..%s (%d commits))' % (
self._id[:6],
[ oid[:6] for oid in self.parent_commit_ids ],
self.commit_ids[0][:6],
self.commit_ids[-1][:6],
len(self.commit_ids))