From 7cd9cc0176c8019d948ee2446034bf17846a83bc Mon Sep 17 00:00:00 2001
From: Jordan Lee <jordan@transmissionbt.com>
Date: Mon, 16 May 2011 02:09:31 +0000
Subject: [PATCH] (trunk libT) #4237 "tarnsmission-remote -l shows torrent list
 in reverse order" -- revert r12424 to fix this

---
 libtransmission/torrent.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c
index 825c6e92f..633a82360 100644
--- a/libtransmission/torrent.c
+++ b/libtransmission/torrent.c
@@ -869,9 +869,18 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor )
     }
 
     /* add the torrent to tr_session.torrentList */
-    tor->next = session->torrentList;
-    session->torrentList = tor;
-    ++session->torrentCount;
+    {
+        tr_torrent * it = NULL;
+        tr_torrent * last = NULL;
+        while(( it = tr_torrentNext( session, it )))
+            last = it;
+
+        if( !last )
+            session->torrentList = tor;
+        else
+            last->next = tor;
+        ++session->torrentCount;
+    }
 
     /* if we don't have a local .torrent file already, assume the torrent is new */
     isNewTorrent = stat( tor->info.torrent, &st );
-- 
2.40.0