# HG changeset patch # User Anton Shestakov # Date 1545807127 -28800 # Node ID 0f015fe4f71f1f4fe36e9af600291ced8f8104e3 # Parent e2350851740a1336a5a7aad103bc22b5edb1c049 topic: make revsets like 'foo#topic[0]' work Essentially, 'topic' relation subscript function is the same as 'generations', but is limited to revisions marked with one particular topic. diff -r e2350851740a -r 0f015fe4f71f CHANGELOG --- a/CHANGELOG Thu Jan 10 17:30:01 2019 +0100 +++ b/CHANGELOG Wed Dec 26 14:52:07 2018 +0800 @@ -17,6 +17,7 @@ * stack: introduce a --children flag (see help for details) * topic: make --age compatible with the usual other display for `hg topic` * stack: support for '#stack[idx]' absolute indexing in revset (4.9+ only) + * topic: support for '#topic[idx]' relative indexing in revset (4.9+ only) 8.3.3 -- 2017-12-24 ------------------- diff -r e2350851740a -r 0f015fe4f71f hgext3rd/topic/revset.py --- a/hgext3rd/topic/revset.py Thu Jan 10 17:30:01 2019 +0100 +++ b/hgext3rd/topic/revset.py Wed Dec 26 14:52:07 2018 +0800 @@ -142,3 +142,16 @@ revset.subscriptrelations['stack'] = stackrel revset.subscriptrelations['s'] = stackrel + + def topicrel(repo, subset, x, rel, n, order): + ancestors = revset._ancestors + descendants = revset._descendants + subset = topicset(repo, subset, x) + if n <= 0: + n = -n + return ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1) + else: + return descendants(repo, subset, x, startdepth=n, stopdepth=n + 1) + + revset.subscriptrelations['topic'] = topicrel + revset.subscriptrelations['t'] = topicrel diff -r e2350851740a -r 0f015fe4f71f tests/test-topic.t --- a/tests/test-topic.t Thu Jan 10 17:30:01 2019 +0100 +++ b/tests/test-topic.t Wed Dec 26 14:52:07 2018 +0800 @@ -823,8 +823,8 @@ $ cd .. -Stack relation subscript in revsets -=================================== +Relation subscript in revsets +============================= $ hg init more-than-one-commit-per-topic $ cd more-than-one-commit-per-topic @@ -854,6 +854,24 @@ 3: featureA 4: +topic subscript relation + + $ tlog 'featureA' + 3: featureA + $ tlog 'featureA#topic[0]' + 3: featureA + + $ tlog '2#t[-2]' + $ tlog '2#t[-1]' + 1: featureA + $ tlog '2#t[0]' + 2: featureA + $ tlog '2#t[1]' + 3: featureA + $ tlog '2#t[2]' + +stack subscript relation + $ hg stack ### target: default (branch) s2@ 4 (current)