This instance will be upgraded to Heptapod 0.21.0rc2 on 2021-04-16 at 11:00 UTC+2 (a few minutes of down time)

graph_test.py 33.1 KB
Newer Older
1 2 3
import os
from nose.tools import *

4 5 6 7
from mercurial import (
    pycompat,
)

8
from tortoisehg.hgqt import graph, thgrepo
9
from tortoisehg.util import hglib
10 11 12

import helpers

13
def setup_module():
14 15 16
    global _tmpdir
    _tmpdir = helpers.mktmpdir(__name__)

17 18 19
    setup_namedbranch()
    setup_20nodes()
    setup_20patches()
20
    setup_nestedbranch()
21
    setup_straightenedbyrevset()
22
    setup_bulkgraft()
23
    setup_commonedge()
24
    setup_manyheads()
25
    setup_obsolete()
26
    setup_familyline()
27
    setup_movedfile()
28

29
def openrepo(name):
30
    return thgrepo.repository(hglib.loadui(), os.path.join(_tmpdir, name))
31

32 33 34 35
def buildrepo(name, graphtext):
    path = os.path.join(_tmpdir, name)
    helpers.buildgraph(path, graphtext)

36 37
def buildlinetable(grapher, predicate):
    table = {}  # rev: [predicate(edge), ...
38 39 40
    for node in grapher:
        if not node:
            continue
41
        # draw overlapped lines in the same way as HgRepoListModel
42
        lt = dict((p, predicate(p, e)) for p, e
43
                  in sorted(node.bottomlines, key=lambda pe: pe[1].importance))
44
        # and sort them in (start, end) order
45
        lines = [l for p, l in sorted(lt.items(), key=lambda pl: pl[0])]
46
        table[node.rev] = lines
47 48
    return table

49 50 51
def buildlinecolortable(grapher):
    return buildlinetable(grapher, lambda p, e: e.color)

52 53 54
def buildlinecolumntable(grapher):
    linktypetags = {
        graph.LINE_TYPE_PARENT: '',
55
        graph.LINE_TYPE_FAMILY: 'F',
56 57 58 59 60 61 62
        graph.LINE_TYPE_GRAFT: 'G',
        graph.LINE_TYPE_OBSOLETE: 'O',
    }
    def predicate(p, e):
        return '%d-%d%s' % (p[0], p[1], linktypetags[e.linktype])
    return buildlinetable(grapher, predicate)

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
def setup_namedbranch():
    buildrepo('named-branch', r"""
        8
        |\  7 [files=data]
        | 6 | [merge=local]
        |/| |
        | 5 | [files=data]
        | 4 | [files=data]
        | | 3 [files=data]
        2 |/ [branch=bar files=data]
        | 1 [files=data]
        |/
        0 [files=data]
    """)

78 79
def test_linecolor_unfiltered():
    repo = openrepo('named-branch')
80
    grapher = graph.revision_grapher(repo, {})
81
    c0, c1, c2 = 0, 1, 2
82 83
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
84
                              # wt
85
        None: [c0],           # |
86
                              # 8
87
        8: [c0, c1],          # |\
88
                              # | | 7
89
        7: [c0, c1, c2],      # | | |
90
                              # | 6 |
91
        6: [c0, c0, c1, c2],  # |/| |
92
                              # | 5 |
93
        5: [c0, c1, c2],      # | | |
94
                              # | 4 |
95
        4: [c0, c1, c2],      # | | |
96
                              # | | 3
97
        3: [c0, c1, c2],      # | |/
98
                              # 2 |
99
        2: [c0, c1],          # | |
100
                              # | 1
101
        1: [c0, c1],          # |/
102
                              # 0
103 104 105 106 107 108
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_linecolor_branchfiltered():
    repo = openrepo('named-branch')
109
    grapher = graph.revision_grapher(repo, {'branch': 'default'})
110
    c0, c1 = 0, 1
111 112
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
113
                      # 7
114
        7: [c0],      # |
115
                      # | 6
116
        6: [c0, c1],  # | |
117
                      # | 5
118
        5: [c0, c1],  # | |
119
                      # | 4
120
        4: [c0, c1],  # | |
121
                      # 3 |
122
        3: [c0, c1],  # |/
123
                      # 1
124
        1: [c0],      # |
125
                      # 0
126 127 128 129 130 131 132
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_linecolor_filelog():
    repo = openrepo('named-branch')
    grapher = graph.filelog_grapher(repo, 'data')
