Mercurial > evolve
annotate hgext3rd/evolve/obshistory.py @ 2416:23c0bef0b5d4
obshistory: rename the command to "olog"
The command start to look good enough to be handed out to user. We replace the
old and useless "olog" alias in favor of the new command.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 18 May 2017 18:18:01 +0200 |
parents | 89a5dabbb43d |
children | 4993d1812311 |
rev | line source |
---|---|
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
1 # Code dedicated to display and exploration of the obsolescence history |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
2 # |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
3 # This module content aims at being upstreamed enventually. |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
4 # |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
5 # Copyright 2017 Octobus SAS <contact@octobus.net> |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
6 # |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
7 # This software may be used and distributed according to the terms of the |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
8 # GNU General Public License version 2 or any later version. |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
9 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
10 from mercurial import ( |
2407
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
11 cmdutil, |
2415
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
12 commands, |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
13 error, |
2407
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
14 graphmod, |
2415
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
15 node as nodemod, |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
16 scmutil, |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
17 ) |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
18 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
19 from mercurial.i18n import _ |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
20 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
21 from . import ( |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
22 exthelper, |
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
23 ) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
24 |
2415
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
25 eh = exthelper.exthelper() |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
26 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
27 @eh.command( |
2416
23c0bef0b5d4
obshistory: rename the command to "olog"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2415
diff
changeset
|
28 'olog', |
2415
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
29 [('G', 'graph', True, _("show the revision DAG")), |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
30 ('r', 'rev', [], _('show the specified revision or revset'), _('REV')) |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
31 ] + commands.formatteropts, |
2416
23c0bef0b5d4
obshistory: rename the command to "olog"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2415
diff
changeset
|
32 _('hg olog [OPTION]... [REV]')) |
2415
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
33 def cmdobshistory(ui, repo, *revs, **opts): |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
34 """show the obsolescence history of the specified revisions. |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
35 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
36 By default this command prints the selected revisions and all its |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
37 precursors. For precursors pointing on existing revisions in the repository, |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
38 it will display revisions node id, revision number and the first line of the |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
39 description. For precursors pointing on non existing revisions in the |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
40 repository (that can happen when exchanging obsolescence-markers), display |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
41 only the node id. |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
42 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
43 In both case, for each node, its obsolescence marker will be displayed with |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
44 the obsolescence operation (rewritten or pruned) in addition of the user and |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
45 date of the operation. |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
46 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
47 The output is a graph by default but can deactivated with the option '--no- |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
48 graph'. |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
49 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
50 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete, |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
51 and '+' represents a fork where the changeset from the lines below is a |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
52 parent of the 'o' merge on the same line. |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
53 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
54 Paths in the DAG are represented with '|', '/' and so forth. |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
55 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
56 Returns 0 on success. |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
57 """ |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
58 revs = list(revs) + opts['rev'] |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
59 if not revs: |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
60 revs = ['.'] |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
61 revs = scmutil.revrange(repo, revs) |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
62 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
63 if opts['graph']: |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
64 return _debugobshistorygraph(ui, repo, revs, opts) |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
65 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
66 fm = ui.formatter('debugobshistory', opts) |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
67 revs.reverse() |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
68 _debugobshistorysingle(fm, repo, revs) |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
69 |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
70 fm.end() |
89a5dabbb43d
obshistory: move the command into the obshistory module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2411
diff
changeset
|
71 |
2407
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
72 class obsmarker_printer(cmdutil.changeset_printer): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
73 """show (available) information about a node |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
74 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
75 We display the node, description (if available) and various information |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
76 about obsolescence markers affecting it""" |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
77 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
78 def show(self, ctx, copies=None, matchfn=None, **props): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
79 if self.buffered: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
80 self.ui.pushbuffer(labeled=True) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
81 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
82 changenode = ctx.node() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
83 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
84 fm = self.ui.formatter('debugobshistory', props) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
85 _debugobshistorydisplaynode(fm, self.repo, changenode) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
86 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
87 succs = self.repo.obsstore.successors.get(changenode, ()) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
88 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
89 markerfm = fm.nested("debugobshistory.markers") |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
90 for successor in sorted(succs): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
91 _debugobshistorydisplaymarker(markerfm, self.repo, successor) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
92 markerfm.end() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
93 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
94 markerfm.plain('\n') |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
95 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
96 self.hunk[ctx.node()] = self.ui.popbuffer() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
97 else: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
98 ### graph output is buffered only |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
99 msg = 'cannot be used outside of the graphlog (yet)' |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
100 raise error.ProgrammingError(msg) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
101 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
102 def flush(self, ctx): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
103 ''' changeset_printer has some logic around buffering data |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
104 in self.headers that we don't use |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
105 ''' |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
106 pass |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
107 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
108 class missingchangectx(object): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
109 ''' a minimal object mimicking changectx for change contexts |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
110 references by obs markers but not available locally ''' |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
111 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
112 def __init__(self, repo, nodeid): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
113 self._repo = repo |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
114 self._node = nodeid |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
115 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
116 def node(self): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
117 return self._node |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
118 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
119 def obsolete(self): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
120 # If we don't have it locally, it's obsolete |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
121 return True |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
122 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
123 def cyclic(graph): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
124 """Return True if the directed graph has a cycle. |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
125 The graph must be represented as a dictionary mapping vertices to |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
126 iterables of neighbouring vertices. For example: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
127 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
128 >>> cyclic({1: (2,), 2: (3,), 3: (1,)}) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
129 True |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
130 >>> cyclic({1: (2,), 2: (3,), 3: (4,)}) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
131 False |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
132 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
133 Taken from: https://codereview.stackexchange.com/a/86067 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
134 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
135 """ |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
136 visited = set() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
137 o = object() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
138 path = [o] |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
139 path_set = set(path) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
140 stack = [iter(graph)] |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
141 while stack: |
2411
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
142 for v in sorted(stack[-1]): |
2407
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
143 if v in path_set: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
144 path_set.remove(o) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
145 return path_set |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
146 elif v not in visited: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
147 visited.add(v) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
148 path.append(v) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
149 path_set.add(v) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
150 stack.append(iter(graph.get(v, ()))) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
151 break |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
152 else: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
153 path_set.remove(path.pop()) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
154 stack.pop() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
155 return False |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
156 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
157 def _obshistorywalker(repo, revs): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
158 """ Directly inspired by graphmod.dagwalker, |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
159 walk the obs marker tree and yield |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
160 (id, CHANGESET, ctx, [parentinfo]) tuples |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
161 """ |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
162 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
163 # Get the list of nodes and links between them |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
164 candidates, nodesucc, nodeprec = _obshistorywalker_links(repo, revs) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
165 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
166 # Shown, set of nodes presents in items |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
167 shown = set() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
168 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
169 def isvalidcandidate(candidate): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
170 """ Function to filter candidates, check the candidate succ are |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
171 in shown set |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
172 """ |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
173 return nodesucc.get(candidate, set()).issubset(shown) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
174 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
175 # While we have some nodes to show |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
176 while candidates: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
177 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
178 # Filter out candidates, returns only nodes with all their successors |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
179 # already shown |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
180 validcandidates = filter(isvalidcandidate, candidates) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
181 |
2411
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
182 # If we likely have a cycle |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
183 if not validcandidates: |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
184 cycle = cyclic(nodesucc) |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
185 assert cycle |
2407
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
186 |
2411
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
187 # Then choose a random node from the cycle |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
188 breaknode = sorted(cycle)[0] |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
189 # And display it by force |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
190 repo.ui.debug('obs-cycle detected, forcing display of %s\n' |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
191 % nodemod.short(breaknode)) |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
192 validcandidates = [breaknode] |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
193 |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
194 # Display all valid candidates |
2407
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
195 for cand in sorted(validcandidates): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
196 # Remove candidate from candidates set |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
197 candidates.remove(cand) |
2411
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
198 # And remove it from nodesucc in case of future cycle detected |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
199 try: |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
200 del nodesucc[cand] |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
201 except KeyError: |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
202 pass |
bd937b7ce7d2
debugobshistory: handle multiple cycles
Boris Feld <boris.feld@octobus.net>
parents:
2407
diff
changeset
|
203 |
2407
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
204 shown.add(cand) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
205 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
206 # Add the right changectx class |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
207 if cand in repo: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
208 changectx = repo[cand] |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
209 else: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
210 changectx = missingchangectx(repo, cand) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
211 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
212 childrens = [(graphmod.PARENT, x) for x in nodeprec.get(cand, ())] |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
213 yield (cand, 'M', changectx, childrens) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
214 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
215 def _obshistorywalker_links(repo, revs): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
216 """ Iterate the obs history tree starting from revs, traversing |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
217 each revision precursors recursively. |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
218 Return a tuple of: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
219 - The list of node crossed |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
220 - The dictionnary of each node successors, values are a set |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
221 - The dictionnary of each node precursors, values are a list |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
222 """ |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
223 precursors = repo.obsstore.precursors |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
224 nodec = repo.changelog.node |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
225 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
226 # Parents, set of parents nodes seen during walking the graph for node |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
227 nodesucc = dict() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
228 # Childrens |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
229 nodeprec = dict() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
230 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
231 nodes = [nodec(r) for r in revs] |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
232 seen = set(nodes) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
233 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
234 # Iterate on each node |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
235 while nodes: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
236 node = nodes.pop() |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
237 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
238 precs = precursors.get(node, ()) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
239 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
240 nodeprec[node] = [] |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
241 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
242 for prec in sorted(precs): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
243 precnode = prec[0] |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
244 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
245 # Mark node as prec successor |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
246 nodesucc.setdefault(precnode, set()).add(node) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
247 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
248 # Mark precnode as node precursor |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
249 nodeprec[node].append(precnode) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
250 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
251 # Add prec for future processing if not node already processed |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
252 if precnode not in seen: |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
253 seen.add(precnode) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
254 nodes.append(precnode) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
255 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
256 return sorted(seen), nodesucc, nodeprec |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
257 |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
258 def _debugobshistorygraph(ui, repo, revs, opts): |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
259 displayer = obsmarker_printer(ui, repo.unfiltered(), None, opts, buffered=True) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
260 edges = graphmod.asciiedges |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
261 cmdutil.displaygraph(ui, repo, _obshistorywalker(repo.unfiltered(), revs), displayer, edges) |
783a74c60a5e
obshistory: add a graph option on the debugobshistory command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2406
diff
changeset
|
262 |
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
263 def _debugobshistorysingle(fm, repo, revs): |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
264 """ Display the obsolescence history for a single revision |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
265 """ |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
266 precursors = repo.obsstore.precursors |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
267 successors = repo.obsstore.successors |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
268 nodec = repo.changelog.node |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
269 nodes = [nodec(r) for r in revs] |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
270 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
271 seen = set(nodes) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
272 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
273 while nodes: |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
274 ctxnode = nodes.pop() |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
275 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
276 _debugobshistorydisplaynode(fm, repo, ctxnode) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
277 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
278 succs = successors.get(ctxnode, ()) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
279 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
280 markerfm = fm.nested("debugobshistory.markers") |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
281 for successor in sorted(succs): |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
282 _debugobshistorydisplaymarker(markerfm, repo, successor) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
283 markerfm.end() |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
284 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
285 precs = precursors.get(ctxnode, ()) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
286 for p in sorted(precs): |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
287 # Only show nodes once |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
288 if p[0] not in seen: |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
289 seen.add(p[0]) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
290 nodes.append(p[0]) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
291 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
292 def _debugobshistorydisplaynode(fm, repo, node): |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
293 if node in repo.unfiltered(): |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
294 _debugobshistorydisplayctx(fm, repo.unfiltered()[node]) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
295 else: |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
296 _debugobshistorydisplaymissingctx(fm, node) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
297 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
298 def _debugobshistorydisplayctx(fm, ctx): |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
299 shortdescription = ctx.description().splitlines()[0] |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
300 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
301 fm.startitem() |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
302 fm.write('debugobshistory.node', '%s', str(ctx), |
2404
c07f752137f4
label: rename 'evolve.short_node' to 'evolve.node'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2403
diff
changeset
|
303 label="evolve.node") |
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
304 fm.plain(' ') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
305 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
306 fm.write('debugobshistory.rev', '(%d)', int(ctx), |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
307 label="evolve.rev") |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
308 fm.plain(' ') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
309 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
310 fm.write('debugobshistory.shortdescription', '%s', shortdescription, |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
311 label="evolve.short_description") |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
312 fm.plain('\n') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
313 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
314 def _debugobshistorydisplaymissingctx(fm, nodewithoutctx): |
2406
31255706b591
obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2404
diff
changeset
|
315 hexnode = nodemod.short(nodewithoutctx) |
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
316 fm.startitem() |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
317 fm.write('debugobshistory.node', '%s', hexnode, |
2404
c07f752137f4
label: rename 'evolve.short_node' to 'evolve.node'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2403
diff
changeset
|
318 label="evolve.node evolve.missing_change_ctx") |
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
319 fm.plain('\n') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
320 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
321 def _debugobshistorydisplaymarker(fm, repo, marker): |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
322 succnodes = marker[1] |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
323 date = marker[4] |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
324 metadata = dict(marker[3]) |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
325 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
326 fm.startitem() |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
327 fm.plain(' ') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
328 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
329 # Detect pruned revisions |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
330 if len(succnodes) == 0: |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
331 verb = 'pruned' |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
332 else: |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
333 verb = 'rewritten' |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
334 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
335 fm.write('debugobshistory.verb', '%s', verb, |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
336 label="evolve.verb") |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
337 fm.plain(' by ') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
338 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
339 fm.write('debugobshistory.marker_user', '%s', metadata['user'], |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
340 label="evolve.user") |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
341 fm.plain(' ') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
342 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
343 fm.write('debugobshistory.marker_date', '(%s)', fm.formatdate(date), |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
344 label="evolve.date") |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
345 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
346 if len(succnodes) > 0: |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
347 fm.plain(' as ') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
348 |
2406
31255706b591
obshistory: import 'node' as 'nodemod'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2404
diff
changeset
|
349 shortsnodes = (nodemod.short(succnode) for succnode in sorted(succnodes)) |
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
350 nodes = fm.formatlist(shortsnodes, 'debugobshistory.succnodes', sep=', ') |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
351 fm.write('debugobshistory.succnodes', '%s', nodes, |
2404
c07f752137f4
label: rename 'evolve.short_node' to 'evolve.node'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2403
diff
changeset
|
352 label="evolve.node") |
2403
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
353 |
1b348702d79e
obshistory: refactor debugobshistory
Boris Feld <boris.feld@octobus.net>
parents:
diff
changeset
|
354 fm.plain("\n") |