log.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:Taigabot 作者: FrozenPigs 项目源码 文件源码
def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message):
        """Append a new log entry to the revlog at filepath.

        :param config_reader: configuration reader of the repository - used to obtain
            user information. May also be an Actor instance identifying the committer directly.
            May also be None
        :param filepath: full path to the log file
        :param oldbinsha: binary sha of the previous commit
        :param newbinsha: binary sha of the current commit
        :param message: message describing the change to the reference
        :param write: If True, the changes will be written right away. Otherwise
            the change will not be written
        :return: RefLogEntry objects which was appended to the log
        :note: As we are append-only, concurrent access is not a problem as we
            do not interfere with readers."""
        if len(oldbinsha) != 20 or len(newbinsha) != 20:
            raise ValueError("Shas need to be given in binary format")
        # END handle sha type
        assure_directory_exists(filepath, is_file=True)
        first_line = message.split('\n')[0]
        committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader)
        entry = RefLogEntry((
            bin_to_hex(oldbinsha).decode('ascii'),
            bin_to_hex(newbinsha).decode('ascii'),
            committer, (int(time.time()), time.altzone), first_line
        ))

        lf = LockFile(filepath)
        lf._obtain_lock_or_raise()
        fd = open(filepath, 'ab')
        try:
            fd.write(entry.format().encode(defenc))
        finally:
            fd.close()
            lf._release_lock()
        # END handle write operation

        return entry
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号