133
    c0, c1, c2 = 0, 1, 2
134 135
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
136
                          # 7
137
        7: [c0],          # |
138 139 140 141 142 143
                          # | 6
        6: [c0, c1, c2],  # | |\
                          # | 5 |
        5: [c0, c1, c2],  # | | |
                          # | 4 |
        4: [c0, c1, c2],  # | | |
144
                          # 3 | |
145 146 147 148 149
        3: [c0, c1, c2],  # |/ /
                          # | 2
        2: [c0, c2],      # | |
                          # 1 |
        1: [c0, c2],      # |/
150
                          # 0
151 152 153
        0: [],
        }
    assert_equal(expectedtable, actualtable)
154

155 156 157 158 159 160
def setup_20nodes():
    # Graph.index fetches 10 nodes by default
    hg = helpers.HgClient(os.path.join(_tmpdir, '20nodes'))
    hg.init()
    hg.ftouch('data')
    hg.add('data')
161
    for i in pycompat.xrange(20):
162 163
        hg.fappend('data', '%d\n' % i)
        hg.commit('-m', str(i))
164 165 166

def test_graph_index():
    repo = openrepo('20nodes')
167
    grapher = graph.revision_grapher(repo, {})
168 169 170 171 172 173 174
    graphobj = graph.Graph(repo, grapher)
    assert_equal(0, len(graphobj))
    assert_equal(0, graphobj.index(None))  # working dir
    assert_equal(1, graphobj.index(19))
    assert_equal(20, graphobj.index(0))
    assert_equal(21, len(graphobj))

175
    assert_raises(ValueError, lambda: graphobj.index(20))  # unknown
176

177 178 179 180 181 182 183 184 185 186 187 188
def test_graph_build_0node():
    repo = openrepo('20nodes')
    graphobj = graph.Graph(repo, graph.revision_grapher(repo, {}))
    graphobj.build_nodes(0)
    assert_equal(0, len(graphobj))

def test_graph_build_1node():
    repo = openrepo('20nodes')
    graphobj = graph.Graph(repo, graph.revision_grapher(repo, {}))
    graphobj.build_nodes(1)
    assert_equal(1, len(graphobj))  # [wdir]

189 190 191 192 193 194
def test_graph_build_nodes_up_to_rev():
    repo = openrepo('20nodes')
    graphobj = graph.Graph(repo, graph.revision_grapher(repo, {}))
    graphobj.build_nodes(rev=19)
    assert_equal(2, len(graphobj))  # [wdir, 19]

195 196 197
    graphobj.build_nodes(rev=19)
    assert_equal(2, len(graphobj))

198 199 200 201 202 203
def test_graph_build_nodes_up_to_rev_plus0():
    repo = openrepo('20nodes')
    graphobj = graph.Graph(repo, graph.revision_grapher(repo, {}))
    graphobj.build_nodes(0, 19)
    assert_equal(2, len(graphobj))  # [wdir, 19]

204 205 206
    graphobj.build_nodes(0, 19)
    assert_equal(2, len(graphobj))

207 208 209 210 211 212
def test_graph_build_nodes_up_to_rev_plus1():
    repo = openrepo('20nodes')
    graphobj = graph.Graph(repo, graph.revision_grapher(repo, {}))
    graphobj.build_nodes(1, 19)
    assert_equal(3, len(graphobj))  # [wdir, 19, 18]

213 214 215
    graphobj.build_nodes(1, 18)
    assert_equal(4, len(graphobj))  # [wdir, 19, 18, 17]

216 217 218 219 220 221 222
def setup_20patches():
    hg = helpers.HgClient(os.path.join(_tmpdir, '20patches'))
    hg.init()
    hg.fappend('data', '0\n')
    hg.commit('-Am', '0')
    hg.fappend('data', '1\n')
    hg.commit('-Am', '1')
223
    for i in pycompat.xrange(20):
224 225 226
        hg.qnew('%d.diff' % i)
    hg.qpop('-a')

227
def test_graph_index_unapplied_patches():
228
    repo = openrepo('20patches')
229
    grapher = graph.revision_grapher(repo, {})
230 231
    graphobj = graph.GraphWithMq(graph.Graph(repo, grapher),
                                 repo.thgmqunappliedpatches)
232
    assert_equal(20, len(graphobj))  # unapplied-patch nodes are preloaded
