示例#1
0
def init_test_repo():
    babygit.put_test_repo(s)

    r = repo.Repo(s)
    stage.checkout(r) 
    tree = stage.getroot(r)
    tree = stage.save(r, 'dir/newfile', 'This is a new file!\n', tree)
    tree = stage.save(r, 'dir/anotherfile', 'This is another new file!\n', tree)
    tree = stage.save(r, 'dir/newfile', 'Replace contents\n', tree)
    stage.add(r, tree)
    stage.commit(r, 'Author <*****@*****.**>', 'Test adding a new file\n')
示例#2
0
文件: web.py 项目: jkingdon/ghilbert
def init_test_repo():
    babygit.put_test_repo(s)

    r = repo.Repo(s)
    stage.checkout(r) 
    tree = stage.getroot(r)
    tree = stage.save(r, 'dir/newfile', 'This is a new file!\n', tree)
    tree = stage.save(r, 'dir/anotherfile', 'This is another new file!\n', tree)
    tree = stage.save(r, 'dir/newfile', 'Replace contents\n', tree)
    stage.add(r, tree)
    stage.commit(r, 'Author <*****@*****.**>', 'Test adding a new file\n')
示例#3
0
    def post(self, arg):
        if arg == 'git-upload-pack':
            o = self.response.out
            lines = self.parse_pktlines(self.request.body)
            logging.debug(`lines`)
            wants = set()
            haves = set()
            in_haves = False
            ready = False
            common = None
            for l in lines:
                if l is None:
                    if in_haves:
                        o.write(packetstr('NAK\n'))
                        logging.debug('NAK')
                        return
                    else:
                        in_haves = True
                # TODO: parse have's
                elif l.startswith('want '):
                    wants.add(l.rstrip('\n').split(' ')[1])
                elif l.startswith('have '):
                    sha = l.rstrip('\n').split(' ')[1]
                    obj = self.repo.store.getobj(sha)
                    if obj is not None:
                        haves.add(sha)
                        common = sha
                        if not ready:
                            o.write(packetstr('ACK ' + sha + ' common\n'))
                            ready = False  # TODO: actually compute
                            if ready:
                                o.write(packetstr('ACK ' + sha + ' ready\n'))
                                logging.debug('ACK ' + sha + ' ready')
            objs = self.repo.walk(wants, haves)
            self.response.headers['Content-Type'] = 'application/x-git-upload-pack-result'
            if common is None:
                o.write(packetstr('NAK\n'))
                logging.debug('NAK')
            else:
                o.write(packetstr('ACK ' + common + '\n'))
                logging.debug('ACK ' + common)
            self.send_packfile(objs, o)
        elif arg == 'git-receive-pack':
            # Do authentication here, as this is the risky transaction
            if not self.authenticate():
                return

            lines, offset = self.parse_pktlist(self.request.body)
            #logging.debug(`lines` + ' offset=' + `offset`)
            self.response.headers['Content-Type'] = 'application/x-git-upload-pack-result'
            o = self.response.out
            status = self.process_packfile(self.request.body, offset)
            o.write(packetstr('unpack ' + status + '\n'))
            if status == 'ok':
                for l in lines:
                    l = l.rstrip('\n').split('\x00')[0]
                    oldsha, newsha, name = l.split(' ')
                    success = self.store.updateref(oldsha, newsha, name)
                    if success:
                        o.write(packetstr('ok ' + name + '\n'))
                    else:
                        o.write(packetstr('ng ' + name + ' fail\n'))
            o.write('0000')
        elif arg.startswith('save/'):
            if not self.has_write_perm:
                return app.common.error_403(self)
            editurl = arg[5:]
            stage.checkout(self.repo)
            tree = stage.getroot(self.repo)
            tree = stage.save(self.repo, editurl, self.request.get('content'))
            stage.add(self.repo, tree)
            author = self.userobj.identity
            msg = 'Commit from wiki\n'
            commitsha = stage.commit(self.repo, author, msg)
            self.response.out.write('saved ' + cgi.escape(editurl) + ' with commit ' + commitsha + '\n')
