예제 #1
0
 def handle_request(self, repo, path):
     ref, path, tree, _ = self.split_ref(repo, path)
     if ref not in repo:
         ref = repo.lookup_reference('refs/heads/%s' % ref).hex
     if hasattr(repo[ref], 'target'):
         ref = repo[repo[ref].target].hex
     cfile = os.path.join(repo.cpath, 'dirlog_%s_%s.json' % (ref, path.replace('/', '_')))
     if not os.path.exists(cfile):
         tree = repo[ref].tree
         for elt in path.split('/'):
             if elt:
                 tree = repo[tree[elt].hex]
         lastchanged = repo.tree_lastchanged(repo[ref], path)
         commits = {}
         for commit in set(lastchanged.values()):
             commit = repo[commit]
             commits[commit.hex] = [commit.commit_time, escape(shortmsg(commit.message))]
         for file in lastchanged:
             lastchanged[file] = (lastchanged[file], tree[file].hex[:7])
         ret = {'files': lastchanged, 'commits': commits}
         with open(cfile, 'w') as fd:
             json.dump(ret, fd)
     if 'wsgi.version' in request.environ and request.environ['SERVER_PORT'] != '5000':
         # Redirect to the file, let the webserver deal with it
         return redirect(cfile.replace(current_app.config['REPO_ROOT'], ''))
     else:
         return send_file(cfile)
예제 #2
0
 def handle_request(self, repo, path):
     ref, path, tree, _ = self.split_ref(repo, path)
     if ref not in repo:
         ref = repo.lookup_reference('refs/heads/%s' % ref).hex
     if hasattr(repo[ref], 'target'):
         ref = repo[repo[ref].target].hex
     cfile = os.path.join(
         repo.cpath, 'dirlog_%s_%s.json' % (ref, path.replace('/', '_')))
     if not os.path.exists(cfile):
         tree = repo[ref].tree
         for elt in path.split('/'):
             if elt:
                 tree = repo[tree[elt].hex]
         lastchanged = repo.tree_lastchanged(repo[ref], path)
         commits = {}
         for commit in set(lastchanged.values()):
             commit = repo[commit]
             commits[commit.hex] = [
                 commit.commit_time,
                 escape(shortmsg(commit.message))
             ]
         for file in lastchanged:
             lastchanged[file] = (lastchanged[file], tree[file].hex[:7])
         ret = {'files': lastchanged, 'commits': commits}
         with open(cfile, 'w') as fd:
             json.dump(ret, fd)
     if 'wsgi.version' in request.environ and request.environ[
             'SERVER_PORT'] != '5000':
         # Redirect to the file, let the webserver deal with it
         return redirect(cfile.replace(current_app.config['REPO_ROOT'], ''))
     else:
         return send_file(cfile)
예제 #3
0
 def handle_request(self, repo, path):
     ref, path, tree, _ = self.split_ref(repo, path)
     try:
         if ref not in repo:
             ref = repo.lookup_reference('refs/heads/%s' % ref).target.hex
     except ValueError:
         ref = repo.lookup_reference('refs/heads/%s' % ref).target.hex
     if hasattr(repo[ref], 'target'):
         ref = repo[repo[ref].target].hex
     cache_dir = os.path.join(current_app.config['CACHE_ROOT'], 'dirlog')
     if not os.path.exists(cache_dir):
         os.makedirs(cache_dir)
     cfile = os.path.join(cache_dir, 'dirlog_%s_%s.json' % (ref, path.replace('/', '_')))
     if not os.path.exists(cfile):
         tree = repo[ref].tree
         for elt in path.split('/'):
             if elt:
                 tree = repo[tree[elt].hex]
         lastchanged = repo.tree_lastchanged(repo[ref], path)
         commits = {}
         for commit in set(lastchanged.values()):
             commit = repo[commit]
             commits[commit.hex] = [commit.commit_time, escape(shortmsg(commit.message))]
         for file in lastchanged:
             lastchanged[file] = (lastchanged[file], tree[file].hex[:7])
         ret = {'files': lastchanged, 'commits': commits}
         with open(cfile, 'w') as fd:
             json.dump(ret, fd)
     return send_file(cfile)
예제 #4
0
 def handle_request(self, repo, path):
     ref, path, tree, _ = self.split_ref(repo, path)
     if ref not in repo:
         ref = repo.lookup_reference("refs/heads/%s" % ref).hex
     lastchanged = repo.tree_lastchanged(repo[ref], path and path.split("/") or [])
     ret = {}
     for file, data in lastchanged.iteritems():
         ret[file] = [
             data["hex"][:7],
             humantime(data["commit"].commit_time),
             data["commit"].hex,
             escape(shortmsg(data["commit"].message)),
         ]
     return json.dumps(ret), 200, {"Content-Type": "application/json"}