233 234 235 236 237 238
    assert_equal(0, graphobj.index('19.diff'))
    assert_equal(19, graphobj.index('0.diff'))
    assert_equal(20, graphobj.index(None))  # working dir
    assert_equal(21, graphobj.index(1))
    assert_equal(22, graphobj.index(0))
    assert_equal(23, len(graphobj))
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

def setup_nestedbranch():
    buildrepo('nested-branch', r"""
        9
        |\
        | 8 [files=data]
        | 7
        6 |\  [files=data]
        | | 5 [files=data]
        | 4 | [files=data]
        | | 3 [files=data]
        | |/
        2 | [files=data]
        | 1 [files=data]
        |/
        0 [files=data]
    """)

def test_linecolor_nestedbranch():
    repo = openrepo('nested-branch')
    grapher = graph.revision_grapher(repo, {})
    c0, c1, c2 = 0, 1, 2
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
                              # wt
        None: [c0],           # |
                              # 9
        9: [c0, c1],          # |\
                              # | 8
        8: [c0, c1],          # | |
                              # | 7
        7: [c0, c1, c2],      # | |\
                              # 6 | |
        6: [c0, c1, c2],      # | | |
                              # | | 5
        5: [c0, c1, c2],      # | | |
                              # | 4 |
        4: [c0, c1, c2],      # | | |
                              # | | 3
278
        3: [c0, c1, c2],      # | |/
279
                              # 2 |
280
        2: [c0, c1],          # | |
281
                              # | 1
282
        1: [c0, c1],          # |/
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
                              # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_linecolor_filelog_nestedbranch():
    repo = openrepo('nested-branch')
    grapher = graph.filelog_grapher(repo, 'data')
    c0, c1, c2 = 0, 1, 2
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
                              # 9
        9: [c0, c1],          # |\
                              # | 8
        8: [c0, c1],          # | |
                              # | 7
        7: [c0, c1, c2],      # | |\
                              # 6 | |
        6: [c0, c1, c2],      # | | |
                              # | | 5
        5: [c0, c1, c2],      # | | |
                              # | 4 |
        4: [c0, c1, c2],      # | | |
                              # | | 3
307
        3: [c0, c1, c2],      # | |/
308
                              # 2 |
309
        2: [c0, c1],          # | |
310
                              # | 1
311
        1: [c0, c1],          # |/
312 313 314 315 316
                              # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
def setup_straightenedbyrevset():
    buildrepo('straightened-by-revset', r"""
        7
        6
        |\
        5 |
        | 4
        3 |
        | 2
        |/
        1
        0
    """)

def test_linecolor_straightened_by_revset():
    repo = openrepo('straightened-by-revset')
333
    revset = {0, 1, 2, 4, 6, 7}  # exclude 3, 5
334
    grapher = graph.revision_grapher(repo, {"revset": revset})
335
    c0, c1 = 0, 1
336 337 338 339 340
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
                              # 7
        7: [c0],              # |
                              # 6
341
        6: [c1],              #  \
342
                              #   4
343
        4: [c1],              #   |
344
                              #   2
345
        2: [c1],              #  /
346 347 348 349 350 351 352 353 354
                              # 1
        1: [c0],              # |
                              # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_linecolor_straightened_by_revset_2():
    repo = openrepo('straightened-by-revset')
355
    revset = {0, 1, 2, 3, 4, 6, 7}  # exclude 5
356
    grapher = graph.revision_grapher(repo, {"revset": revset})
357
    c0, c1 = 0, 1
358 359 360 361 362
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
                              # 7
        7: [c0],              # |
                              # 6
363
        6: [c1],              # |
364
                              # 4
365
        4: [c1],              # |
366
                              # | 3
367
        3: [c1, c0],          # | |
368
                              # 2 |
369
        2: [c1, c0],          # |/
370 371 372 373 374 375 376 377 378
                              # 1
        1: [c0],              # |
                              # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_linecolor_straightened_by_revset_3():
    repo = openrepo('straightened-by-revset')
379
    revset = {0, 1, 2, 3, 6, 7}  # exclude 4, 5
380
    grapher = graph.revision_grapher(repo, {"revset": revset})
381
    c0, c1 = 0, 1
382 383 384 385 386 387 388 389 390
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
                              # 7
        7: [c0],              # |
                              # 6
        6: [],                #
                              # 3
        3: [c0],              # |
                              # | 2
