RFE: permalink to submissions using list-id/message-id (GH issue 106)

Message ID 20180801190454.GA14991@chatter
State New
Headers show
Series
  • RFE: permalink to submissions using list-id/message-id (GH issue 106)
Related show

Commit Message

Konstantin Ryabitsev Aug. 1, 2018, 7:04 p.m.
Hi, all:

I'm largely duplicating what I wrote in the GitHub issue 106 
(https://github.com/getpatchwork/patchwork/issues/106) just to reiterate 
a personal plea. :)

One of the side-effects of moving the LKML project to a dedicated 
instance was the fact that I discovered just how many people were using 
patchwork.kernel.org links in various places. Arguably, this is the 
wrong way to use patchwork, since it's supposed to remain entirely 
behind the scenes, but this is obviously a losing battle, considering 
how many hits the following query returns:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/?qt=grep&q=patchwork.kernel.org

Android and ChromiumOS folks are also using it:

https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/1092792

Since all patches have different IDs on the new instance 
(lore.kernel.org/patchwork), all these URLs were now broken. I fixed 
this for the moment by creating a simple dict matching of oldid -> newid 
mapped using the message-id of each submission, and added the following 
nasty hack to the running code:



This does the job for the moment, though I probably shouldn't be keeping 
the mapping dict in RAM at all times, even if it *is* just a bunch of 
ints.

Anyway, my request is that, since people can't be convinced to stop 
using patchwork links, that we provide them with a convenient way to 
obtain permalinks in a format that doesn't rely on patch-id. I suggest:

sitename/p/list-id/message-id

e.g.:

patchwork.kernel.org/p/linux-kernel.vger.kernel.org/20170619152033.893467280@linuxfoundation.org

Perhaps add a [permalink] button to the same row currently showing 
[patch-id | diff | mbox | series ].

This should contain all the necessary info for patchwork to rewrite this 
into a patch view. If the list-id changes, as they sometimes do, the 
site administrator can easily add a one-line rewrite rule that would 
preserve link validity.

This has two added benefits over the status quo:

1. Moving projects between databases becomes possible
2. More importantly, this allows future code historians to still be able 
to get context about a commit even if the patchwork service is no longer 
operating. If they can see both the list-id and the message-id, that 
should give them enough information to locate the conversation in 
mailing list archives.

-K

Patch

diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py
index eccb544..242da7b 100644
--- a/patchwork/views/patch.py
+++ b/patchwork/views/patch.py
@@ -37,6 +37,13 @@  from patchwork.views import generic_list
 from patchwork.views.utils import patch_to_mbox
 from patchwork.views.utils import series_patch_to_mbox

+try:
+    with open('/opt/patchwork/idmap.pickle', 'rb') as idp:
+        import pickle
+        lkml_idmap = pickle.load(idp)
+        idp.close()
+except:
+    lkml_idmap = {}

 def patch_list(request, project_id):
     project = get_object_or_404(Project, linkname=project_id)
@@ -58,6 +65,9 @@  def patch_detail(request, patch_id):
         if submissions:
             return HttpResponseRedirect(
                 reverse('cover-detail', kwargs={'cover_id': patch_id}))
+        elif int(patch_id) in lkml_idmap:
+            newurl = 'https://lore.kernel.org/patchwork/patch/%s/' % lkml_idmap[int(patch_id)]
+            return HttpResponseRedirect(newurl)
         raise exc

     editable = patch.is_editable(request.user)