示例#1
0
文件: hg.py 项目: pombredanne/allura
 def refresh_commit_info(self, oid, seen, lazy=True):
     from allura.model.repo import CommitDoc
     ci_doc = CommitDoc.m.get(_id=oid)
     if ci_doc and lazy: return False
     obj = self._hg[oid]
     # Save commit metadata
     mo = self.re_hg_user.match(obj.user())
     if mo:
         user_name, user_email = mo.groups()
     else:
         user_name = user_email = obj.user()
     user = Object(name=h.really_unicode(user_name),
                   email=h.really_unicode(user_email),
                   date=datetime.utcfromtimestamp(obj.date()[0]))
     fake_tree = self._tree_from_changectx(obj)
     args = dict(tree_id=fake_tree.hex(),
                 committed=user,
                 authored=user,
                 message=h.really_unicode(obj.description() or ''),
                 child_ids=[],
                 parent_ids=[
                     p.hex() for p in self.real_parents(obj)
                     if p.hex() != obj.hex()
                 ])
     if ci_doc:
         ci_doc.update(args)
         ci_doc.m.save()
     else:
         ci_doc = CommitDoc(dict(args, _id=oid))
         try:
             ci_doc.m.insert(safe=True)
         except DuplicateKeyError:
             if lazy: return False
     self.refresh_tree_info(fake_tree, seen, lazy)
     return True
示例#2
0
 def refresh_commit_info(self, oid, seen, lazy=True):
     from allura.model.repo import CommitDoc
     ci_doc = CommitDoc.m.get(_id=oid)
     if ci_doc and lazy: return False
     ci = self._git.rev_parse(oid)
     args = dict(tree_id=ci.tree.hexsha,
                 committed=Object(
                     name=h.really_unicode(ci.committer.name),
                     email=h.really_unicode(ci.committer.email),
                     date=datetime.utcfromtimestamp(ci.committed_date)),
                 authored=Object(name=h.really_unicode(ci.author.name),
                                 email=h.really_unicode(ci.author.email),
                                 date=datetime.utcfromtimestamp(
                                     ci.authored_date)),
                 message=h.really_unicode(ci.message or ''),
                 child_ids=[],
                 parent_ids=[p.hexsha for p in ci.parents])
     if ci_doc:
         ci_doc.update(**args)
         ci_doc.m.save()
     else:
         ci_doc = CommitDoc(dict(args, _id=ci.hexsha))
         try:
             ci_doc.m.insert(safe=True)
         except DuplicateKeyError:
             if lazy: return False
     self.refresh_tree_info(ci.tree, seen, lazy)
     return True
示例#3
0
 def refresh_commit_info(self, oid, seen_object_ids, lazy=True):
     from allura.model.repo import CommitDoc, DiffInfoDoc
     ci_doc = CommitDoc.m.get(_id=oid)
     if ci_doc and lazy: return False
     revno = self._revno(oid)
     rev = self._revision(oid)
     try:
         log_entry = self._svn.log(self._url,
                                   revision_start=rev,
                                   limit=1,
                                   discover_changed_paths=True)[0]
     except pysvn.ClientError:
         log.info('ClientError processing %r %r, treating as empty',
                  oid,
                  self._repo,
                  exc_info=True)
         log_entry = Object(date='', message='', changed_paths=[])
     log_date = None
     if hasattr(log_entry, 'date'):
         log_date = datetime.utcfromtimestamp(log_entry.date)
     user = Object(name=h.really_unicode(log_entry.get(
         'author', '--none--')),
                   email='',
                   date=log_date)
     args = dict(tree_id=None,
                 committed=user,
                 authored=user,
                 message=h.really_unicode(
                     log_entry.get("message", "--none--")),
                 parent_ids=[],
                 child_ids=[])
     if revno > 1:
         args['parent_ids'] = [self._oid(revno - 1)]
     if ci_doc:
         ci_doc.update(**args)
         ci_doc.m.save()
     else:
         ci_doc = CommitDoc(dict(args, _id=oid))
         try:
             ci_doc.m.insert(safe=True)
         except DuplicateKeyError:
             if lazy: return False
     # Save diff info
     di = DiffInfoDoc.make(dict(_id=ci_doc._id, differences=[]))
     for path in log_entry.changed_paths:
         if path.action in ('A', 'M', 'R'):
             try:
                 rhs_info = self._svn.info2(
                     self._url + h.really_unicode(path.path),
                     revision=self._revision(ci_doc._id),
                     recurse=False)[0][1]
                 rhs_id = self._obj_oid(ci_doc._id, rhs_info)
             except pysvn.ClientError, e:
                 # pysvn will sometimes misreport deleted files (D) as
                 # something else (like A), causing info2() to raise a
                 # ClientError since the file doesn't exist in this
                 # revision. Set lrhs_id = None to treat like a deleted file
                 log.info('This error was handled gracefully and logged '
                          'for informational purposes only:\n' + str(e))
                 rhs_id = None
         else:
             rhs_id = None
         if ci_doc.parent_ids and path.action in ('D', 'M', 'R'):
             try:
                 lhs_info = self._svn.info2(
                     self._url + h.really_unicode(path.path),
                     revision=self._revision(ci_doc.parent_ids[0]),
                     recurse=False)[0][1]
                 lhs_id = self._obj_oid(ci_doc._id, lhs_info)
             except pysvn.ClientError, e:
                 # pysvn will sometimes report new files as 'M'odified,
                 # causing info2() to raise ClientError since the file
                 # doesn't exist in the parent revision. Set lhs_id = None
                 # to treat like a newly added file.
                 log.info('This error was handled gracefully and logged '
                          'for informational purposes only:\n' + str(e))
                 lhs_id = None