391
        2: [c0, c1],          # |/
392 393 394 395 396 397 398 399 400
                              # 1
        1: [c0],              # |
                              # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_linecolor_straightened_by_revset_4():
    repo = openrepo('straightened-by-revset')
401
    revset = {0, 1, 3, 4, 6, 7}  # exclude 2, 5
402
    grapher = graph.revision_grapher(repo, {"revset": revset})
403
    c0, c1 = 0, 1
404 405 406 407 408
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
                              # 7
        7: [c0],              # |
                              # 6
409
        6: [c1],              #  \
410 411 412 413 414 415 416 417 418 419
                              #   4
        4: [],                #
                              # 3
        3: [c0],              # |
                              # 1
        1: [c0],              # |
                              # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)
420 421 422 423 424 425 426 427

def setup_bulkgraft():
    buildrepo('bulkgraft', r"""
    7 [source=3]
    6 [source=2]
    5 [source=1]
    4
    | 3
428
    | 2 [branch=foo]
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
    | 1
    |/
    0
    """)

def test_linecolor_bulkgraft():
    repo = openrepo('bulkgraft')
    grapher = graph.revision_grapher(repo, {"showgraftsource": True})
    c0, c1, c2, c3, c4 = 0, 1, 2, 3, 4
    actualtable = buildlinecolortable(grapher)
    expectedtable = {
                                # wt
        None: [c0],             # |
                                # 7
        7: [c0, c1],            # |\
                                # 6 .
        6: [c0, c2, c1],        # |\ \
                                # 5 . .
        5: [c0, c3, c2, c1],    # |\ \ \
                                # 4 : : :
        4: [c0, c3, c2, c1],    # | : : :
                                # | : : 3
        3: [c0, c3, c2, c4],    # | : :/
                                # | : 2
        2: [c0, c3, c4],        # | :/
                                # | 1
        1: [c0, c4],            # |/
                                # 0
        0: [],
    }
    assert_equal(expectedtable, actualtable)

461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
def setup_commonedge():
    buildrepo('commonedge', r"""
        6
        | 5
        |/
        | 4
        |/
        | 3
        | |
        | 2
        |/
        1
        |
        0
    """)

