~sircmpwn/sr.ht-dev

3 2

[PATCH 1 of 3 hg.sr.ht] Extend raw commit object before rendering in commit() view

Details
Message ID
<7d75ba8c5f164acb0e2e.1569080469@marimba>
DKIM signature
missing
Download raw message
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1569077044 -7200
#      sam. sept. 21 16:44:04 2019 +0200
# Node ID 7d75ba8c5f164acb0e2e61fa7db6951809950f9b
# Parent  a0b942f18d3b893d214c2880c1453864389bb800
Extend raw commit object before rendering in commit() view

By calling get_rev_view_data() on the revision object retrieved from
Mercurial repository, we get extra attributes (like short_id, long_id,
refs, etc.) which are expected upon rendering in commit_event macro in
scmsrht/templates/macros/scmutils.py).

Noticeably, the commit id now appears in "/<owner>/<repo>/rev/<rev>"
view (before author name), eventual tags appears after author name, etc.

diff --git a/hgsrht/blueprints/repo.py b/hgsrht/blueprints/repo.py
index a193494..df7614f 100644
--- a/hgsrht/blueprints/repo.py
+++ b/hgsrht/blueprints/repo.py
@@ -515,6 +515,7 @@ def commit(owner, repo, rev):
                 "error-invalid-ref.html", view="log",
                 owner=owner, repo=repo, error=exc.err.decode())
 
+        commit = get_rev_view_data(commit, owner, repo)
         key = "hg.sr.ht:hg:commit:{}:{}:{}:v1".format(
             owner.username, repo.name, commit.node)
         diff_json = redis.get(key)

[PATCH 2 of 3 hg.sr.ht] Retrieve phase and obsolescence info in lookup_rev()

Details
Message ID
<51d51bc6d72734a0ea32.1569080470@marimba>
In-Reply-To
<7d75ba8c5f164acb0e2e.1569080469@marimba> (view parent)
DKIM signature
missing
Download raw message
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1569080432 -7200
#      sam. sept. 21 17:40:32 2019 +0200
# Node ID 51d51bc6d72734a0ea32d599672c62b490bbde31
# Parent  7d75ba8c5f164acb0e2e61fa7db6951809950f9b
Retrieve phase and obsolescence info in lookup_rev()

We now use log2() method which fetches extra information about phase and
obsolescence for given revision in lookup_rev(). This makes these pieces
of information displayed in "/<owner>/<repo>/rev/<rev>" view.

diff --git a/hgsrht/blueprints/repo.py b/hgsrht/blueprints/repo.py
index df7614f..c55c27b 100644
--- a/hgsrht/blueprints/repo.py
+++ b/hgsrht/blueprints/repo.py
@@ -7,7 +7,7 @@ import os.path
 import re
 from flask import Blueprint, Response, render_template, abort, request
 from flask import redirect, url_for, send_file
-from hgsrht.hg import HgRepository, HgCommandError, HgServerError, torev2
+from hgsrht.hg import HgRepository, HgCommandError, HgServerError
 from hgsrht.types import User, Repository, Redirect
 from io import BytesIO
 from jinja2 import Markup
@@ -47,13 +47,13 @@ def get_readme(hg_repo, root_dir, change
 
 def lookup_rev(hg_repo, rev, none_on_error=True):
     try:
-        commits = hg_repo.client.log(revrange=rev)
+        revs = hg_repo.log2(revrange=rev)
     except HgCommandError:
         if none_on_error:
             return None
         raise
-    if commits:
-        return torev2(commits[0])
+    if revs:
+        return revs[0]
     return None
 
 def lookup_default_rev(hg_repo):

[PATCH 3 of 3 hg.sr.ht] Drop torev2() function

Details
Message ID
<9fa009e2d856beca58af.1569080471@marimba>
In-Reply-To
<7d75ba8c5f164acb0e2e.1569080469@marimba> (view parent)
DKIM signature
missing
Download raw message
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1569079048 -7200
#      sam. sept. 21 17:17:28 2019 +0200
# Node ID 9fa009e2d856beca58af204009b88b35c5ba2b30
# Parent  51d51bc6d72734a0ea32d599672c62b490bbde31
Drop torev2() function

From previous changeset, it is now unused. (The import in extramanage.py
was already unused.)

diff --git a/hgsrht/blueprints/extramanage.py b/hgsrht/blueprints/extramanage.py
index caeac3f..b50f16c 100644
--- a/hgsrht/blueprints/extramanage.py
+++ b/hgsrht/blueprints/extramanage.py
@@ -1,6 +1,6 @@
 from flask import Blueprint, Response, render_template, abort, request
 from flask import redirect, url_for
-from hgsrht.hg import HgRepository, HgCommandError, torev2
+from hgsrht.hg import HgRepository, HgCommandError
 from hgsrht.repos import generate_and_write_hgrc
 from hgsrht.types import User, Repository, Redirect
 from scmsrht.access import get_repo_or_redir
diff --git a/hgsrht/hg.py b/hgsrht/hg.py
index 02a46d6..45c500c 100644
--- a/hgsrht/hg.py
+++ b/hgsrht/hg.py
@@ -81,16 +81,6 @@ def split_author(author):
         return m.group('name'), m.group('email')
     return author, None
 
-def torev2(revs):
-    if isinstance(revs, revision):
-        return revision2.from_rev(revs)
-    if isinstance(revs, list):
-        return [revision2.from_rev(r) for r in revs]
-    if isinstance(revs, tuple):
-        return (revision2.from_rev(r) for r in revs)
-    if isinstance(revs, set):
-        return {revision2.from_rev(r) for r in revs}
-
 class revision2:
     def __init__(self, vals):
         """ `vals` should be a tuple of: revnum, node, tags, branch, author,
Details
Message ID
<8037f559-7059-4845-92f4-248f2b067674@www.fastmail.com>
In-Reply-To
<7d75ba8c5f164acb0e2e.1569080469@marimba> (view parent)
DKIM signature
pass
Download raw message
All 3 patches look good, I pushed them upstream. They will be deployed
with the next release. Thanks!