示例#4
0
文件: web.py 项目: jkingdon/ghilbert
    def post(self, arg):
        if arg == 'git-upload-pack':
            o = self.response.out
            lines = self.parse_pktlines(self.request.body)
            logging.debug(`lines`)
            wants = set()
            haves = set()
            in_haves = False
            ready = False
            common = None
            for l in lines:
                if l is None:
                    if in_haves:
                        o.write(packetstr('NAK\n'))
                        logging.debug('NAK')
                        return
                    else:
                        in_haves = True
                # TODO: parse have's
                elif l.startswith('want '):
                    wants.add(l.rstrip('\n').split(' ')[1])
                elif l.startswith('have '):
                    sha = l.rstrip('\n').split(' ')[1]
                    obj = self.repo.store.getobj(sha)
                    if obj is not None:
                        haves.add(sha)
                        common = sha
                        if not ready:
                            o.write(packetstr('ACK ' + sha + ' common\n'))
                            ready = False  # TODO: actually compute
                            if ready:
                                o.write(packetstr('ACK ' + sha + ' ready\n'))
                                logging.debug('ACK ' + sha + ' ready')
            objs = self.repo.walk(wants, haves)
            self.response.headers['Content-Type'] = 'application/x-git-upload-pack-result'
            if common is None:
                o.write(packetstr('NAK\n'))
                logging.debug('NAK')
            else:
                o.write(packetstr('ACK ' + common + '\n'))
                logging.debug('ACK ' + common)
            self.send_packfile(objs, o)
        elif arg == 'git-receive-pack':
            # Do authentication here, as this is the risky transaction
            if not self.authenticate():
                return

            lines, offset = self.parse_pktlist(self.request.body)
            #logging.debug(`lines` + ' offset=' + `offset`)
            self.response.headers['Content-Type'] = 'application/x-git-upload-pack-result'
            o = self.response.out
            status = self.process_packfile(self.request.body, offset)
            o.write(packetstr('unpack ' + status + '\n'))
            if status == 'ok':
                for l in lines:
                    l = l.rstrip('\n').split('\x00')[0]
                    oldsha, newsha, name = l.split(' ')
                    success = self.store.updateref(oldsha, newsha, name)
                    if success:
                        o.write(packetstr('ok ' + name + '\n'))
                    else:
                        o.write(packetstr('ng ' + name + ' fail\n'))
            o.write('0000')
        elif arg.startswith('save/'):
            if not self.has_write_perm:
                return app.common.error_403(self)
            editurl = arg[5:]
            stage.checkout(self.repo)
            tree = stage.getroot(self.repo)
            tree = stage.save(self.repo, editurl, self.request.get('content'))
            stage.add(self.repo, tree)
            author = self.userobj.identity
            msg = 'Commit from wiki\n'
            commitsha = stage.commit(self.repo, author, msg)
            self.response.out.write('saved ' + cgi.escape(editurl) + ' with commit ' + commitsha + '\n')
示例#5
0
文件: web.py 项目: google/ghilbert
    def post(self, arg):
        if arg == "git-upload-pack":
            o = self.response.out
            lines = self.parse_pktlines(self.request.body)
            logging.debug(` lines `)
            wants = set()
            haves = set()
            in_haves = False
            ready = False
            common = None
            for l in lines:
                if l is None:
                    if in_haves:
                        o.write(packetstr("NAK\n"))
                        logging.debug("NAK")
                        return
                    else:
                        in_haves = True
                # TODO: parse have's
                elif l.startswith("want "):
                    wants.add(l.rstrip("\n").split(" ")[1])
                elif l.startswith("have "):
                    sha = l.rstrip("\n").split(" ")[1]
                    obj = self.repo.store.getobj(sha)
                    if obj is not None:
                        haves.add(sha)
                        common = sha
                        if not ready:
                            o.write(packetstr("ACK " + sha + " common\n"))
                            ready = False  # TODO: actually compute
                            if ready:
                                o.write(packetstr("ACK " + sha + " ready\n"))
                                logging.debug("ACK " + sha + " ready")
            objs = self.repo.walk(wants, haves)
            self.response.headers["Content-Type"] = "application/x-git-upload-pack-result"
            if common is None:
                o.write(packetstr("NAK\n"))
                logging.debug("NAK")
            else:
                o.write(packetstr("ACK " + common + "\n"))
                logging.debug("ACK " + common)
            self.send_packfile(objs, o)
        elif arg == "git-receive-pack":
            # Do authentication here, as this is the risky transaction
            if not self.authenticate():
                return

            lines, offset = self.parse_pktlist(self.request.body)
            # logging.debug(`lines` + ' offset=' + `offset`)
            self.response.headers["Content-Type"] = "application/x-git-upload-pack-result"
            o = self.response.out
            status = self.process_packfile(self.request.body, offset)
            o.write(packetstr("unpack " + status + "\n"))
            if status == "ok":
                for l in lines:
                    l = l.rstrip("\n").split("\x00")[0]
                    oldsha, newsha, name = l.split(" ")
                    success = self.store.updateref(oldsha, newsha, name)
                    if success:
                        o.write(packetstr("ok " + name + "\n"))
                    else:
                        o.write(packetstr("ng " + name + " fail\n"))
            o.write("0000")
        elif arg.startswith("save/"):
            if not self.has_write_perm:
                return app.common.error_403(self)
            editurl = arg[5:]
            stage.checkout(self.repo)
            tree = stage.getroot(self.repo)
            tree = stage.save(self.repo, editurl, self.request.get("content"))
            stage.add(self.repo, tree)
            author = self.userobj.identity
            msg = "Commit from wiki\n"
            commitsha = stage.commit(self.repo, author, msg)
            self.response.out.write("saved " + cgi.escape(editurl) + " with commit " + commitsha + "\n")