def test_linecolor_commonedge():
    repo = openrepo('commonedge')
    grapher = graph.revision_grapher(repo, {})
    c0, c1, c2, c3 = 0, 1, 2, 3
    actualtable = buildlinecolortable(grapher)
    expectedtable = {       # wt
        None: [c0],         # |
                            # 6
        6: [c0],            # |
                            # | 5
        5: [c0, c1],        # |/
                            # | 4
489
        4: [c0, c2],        # |/
490
                            # | 3
491
        3: [c0, c3],        # | |
492
                            # | 2
493
        2: [c0, c3],        # |/
494 495 496 497 498 499
                            # 1
        1: [c0],            # |
                            # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)
500 501 502

def setup_manyheads():
    buildrepo('manyheads', r"""
503 504 505
    8
    |\  7
    | | 6
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
    | |/
    | 5 [branch=foo]
    |/| 4 [branch=foo]
    3 |/
    | 2
    |/
    1
    0
    """)

def test_grapher_noopt():
    repo = openrepo('manyheads')
    grapher = graph.revision_grapher(repo, {})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                                        # wt
        None : ['0-0'],                 # |
523 524 525 526
                                        # 8
        8 : ['0-0', '0-1'],             # |\
                                        # | | 7
        7 : ['0-0', '1-1', '2-2'],      # | | |
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
                                        # | | 6
        6 : ['0-0', '1-1', '2-1'],      # | |/
                                        # | 5
        5 : ['0-0', '1-0', '1-1'],      # |/|
                                        # | | 4
        4 : ['0-0', '1-1', '2-1'],      # | |/
                                        # 3 |
        3 : ['0-0', '1-1'],             # | |
                                        # | 2
        2 : ['0-0', '1-0'],             # |/
                                        # 1
        1 : ['0-0'],                    # |
                                        # 0
        0 : [],
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_branch_1():
    repo = openrepo('manyheads')
    grapher = graph.revision_grapher(repo, {'branch': 'default'})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                                # wt
        None: ['0-0'],          # |
551 552
                                # 8
        8: ['0-0'],             # |
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
                                # 3
        3: ['0-0'],             # |
                                # | 2
        2: ['0-0', '1-0'],      # |/
                                # 1
        1: ['0-0'],             # |
                                # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_branch_2():
    repo = openrepo('manyheads')
    grapher = graph.revision_grapher(repo, {'branch': 'foo'})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
569 570
                        # 7
        7 :['0-0'],     # |
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
                        # 6
        6 :['0-0'],     # |
                        # 5
        5 :[],          #
                        # 4
        4 :[],          #
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_branch_allparents_1():
    repo = openrepo('manyheads')
    grapher = graph.revision_grapher(
            repo, {'branch': 'default', 'allparents': True})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                                     # wt
        None: ['0-0'],               # |
588 589
                                     # 8
        8: ['0-0', '0-1'],           # |\
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
                                     # | 5
        5: ['0-0', '1-0', '1-1'],    # |/|
                                     # 3 |
        3: ['0-0', '1-1'],           # | |
                                     # | 2
        2: ['0-0', '1-0'],           # |/
                                     # 1
        1: ['0-0'],                  # |
                                     # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_branch_allparents_2():
    repo = openrepo('manyheads')
    grapher = graph.revision_grapher(
            repo, {'branch': 'foo', 'allparents': True})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
609 610
                                     # 7
        7: ['0-0'],                  # |
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
                                     # 6
        6: ['0-0'],                  # |
                                     # 5
        5: ['0-0', '0-1'],           # |\
                                     # +---4
        4: ['0-0', '1-1', '2-0'],    # | |
                                     # | 3
        3: ['0-0', '1-1'],           # | |
                                     # 2 |
        2: ['0-0', '1-0'],           # |/
                                     # 1
        1: ['0-0'],                  # |
                                     # 0
        0: [],
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_revset_1():
    repo = openrepo('manyheads')
630
    revset = {8, 6, 5, 4, 3}
631 632 633
    grapher = graph.revision_grapher(repo, {'revset': revset})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
634 635
                                    # 8
        8: ['0-0', '0-1'],          # |\
636 637 638 639 640 641 642 643 644 645 646 647 648
                                    # | | 6
        6: ['0-0', '1-1', '2-1'],   # | |/
                                    # | 5
        5: ['0-0', '1-0'],          # |/
                                    # | 4
        4: ['0-0'],                 # |
                                    # 3
        3: [],
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_revset_2():
    repo = openrepo('manyheads')
649
    revset = {5, 4, 3, 2, 1}
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
    grapher = graph.revision_grapher(repo, {'revset': revset})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                                    # 5
        5: ['0-0', '0-1'],          # |\
                                    # +---4
        4: ['0-0', '1-1', '2-0'],   # | |
                                    # | 3
        3: ['0-0', '1-1'],          # | |
                                    # 2 |
        2: ['0-0', '1-0'],          # |/
                                    # 1
        1: [],
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_revset_3():
    repo = openrepo('manyheads')
668
    revset = {8, 5, 3}
669 670 671
    grapher = graph.revision_grapher(repo, {'revset': revset})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
672 673
                                    # 8
        8: ['0-0', '0-1'],          # |\
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
                                    # | 5
        5: ['0-0', '1-0'],          # |/
                                    # 3
        3: [],                      #
        }
    assert_equal(expectedtable, actualtable)

def test_grapher_showgraftsource():
    repo = openrepo('bulkgraft')
    grapher = graph.revision_grapher(repo, {"showgraftsource": True})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                                            # wt
        None: ['0-0'],                      # |
                                            # 7
        7: ['0-0', '0-1G'],                 # |\
                                            # 6 .
        6: ['0-0', '0-1G', '1-2G'],         # |\ \
                                            # 5 . .
        5: ['0-0', '0-1G', '1-2G', '2-3G'], # |\ \ \
                                            # 4 : : :
        4: ['0-0', '1-1G', '2-2G', '3-3G'], # | : : :
                                            # | : : 3
        3: ['0-0', '1-1G', '2-2G', '3-2'],  # | : :/
                                            # | : 2
        2: ['0-0', '1-1G', '2-1'],          # | :/
                                            # | 1
        1: ['0-0', '1-0'],                  # |/
                                            # 0
        0: [],
    }
    assert_equal(expectedtable, actualtable)

