def do_cmd(self): repos = self.link.repos args = self.args url = self.link.url rev = None path = parse.string(args[0]) if len(path) > 0: url = '/'.join((url, path)) if len(args) > 1: rev = int(args[1][0]) path, kind, size, changed, by, at = repos.stat(url, rev) if path is None: self.link.send_msg(gen.success(gen.list())) return props = repos.get_props(url, rev, False) if by is None: by = gen.list() else: by = gen.list(gen.string(by)) ls_data = gen.list(kind, size, gen.bool(len(props) > 0), changed, gen.list(gen.string(at)), by) self.link.send_msg(gen.success(gen.list(ls_data)))
def do_commit(self): repos = self.link.repos msg = parse.string(self.args[0]) self.commit_info = None if self.aborted: self.link.send_msg(gen.error(1, "aborted")) return try: rev, date, author, error = repos.complete_commit(self.commit, msg) except HookFailure as hf: err, msg = hooks.pre_commit(hf.code, hf.text) self.link.send_msg(gen.error(err, msg)) return print rev, date, author, error if rev is None: self.link.send_msg(gen.error(1, "vcs error: %s" % error)) return self.commit_info = gen.list(rev, gen.list(gen.string(date)), gen.list(gen.string(author)), gen.list()) self.link.send_msg(gen.success()) raise ChangeMode("auth", "command")
def do_commit(self): repos = self.link.repos msg = parse.string(self.args[0]) self.commit_info = None if self.aborted: self.link.send_msg(gen.error(1, "aborted")) return try: rev, date, author, error = repos.complete_commit(self.commit, msg) except HookFailure as hf: err, msg = hooks.pre_commit(hf.code, hf.text) self.link.send_msg(gen.error(err, msg)) return print rev, date, author, error if rev is None: self.link.send_msg(gen.error(1, "vcs error: %s" % error)) return self.commit_info = gen.list(rev, gen.list(gen.string(date)), gen.list(gen.string(author)), gen.list()) self.link.send_msg(gen.success()) raise ChangeMode('auth', 'command')
def do_cmd(self): repos = self.link.repos args = self.args url = self.link.url rev = None path = parse.string(args.pop(0)) if len(path) > 0: url = '/'.join((url, path)) arg = args.pop(0) if len(arg) > 0: rev = int(arg[0]) want_props = parse.bool(args.pop(0)) want_contents = parse.bool(args.pop(0)) fields = [] if len(args) > 0: fields = args.pop(0) ls_data = [] if want_contents: for path, kind, size, changed, by, at in repos.ls(url, rev): path_url = "%s/%s" % (url, path) has_props = len(repos.get_props(path_url, rev, False)) == 0 if by is None: by = gen.list() else: by = gen.list(gen.string(by)) ls_data.append(gen.list(gen.string(path), kind, size, gen.bool(has_props), changed, gen.list(gen.string(at)), by)) p = [] if want_props: for name, value in repos.get_props(url, rev): p.append(gen.list(gen.string(name), gen.string(value))) response = "%d %s %s" % (rev, gen.list(*p), gen.list(*ls_data)) self.link.send_msg(gen.success(response))
def do_cmd(self): repos = self.link.repos args = self.args url = self.link.url rev = None path = parse.string(args.pop(0)) if len(path) > 0: url = '/'.join((url, path)) arg = args.pop(0) if len(arg) > 0: rev = int(arg[0]) want_props = parse.bool(args.pop(0)) want_contents = parse.bool(args.pop(0)) fields = [] if len(args) > 0: fields = args.pop(0) ls_data = [] if want_contents: for path, kind, size, changed, by, at in repos.ls(url, rev): path_url = "%s/%s" % (url, path) has_props = len(repos.get_props(path_url, rev, False)) == 0 if by is None: by = gen.list() else: by = gen.list(gen.string(by)) ls_data.append( gen.list(gen.string(path), kind, size, gen.bool(has_props), changed, gen.list(gen.string(at)), by)) p = [] if want_props: for name, value in repos.get_props(url, rev): p.append(gen.list(gen.string(name), gen.string(value))) response = "%d %s %s" % (rev, gen.list(*p), gen.list(*ls_data)) self.link.send_msg(gen.success(response))
def do_cmd(self): repos = self.link.repos args = self.args url = self.link.url start_rev = None end_rev = None target_paths = [parse.string(x) for x in args.pop(0)] arg = args.pop(0) if len(arg) > 0: start_rev = int(arg[0]) if start_rev == 0: start_rev = 1 arg = args.pop(0) if len(arg) > 0: end_rev = int(arg[0]) if end_rev == 0: end_rev = 1 send_changed_paths = parse.bool(args.pop(0)) strict_node = parse.bool(args.pop(0)) limit = 0 if len(args) > 0: limit = int(args.pop(0)) include_merged_revisions = False if len(args) > 0: include_merged_revisions = parse.bool(args.pop(0)) # all-revprops | revprops # ( revprop:string ... ) for changes, rev, author, date, msg, has_children, revprops in repos.log(url, target_paths, start_rev, end_rev, limit): changed_paths = [] if send_changed_paths: for path, data in sorted(changes.items()): change, cp, cr, kind, tmod, pmod = data copy = gen.list() if cp is not None and cr is not None: copy = gen.list(gen.string(cp), cr) ct = gen.list(gen.string(kind), gen.bool(tmod), gen.bool(pmod)) changed_paths.append(gen.list(gen.string(path), change, copy, ct)) log_entry = gen.list(gen.list(*changed_paths), rev, gen.list(gen.string(author)), gen.list(gen.string(date)), gen.list(gen.string(msg))) self.link.send_msg(log_entry) self.link.send_msg('done') self.link.send_msg(gen.success())
def do_cmd(self): repos = self.link.repos args = self.args url = self.link.url rev = None path = parse.string(args[0]) if len(path) > 0: url = '/'.join((url, path)) if len(args[1]) > 0: rev = int(args[1][0]) want_props = parse.bool(args[2]) want_contents = parse.bool(args[3]) print "props: %s, contents: %s" % (want_props, want_contents) rev, props, contents = repos.get_file(url, rev) p = [] if want_props: for name, value in props: p.append(gen.list(gen.string(name), gen.string(value))) m = md5() data = contents.read(8192) total_len = len(data) while len(data) > 0: m.update(data) data = contents.read(8192) total_len += len(data) csum = gen.string(m.hexdigest()) contents.close() response = (gen.list(csum), rev, gen.list(*p)) self.link.send_msg(gen.success(*response)) if want_contents: if total_len == len(data): self.link.send_msg(gen.string(data)) else: rev, props, contents = repos.get_file(url, rev) data = contents.read(8192) while len(data) > 0: self.link.send_msg(gen.string(data)) data = contents.read(8192) self.link.send_msg(gen.string('')) self.link.send_msg(gen.success()) contents.close()
def update_dir(self, path, rev, want, props, contents, parent_token=None): repos = self.link.repos url = '/'.join((self.link.url, path)) newurl = '/'.join((self.newurl, path)) if '/' in want: want_head, want_tail = want.split('/', 1) else: want_head, want_tail = want, '' new_dir = True token = self.get_token(path) prev_rev, start_empty = self.get_prev(path) if prev_rev is None: new_dir = True elif not repos.paths_different(newurl, rev, url, prev_rev) \ and not self.get_prev_subpath_empty(path): return else: stat = repos.stat(url, prev_rev) new_dir = stat[0] is None if parent_token is None: self.send(gen.tuple('open-root', gen.list(rev), gen.string(token))) props = repos.get_props(url, rev) contents = contents[3] elif new_dir: self.send(gen.tuple('add-dir', gen.string(path), gen.string(parent_token), gen.string(token), '( )')) prev_rev = None else: self.send(gen.tuple('open-dir', gen.string(path), gen.string(parent_token), gen.string(token), gen.list(rev))) prev_props = {} if prev_rev is not None and not start_empty: for name, value in repos.get_props(url, prev_rev): prev_props[name] = value for name, value in props: if name in prev_props: if prev_props[name] == value: del prev_props[name] continue del prev_props[name] self.send(gen.tuple('change-dir-prop', gen.string(token), gen.string(name), gen.list(gen.string(value)))) for name in prev_props.keys(): self.send(gen.tuple('change-dir-prop', gen.string(token), gen.string(name), gen.list())) current_names = [] for name, kind, props, content in contents: if len(want_head) > 0 and want_head != name: continue current_names.append(name) entry_path = name if len(path) > 0: entry_path = '/'.join((path, name)) if kind == 'dir': self.update_dir(entry_path, rev, want_tail, props, content, token) elif kind == 'file': self.update_file(entry_path, rev, props, content, token) else: raise foo if prev_rev is not None and not start_empty: for entry in repos.ls(url, prev_rev, include_changed=False): name, kind, size, last_rev, last_author, last_date = entry if len(want_head) > 0 and want_head != name: continue if name not in current_names: entry_path = name if len(path) > 0: entry_path = '/'.join((path, name)) if entry_path in self.deleted_paths: continue self.send(gen.tuple('delete-entry', gen.string(entry_path), gen.list(prev_rev), gen.string(token))) self.send(gen.tuple('close-dir', gen.string(token)))
def update_file(self, path, rev, props, contents, parent_token): repos = self.link.repos url = '/'.join((self.link.url, path)) newurl = '/'.join((self.newurl, path)) token = self.get_token(path) prev_rev, start_empty = self.get_prev(path) if prev_rev is None: prev_pl = [] prev_contents = None elif not repos.paths_different(newurl, rev, url, prev_rev): contents.close() return else: prev_rev, prev_pl, prev_contents = repos.get_file(url, prev_rev) new_file = prev_contents is None if new_file: self.send(gen.tuple('add-file', gen.string(path), gen.string(parent_token), gen.string(token), '( )')) else: self.send(gen.tuple('open-file', gen.string(path), gen.string(parent_token), gen.string(token), gen.list(rev))) self.send(gen.tuple('apply-textdelta', gen.string(token), '( )')) diff_version = 0 if 'svndiff1' in self.link.client_caps: diff_version = 1 encoder = svndiff.Encoder(contents, prev_contents, version=diff_version) diff_chunk = encoder.get_chunk() count = 0 while diff_chunk is not None: count += 1 self.send(gen.tuple('textdelta-chunk', gen.string(token), gen.string(diff_chunk))) if count > 2: print "send chunk %d %d" % (count, len(diff_chunk)) diff_chunk = encoder.get_chunk() csum = encoder.get_md5() if prev_contents: prev_contents.close() contents.close() self.send(gen.tuple('textdelta-end', gen.string(token))) prev_props = {} for name, value in prev_pl: prev_props[name] = value for name, value in props: if name in prev_props: if prev_props[name] == value: del prev_props[name] continue del prev_props[name] self.send(gen.tuple('change-file-prop', gen.string(token), gen.string(name), gen.list(gen.string(value)))) for name in prev_props.keys(): self.send(gen.tuple('change-file-prop', gen.string(token), gen.string(name), gen.list())) self.send(gen.tuple('close-file', gen.string(token), gen.list(gen.string(csum))))
def update_dir(self, path, rev, want, props, contents, parent_token=None): repos = self.link.repos url = '/'.join((self.link.url, path)) newurl = '/'.join((self.newurl, path)) if '/' in want: want_head, want_tail = want.split('/', 1) else: want_head, want_tail = want, '' new_dir = True token = self.get_token(path) prev_rev, start_empty = self.get_prev(path) if prev_rev is None: new_dir = True elif not repos.paths_different(newurl, rev, url, prev_rev) \ and not self.get_prev_subpath_empty(path): return else: stat = repos.stat(url, prev_rev) new_dir = stat[0] is None if parent_token is None: self.send(gen.tuple('open-root', gen.list(rev), gen.string(token))) props = repos.get_props(url, rev) contents = contents[3] elif new_dir: self.send( gen.tuple('add-dir', gen.string(path), gen.string(parent_token), gen.string(token), '( )')) prev_rev = None else: self.send( gen.tuple('open-dir', gen.string(path), gen.string(parent_token), gen.string(token), gen.list(rev))) prev_props = {} if prev_rev is not None and not start_empty: for name, value in repos.get_props(url, prev_rev): prev_props[name] = value for name, value in props: if name in prev_props: if prev_props[name] == value: del prev_props[name] continue del prev_props[name] self.send( gen.tuple('change-dir-prop', gen.string(token), gen.string(name), gen.list(gen.string(value)))) for name in prev_props.keys(): self.send( gen.tuple('change-dir-prop', gen.string(token), gen.string(name), gen.list())) current_names = [] for name, kind, props, content in contents: if len(want_head) > 0 and want_head != name: continue current_names.append(name) entry_path = name if len(path) > 0: entry_path = '/'.join((path, name)) if kind == 'dir': self.update_dir(entry_path, rev, want_tail, props, content, token) elif kind == 'file': self.update_file(entry_path, rev, props, content, token) else: raise foo if prev_rev is not None and not start_empty: for entry in repos.ls(url, prev_rev, include_changed=False): name, kind, size, last_rev, last_author, last_date = entry if len(want_head) > 0 and want_head != name: continue if name not in current_names: entry_path = name if len(path) > 0: entry_path = '/'.join((path, name)) if entry_path in self.deleted_paths: continue self.send( gen.tuple('delete-entry', gen.string(entry_path), gen.list(prev_rev), gen.string(token))) self.send(gen.tuple('close-dir', gen.string(token)))
def update_file(self, path, rev, props, contents, parent_token): repos = self.link.repos url = '/'.join((self.link.url, path)) newurl = '/'.join((self.newurl, path)) token = self.get_token(path) prev_rev, start_empty = self.get_prev(path) if prev_rev is None: prev_pl = [] prev_contents = None elif not repos.paths_different(newurl, rev, url, prev_rev): contents.close() return else: prev_rev, prev_pl, prev_contents = repos.get_file(url, prev_rev) new_file = prev_contents is None if new_file: self.send( gen.tuple('add-file', gen.string(path), gen.string(parent_token), gen.string(token), '( )')) else: self.send( gen.tuple('open-file', gen.string(path), gen.string(parent_token), gen.string(token), gen.list(rev))) self.send(gen.tuple('apply-textdelta', gen.string(token), '( )')) diff_version = 0 if 'svndiff1' in self.link.client_caps: diff_version = 1 encoder = svndiff.Encoder(contents, prev_contents, version=diff_version) diff_chunk = encoder.get_chunk() count = 0 while diff_chunk is not None: count += 1 self.send( gen.tuple('textdelta-chunk', gen.string(token), gen.string(diff_chunk))) if count > 2: print "send chunk %d %d" % (count, len(diff_chunk)) diff_chunk = encoder.get_chunk() csum = encoder.get_md5() if prev_contents: prev_contents.close() contents.close() self.send(gen.tuple('textdelta-end', gen.string(token))) prev_props = {} for name, value in prev_pl: prev_props[name] = value for name, value in props: if name in prev_props: if prev_props[name] == value: del prev_props[name] continue del prev_props[name] self.send( gen.tuple('change-file-prop', gen.string(token), gen.string(name), gen.list(gen.string(value)))) for name in prev_props.keys(): self.send( gen.tuple('change-file-prop', gen.string(token), gen.string(name), gen.list())) self.send( gen.tuple('close-file', gen.string(token), gen.list(gen.string(csum))))