707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
def test_grapher_showgraftsource_with_branch():
    repo = openrepo('bulkgraft')
    grapher = graph.revision_grapher(
        repo, {"showgraftsource": True, "branch": "default"})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                            # wt
        None: ['0-0'],      # |
                            # 7
        7: ['0-0'],         # |
                            # 6
        6: ['0-0'],         # |
                            # 5
        5: ['0-0', '0-1G'], # |\
                            # 4 :
        4: ['0-0', '1-1G'], # | :
                            # | 1
        1: ['0-0', '1-0'],  # |/
                            # 0
        0: [],
    }
    assert_equal(expectedtable, actualtable)

730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
def test_grapher_hidegraftsource():
    repo = openrepo('bulkgraft')
    grapher = graph.revision_grapher(repo, {})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                            # wt
        None: ['0-0'],      # |
                            # 7
        7: ['0-0'],         # |
                            # 6
        6: ['0-0'],         # |
                            # 5
        5: ['0-0'],         # |
                            # 4
        4: ['0-0'],         # |
                            # | 3
        3: ['0-0', '1-1'],  # | |
                            # | 2
        2: ['0-0', '1-1'],  # | |
                            # | 1
        1: ['0-0', '1-0'],  # |/
                            # 0
        0: [],
    }
    assert_equal(expectedtable, actualtable)
755 756 757 758 759 760 761 762 763 764

def setup_obsolete():
    buildrepo('obsolete', r"""
    2 [precs=1]
    | 1
    |/
    0
    """)

def test_grapher_hiddenrev():
765
    repo = openrepo('obsolete')
766 767 768 769 770 771 772 773 774 775 776 777 778 779
    grapher = graph.revision_grapher(repo, {})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                            # wt
        None: ['0-0'],      # |
                            # 2
        2: ['0-0'],         # |
                            # 0
        0: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_showobsolete():
    repo = openrepo('obsolete').unfiltered()
780
    grapher = graph.revision_grapher(repo, {'showgraftsource': True})
781 782 783 784 785 786 787 788 789 790 791 792
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
                            # wt
        None: ['0-0'],      # |
                            # 2
        2: ['0-0', '0-1O'], # |`
                            # | 1
        1: ['0-0', '1-0'],  # |/
                            # 0
        0: [],
    }
    assert_equal(expectedtable, actualtable)
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814

def setup_familyline():
    buildrepo('familyline', r"""
    o        # 12
    |\    o  # 11
    o---+ |  # 10
    | 9 |/
    |/| 8
    | 7 |
    6 |\|
    |\| 5
    | 4 |
    |/| 3
    2 |/
    | 1 [branch=foo]
    |/
    0
    """)

def test_grapher_familyline_islands():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
815
                                            'revset': {12, 11}})
816 817 818 819 820 821 822 823 824 825
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
        12: [],
        11: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_1_parent():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
826
                                            'revset': {12, 10}})
827 828 829 830 831 832 833 834 835 836
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
        12: ['0-0'],
        10: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_2_parents():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
837
                                            'revset': {9, 7, 6}})
838 839 840 841 842 843 844 845 846 847 848 849 850
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {       # 9
        9: ['0-0', '0-1'],  # |\
                            # 7 |
        7: ['1-0'],         #  /
                            # 6
        6: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_1_nva():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
851
                                            'revset': {9, 4}})
852 853 854 855 856 857 858 859 860 861
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
        9: ['0-0F'],
        4: []
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_2_nvas():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
862
                                            'revset': {7, 3, 2}})
863 864 865 866 867 868 869 870 871 872 873 874 875
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 7
        7: ['0-0F', '0-1F'],  # |\
                              # | 3
        3: ['0-0F'],          # |
                              # 2    2 is treated as 1st parent because
        2: [],                #      it is ancestor of 4(1st parent of 7)
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_simple_case_1():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
876
                                            'revset': {7, 4, 3, 1}})
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 7
        7: ['0-0', '0-1F'],   # |\
                              # 4 |
        4: ['0-0', '1-1F'],   # | |
                              # | 3
        3: ['0-0', '1-0'],    # |/
                              # 1
        1: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_simple_case_2():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
892
                                            'revset': {7, 5, 4, 1}})
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 7
        7: ['0-0', '0-1'],    # |\
                              # | 5
        5: ['0-0', '1-1F'],   # | |
                              # 4 |
        4: ['0-0', '1-0F'],   # |/
                              # 1
        1: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_many_parents():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
908
                                            'revset': {12, 11, 8, 7, 6}})
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {                           # 12--+
        12: ['0-0F', '0-1F', '0-2F'],           # |\  |
                                                # | +---11
        11: ['0-0F', '1-1F', '2-2F', '3-1'],    # | | |
                                                # | 8 |
         8: ['0-0F', '2-1F'],                   # |  /
                                                # | 7
         7: ['0-0F'],                           # |
                                                # 6
         6: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_dont_draw_familyline_to_parent():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
926
                                            'revset': {6, 2}})
927 928 929 930 931 932 933 934 935 936 937
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 6
        6: ['0-0'],           # | familyline between 6 and 2 (from 6-4-2) is
                              # 2 not drawn because 2 is direct parent of 6
        2: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_dont_draw_familyline_to_ancestor_of_visible_p1():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
938
                                            'revset': {9, 7, 2}})
939 940 941 942 943 944 945 946 947 948 949 950 951
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 9
        9: ['0-0'],           # | familyline between 9 and 2 (from 9-6-2) is
                              # 7 not drawn because 2 is ancestor of 7
        7: ['0-0F'],          # |
                              # 2
        2: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_dont_draw_familyline_to_ancestor_of_visible_p2():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
952
                                            'revset': {9, 6, 1}})
953 954 955 956 957 958 959 960 961 962 963 964 965
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 9
        9: ['0-0'],           # | familyline between 9 and 2 (from 9-7-2) is
                              # 6 not drawn because 2 is ancestor of 6
        6: ['0-0F'],          # |
                              # 1
        1: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_dont_draw_familyline_to_ancestor_of_other_nva():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
966
                                            'revset': {9, 5, 1}})
967 968 969 970 971 972 973 974 975 976 977 978 979
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 9
        9: ['0-0F'],          # | familyline between 9 and 1 (from 9-7-4-1) is
                              # 5 not drawn because 1 is ancestor of 5
        5: ['0-0F'],          # |
                              # 1
        1: [],
    }
    assert_equal(expectedtable, actualtable)

def test_grapher_familyline_branch():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
980
                                            'revset': {10, 9, 8, 6, 5},
981 982 983 984 985 986 987 988 989 990
                                            'branch': 'foo'})
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {         # 9
        9: ['0-0F'],          # |
                              # | 8
        8: ['0-0F', '1-0'],   # |/
                              # 5
        5: [],
    }
    assert_equal(expectedtable, actualtable)
991

992 993 994
def test_grapher_familyline_invisible_earliest():
    repo = openrepo('familyline')
    grapher = graph.revision_grapher(repo, {'showfamilyline': True,
995
                                            'revset': {1, 0},
996 997 998 999 1000 1001 1002 1003
                                            'branch': 'foo'})
    # should empty queue even if the earliest revision is invisible
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
        1: [],
    }
    assert_equal(expectedtable, actualtable)

1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047
def setup_movedfile():
    buildrepo('movedfile', r"""
    6 [files="baz"] # add baz again
    5
    4 [files="foo2=>foo3, bar=>, baz=>"]
    3 [files="foo2"]
    2 [files="foo=>foo2, bar, baz"]
    1
    0 [files="foo, bar, baz"]
    """)

def buildpathtable(grapher):
    return dict((n.rev, n.extra[0]) for n in grapher)

def test_filelog_movedpath():
    repo = openrepo('movedfile')
    grapher = graph.filelog_grapher(repo, 'foo3')
    assert_equal({4: 'foo3', 3: 'foo2', 2: 'foo2', 0: 'foo'},
                 buildpathtable(grapher))

def test_filelog_removedpath():
    repo = openrepo('movedfile')
    grapher = graph.filelog_grapher(repo, 'bar')
    assert_equal({2: 'bar', 0: 'bar'},
                 buildpathtable(grapher))

def test_filelog_readdedpath():
    repo = openrepo('movedfile')
    grapher = graph.filelog_grapher(repo, 'baz')
    assert_equal({6: 'baz', 2: 'baz', 0: 'baz'},
                 buildpathtable(grapher))

def test_filelog_readded_file():
    repo = openrepo('movedfile')
    grapher = graph.filelog_grapher(repo, 'baz')
    actualtable = buildlinecolumntable(grapher)
    expectedtable = {
        6: [],      # 6
                    #
        2: ['0-0'], # 2
                    # |
        0: [],      # 0
    }
    assert_equal(expectedtable, actualtable)