1#include"cache.h" 2#include"commit.h" 3#include"graph.h" 4#include"diff.h" 5#include"revision.h" 6 7/* 8 * TODO: 9 * - Add colors to the graph. 10 * Pick a color for each column, and print all characters 11 * in that column with the specified color. 12 * 13 * - Limit the number of columns, similar to the way gitk does. 14 * If we reach more than a specified number of columns, omit 15 * sections of some columns. 16 * 17 * - The output during the GRAPH_PRE_COMMIT and GRAPH_COLLAPSING states 18 * could be made more compact by printing horizontal lines, instead of 19 * long diagonal lines. For example, during collapsing, something like 20 * this: instead of this: 21 * | | | | | | | | | | 22 * | |_|_|/ | | | |/ 23 * |/| | | | | |/| 24 * | | | | | |/| | 25 * |/| | | 26 * | | | | 27 * 28 * If there are several parallel diagonal lines, they will need to be 29 * replaced with horizontal lines on subsequent rows. 30 */ 31 32struct column { 33/* 34 * The parent commit of this column. 35 */ 36struct commit *commit; 37/* 38 * XXX: Once we add support for colors, struct column could also 39 * contain the color of its branch line. 40 */ 41}; 42 43enum graph_state { 44 GRAPH_PADDING, 45 GRAPH_SKIP, 46 GRAPH_PRE_COMMIT, 47 GRAPH_COMMIT, 48 GRAPH_POST_MERGE, 49 GRAPH_COLLAPSING 50}; 51 52struct git_graph { 53/* 54 * The commit currently being processed 55 */ 56struct commit *commit; 57/* 58 * The number of parents this commit has. 59 * (Stored so we don't have to walk over them each time we need 60 * this number) 61 */ 62int num_parents; 63/* 64 * The next expansion row to print 65 * when state is GRAPH_PRE_COMMIT 66 */ 67int expansion_row; 68/* 69 * The current output state. 70 * This tells us what kind of line graph_next_line() should output. 71 */ 72enum graph_state state; 73/* 74 * The maximum number of columns that can be stored in the columns 75 * and new_columns arrays. This is also half the number of entries 76 * that can be stored in the mapping and new_mapping arrays. 77 */ 78int column_capacity; 79/* 80 * The number of columns (also called "branch lines" in some places) 81 */ 82int num_columns; 83/* 84 * The number of columns in the new_columns array 85 */ 86int num_new_columns; 87/* 88 * The number of entries in the mapping array 89 */ 90int mapping_size; 91/* 92 * The column state before we output the current commit. 93 */ 94struct column *columns; 95/* 96 * The new column state after we output the current commit. 97 * Only valid when state is GRAPH_COLLAPSING. 98 */ 99struct column *new_columns; 100/* 101 * An array that tracks the current state of each 102 * character in the output line during state GRAPH_COLLAPSING. 103 * Each entry is -1 if this character is empty, or a non-negative 104 * integer if the character contains a branch line. The value of 105 * the integer indicates the target position for this branch line. 106 * (I.e., this array maps the current column positions to their 107 * desired positions.) 108 * 109 * The maximum capacity of this array is always 110 * sizeof(int) * 2 * column_capacity. 111 */ 112int*mapping; 113/* 114 * A temporary array for computing the next mapping state 115 * while we are outputting a mapping line. This is stored as part 116 * of the git_graph simply so we don't have to allocate a new 117 * temporary array each time we have to output a collapsing line. 118 */ 119int*new_mapping; 120}; 121 122struct git_graph *graph_init(void) 123{ 124struct git_graph *graph =xmalloc(sizeof(struct git_graph)); 125 graph->commit = NULL; 126 graph->num_parents =0; 127 graph->expansion_row =0; 128 graph->state = GRAPH_PADDING; 129 graph->num_columns =0; 130 graph->num_new_columns =0; 131 graph->mapping_size =0; 132 133/* 134 * Allocate a reasonably large default number of columns 135 * We'll automatically grow columns later if we need more room. 136 */ 137 graph->column_capacity =30; 138 graph->columns =xmalloc(sizeof(struct column) * 139 graph->column_capacity); 140 graph->new_columns =xmalloc(sizeof(struct column) * 141 graph->column_capacity); 142 graph->mapping =xmalloc(sizeof(int) *2* graph->column_capacity); 143 graph->new_mapping =xmalloc(sizeof(int) *2* graph->column_capacity); 144 145return graph; 146} 147 148voidgraph_release(struct git_graph *graph) 149{ 150free(graph->columns); 151free(graph->new_columns); 152free(graph->mapping); 153free(graph); 154} 155 156static voidgraph_ensure_capacity(struct git_graph *graph,int num_columns) 157{ 158if(graph->column_capacity >= num_columns) 159return; 160 161do{ 162 graph->column_capacity *=2; 163}while(graph->column_capacity < num_columns); 164 165 graph->columns =xrealloc(graph->columns, 166sizeof(struct column) * 167 graph->column_capacity); 168 graph->new_columns =xrealloc(graph->new_columns, 169sizeof(struct column) * 170 graph->column_capacity); 171 graph->mapping =xrealloc(graph->mapping, 172sizeof(int) *2* graph->column_capacity); 173 graph->new_mapping =xrealloc(graph->new_mapping, 174sizeof(int) *2* graph->column_capacity); 175} 176 177static voidgraph_insert_into_new_columns(struct git_graph *graph, 178struct commit *commit, 179int*mapping_index) 180{ 181int i; 182 183/* 184 * Ignore uinteresting and pruned commits 185 */ 186if(commit->object.flags & (UNINTERESTING | TREESAME)) 187return; 188 189/* 190 * If the commit is already in the new_columns list, we don't need to 191 * add it. Just update the mapping correctly. 192 */ 193for(i =0; i < graph->num_new_columns; i++) { 194if(graph->new_columns[i].commit == commit) { 195 graph->mapping[*mapping_index] = i; 196*mapping_index +=2; 197return; 198} 199} 200 201/* 202 * This commit isn't already in new_columns. Add it. 203 */ 204 graph->new_columns[graph->num_new_columns].commit = commit; 205 graph->mapping[*mapping_index] = graph->num_new_columns; 206*mapping_index +=2; 207 graph->num_new_columns++; 208} 209 210static voidgraph_update_columns(struct git_graph *graph) 211{ 212struct commit_list *parent; 213struct column *tmp_columns; 214int max_new_columns; 215int mapping_idx; 216int i, seen_this; 217 218/* 219 * Swap graph->columns with graph->new_columns 220 * graph->columns contains the state for the previous commit, 221 * and new_columns now contains the state for our commit. 222 * 223 * We'll re-use the old columns array as storage to compute the new 224 * columns list for the commit after this one. 225 */ 226 tmp_columns = graph->columns; 227 graph->columns = graph->new_columns; 228 graph->num_columns = graph->num_new_columns; 229 230 graph->new_columns = tmp_columns; 231 graph->num_new_columns =0; 232 233/* 234 * Now update new_columns and mapping with the information for the 235 * commit after this one. 236 * 237 * First, make sure we have enough room. At most, there will 238 * be graph->num_columns + graph->num_parents columns for the next 239 * commit. 240 */ 241 max_new_columns = graph->num_columns + graph->num_parents; 242graph_ensure_capacity(graph, max_new_columns); 243 244/* 245 * Clear out graph->mapping 246 */ 247 graph->mapping_size =2* max_new_columns; 248for(i =0; i < graph->mapping_size; i++) 249 graph->mapping[i] = -1; 250 251/* 252 * Populate graph->new_columns and graph->mapping 253 * 254 * Some of the parents of this commit may already be in 255 * graph->columns. If so, graph->new_columns should only contain a 256 * single entry for each such commit. graph->mapping should 257 * contain information about where each current branch line is 258 * supposed to end up after the collapsing is performed. 259 */ 260 seen_this =0; 261 mapping_idx =0; 262for(i =0; i <= graph->num_columns; i++) { 263struct commit *col_commit; 264if(i == graph->num_columns) { 265if(seen_this) 266break; 267 col_commit = graph->commit; 268}else{ 269 col_commit = graph->columns[i].commit; 270} 271 272if(col_commit == graph->commit) { 273 seen_this =1; 274for(parent = graph->commit->parents; 275 parent; 276 parent = parent->next) { 277graph_insert_into_new_columns(graph, 278 parent->item, 279&mapping_idx); 280} 281}else{ 282graph_insert_into_new_columns(graph, col_commit, 283&mapping_idx); 284} 285} 286 287/* 288 * Shrink mapping_size to be the minimum necessary 289 */ 290while(graph->mapping_size >1&& 291 graph->mapping[graph->mapping_size -1] <0) 292 graph->mapping_size--; 293} 294 295voidgraph_update(struct git_graph *graph,struct commit *commit) 296{ 297struct commit_list *parent; 298 299/* 300 * Set the new commit 301 */ 302 graph->commit = commit; 303 304/* 305 * Count how many parents this commit has 306 */ 307 graph->num_parents =0; 308for(parent = commit->parents; parent; parent = parent->next) 309 graph->num_parents++; 310 311/* 312 * Call graph_update_columns() to update 313 * columns, new_columns, and mapping. 314 */ 315graph_update_columns(graph); 316 317 graph->expansion_row =0; 318 319/* 320 * Update graph->state. 321 * 322 * If the previous commit didn't get to the GRAPH_PADDING state, 323 * it never finished its output. Goto GRAPH_SKIP, to print out 324 * a line to indicate that portion of the graph is missing. 325 * 326 * Otherwise, if there are 3 or more parents, we need to print 327 * extra rows before the commit, to expand the branch lines around 328 * it and make room for it. 329 * 330 * If there are less than 3 parents, we can immediately print the 331 * commit line. 332 */ 333if(graph->state != GRAPH_PADDING) 334 graph->state = GRAPH_SKIP; 335else if(graph->num_parents >=3) 336 graph->state = GRAPH_PRE_COMMIT; 337else 338 graph->state = GRAPH_COMMIT; 339} 340 341static intgraph_is_mapping_correct(struct git_graph *graph) 342{ 343int i; 344 345/* 346 * The mapping is up to date if each entry is at its target, 347 * or is 1 greater than its target. 348 * (If it is 1 greater than the target, '/' will be printed, so it 349 * will look correct on the next row.) 350 */ 351for(i =0; i < graph->mapping_size; i++) { 352int target = graph->mapping[i]; 353if(target <0) 354continue; 355if(target == (i /2)) 356continue; 357return0; 358} 359 360return1; 361} 362 363static voidgraph_pad_horizontally(struct git_graph *graph,struct strbuf *sb) 364{ 365/* 366 * Add additional spaces to the end of the strbuf, so that all 367 * lines for a particular commit have the same width. 368 * 369 * This way, fields printed to the right of the graph will remain 370 * aligned for the entire commit. 371 * 372 * This computation results in 3 extra space to the right in most 373 * cases, but only 1 extra space if the commit doesn't have any 374 * children that have already been displayed in the graph (i.e., 375 * if the current commit isn't in graph->columns). 376 */ 377size_t extra; 378size_t final_width = graph->num_columns + graph->num_parents; 379if(graph->num_parents <1) 380 final_width++; 381 final_width *=2; 382 383if(sb->len >= final_width) 384return; 385 386 extra = final_width - sb->len; 387strbuf_addf(sb,"%*s", (int) extra,""); 388} 389 390static voidgraph_output_padding_line(struct git_graph *graph, 391struct strbuf *sb) 392{ 393int i; 394 395/* 396 * We could conceivable be called with a NULL commit 397 * if our caller has a bug, and invokes graph_next_line() 398 * immediately after graph_init(), without first calling 399 * graph_update(). Return without outputting anything in this 400 * case. 401 */ 402if(!graph->commit) 403return; 404 405/* 406 * Output a padding row, that leaves all branch lines unchanged 407 */ 408for(i =0; i < graph->num_new_columns; i++) { 409strbuf_addstr(sb,"| "); 410} 411 412graph_pad_horizontally(graph, sb); 413} 414 415static voidgraph_output_skip_line(struct git_graph *graph,struct strbuf *sb) 416{ 417/* 418 * Output an ellipsis to indicate that a portion 419 * of the graph is missing. 420 */ 421strbuf_addstr(sb,"..."); 422graph_pad_horizontally(graph, sb); 423 424if(graph->num_parents >=3) 425 graph->state = GRAPH_PRE_COMMIT; 426else 427 graph->state = GRAPH_COMMIT; 428} 429 430static voidgraph_output_pre_commit_line(struct git_graph *graph, 431struct strbuf *sb) 432{ 433int num_expansion_rows; 434int i, seen_this; 435 436/* 437 * This function formats a row that increases the space around a commit 438 * with multiple parents, to make room for it. It should only be 439 * called when there are 3 or more parents. 440 * 441 * We need 2 extra rows for every parent over 2. 442 */ 443assert(graph->num_parents >=3); 444 num_expansion_rows = (graph->num_parents -2) *2; 445 446/* 447 * graph->expansion_row tracks the current expansion row we are on. 448 * It should be in the range [0, num_expansion_rows - 1] 449 */ 450assert(0<= graph->expansion_row && 451 graph->expansion_row < num_expansion_rows); 452 453/* 454 * Output the row 455 */ 456 seen_this =0; 457for(i =0; i < graph->num_columns; i++) { 458struct column *col = &graph->columns[i]; 459if(col->commit == graph->commit) { 460 seen_this =1; 461strbuf_addf(sb,"| %*s", graph->expansion_row,""); 462}else if(seen_this) { 463strbuf_addstr(sb,"\\"); 464}else{ 465strbuf_addstr(sb,"| "); 466} 467} 468 469graph_pad_horizontally(graph, sb); 470 471/* 472 * Increment graph->expansion_row, 473 * and move to state GRAPH_COMMIT if necessary 474 */ 475 graph->expansion_row++; 476if(graph->expansion_row >= num_expansion_rows) 477 graph->state = GRAPH_COMMIT; 478} 479 480voidgraph_output_commit_line(struct git_graph *graph,struct strbuf *sb) 481{ 482int seen_this =0; 483int i, j; 484 485/* 486 * Output the row containing this commit 487 * Iterate up to and including graph->num_columns, 488 * since the current commit may not be in any of the existing 489 * columns. (This happens when the current commit doesn't have any 490 * children that we have already processed.) 491 */ 492 seen_this =0; 493for(i =0; i <= graph->num_columns; i++) { 494struct commit *col_commit; 495if(i == graph->num_columns) { 496if(seen_this) 497break; 498 col_commit = graph->commit; 499}else{ 500 col_commit = graph->columns[i].commit; 501} 502 503if(col_commit == graph->commit) { 504 seen_this =1; 505if(graph->num_parents >1) 506strbuf_addch(sb,'M'); 507else 508strbuf_addch(sb,'*'); 509 510if(graph->num_parents <2) 511strbuf_addch(sb,' '); 512else if(graph->num_parents ==2) 513strbuf_addstr(sb," "); 514else{ 515int num_dashes = 516((graph->num_parents -2) *2) -1; 517for(j =0; j < num_dashes; j++) 518strbuf_addch(sb,'-'); 519strbuf_addstr(sb,". "); 520} 521}else if(seen_this && (graph->num_parents >1)) { 522strbuf_addstr(sb,"\\"); 523}else{ 524strbuf_addstr(sb,"| "); 525} 526} 527 528graph_pad_horizontally(graph, sb); 529 530/* 531 * Update graph->state 532 */ 533if(graph->num_parents >1) 534 graph->state = GRAPH_POST_MERGE; 535else if(graph_is_mapping_correct(graph)) 536 graph->state = GRAPH_PADDING; 537else 538 graph->state = GRAPH_COLLAPSING; 539} 540 541voidgraph_output_post_merge_line(struct git_graph *graph,struct strbuf *sb) 542{ 543int seen_this =0; 544int i, j; 545 546/* 547 * Output the post-merge row 548 */ 549for(i =0; i <= graph->num_columns; i++) { 550struct commit *col_commit; 551if(i == graph->num_columns) { 552if(seen_this) 553break; 554 col_commit = graph->commit; 555}else{ 556 col_commit = graph->columns[i].commit; 557} 558 559if(col_commit == graph->commit) { 560 seen_this =1; 561strbuf_addch(sb,'|'); 562for(j =0; j < graph->num_parents -1; j++) 563strbuf_addstr(sb,"\\"); 564if(graph->num_parents ==2) 565strbuf_addch(sb,' '); 566}else if(seen_this && (graph->num_parents >2)) { 567strbuf_addstr(sb,"\\"); 568}else{ 569strbuf_addstr(sb,"| "); 570} 571} 572 573graph_pad_horizontally(graph, sb); 574 575/* 576 * Update graph->state 577 */ 578if(graph_is_mapping_correct(graph)) 579 graph->state = GRAPH_PADDING; 580else 581 graph->state = GRAPH_COLLAPSING; 582} 583 584voidgraph_output_collapsing_line(struct git_graph *graph,struct strbuf *sb) 585{ 586int i; 587int*tmp_mapping; 588 589/* 590 * Clear out the new_mapping array 591 */ 592for(i =0; i < graph->mapping_size; i++) 593 graph->new_mapping[i] = -1; 594 595for(i =0; i < graph->mapping_size; i++) { 596int target = graph->mapping[i]; 597if(target <0) 598continue; 599 600/* 601 * Since update_columns() always inserts the leftmost 602 * column first, each branch's target location should 603 * always be either its current location or to the left of 604 * its current location. 605 * 606 * We never have to move branches to the right. This makes 607 * the graph much more legible, since whenever branches 608 * cross, only one is moving directions. 609 */ 610assert(target *2<= i); 611 612if(target *2== i) { 613/* 614 * This column is already in the 615 * correct place 616 */ 617assert(graph->new_mapping[i] == -1); 618 graph->new_mapping[i] = target; 619}else if(graph->new_mapping[i -1] <0) { 620/* 621 * Nothing is to the left. 622 * Move to the left by one 623 */ 624 graph->new_mapping[i -1] = target; 625}else if(graph->new_mapping[i -1] == target) { 626/* 627 * There is a branch line to our left 628 * already, and it is our target. We 629 * combine with this line, since we share 630 * the same parent commit. 631 * 632 * We don't have to add anything to the 633 * output or new_mapping, since the 634 * existing branch line has already taken 635 * care of it. 636 */ 637}else{ 638/* 639 * There is a branch line to our left, 640 * but it isn't our target. We need to 641 * cross over it. 642 * 643 * The space just to the left of this 644 * branch should always be empty. 645 */ 646assert(graph->new_mapping[i -1] > target); 647assert(graph->new_mapping[i -2] <0); 648 graph->new_mapping[i -2] = target; 649} 650} 651 652/* 653 * The new mapping may be 1 smaller than the old mapping 654 */ 655if(graph->new_mapping[graph->mapping_size -1] <0) 656 graph->mapping_size--; 657 658/* 659 * Output out a line based on the new mapping info 660 */ 661for(i =0; i < graph->mapping_size; i++) { 662int target = graph->new_mapping[i]; 663if(target <0) 664strbuf_addch(sb,' '); 665else if(target *2== i) 666strbuf_addch(sb,'|'); 667else 668strbuf_addch(sb,'/'); 669} 670 671graph_pad_horizontally(graph, sb); 672 673/* 674 * Swap mapping and new_mapping 675 */ 676 tmp_mapping = graph->mapping; 677 graph->mapping = graph->new_mapping; 678 graph->new_mapping = tmp_mapping; 679 680/* 681 * If graph->mapping indicates that all of the branch lines 682 * are already in the correct positions, we are done. 683 * Otherwise, we need to collapse some branch lines together. 684 */ 685if(graph_is_mapping_correct(graph)) 686 graph->state = GRAPH_PADDING; 687} 688 689intgraph_next_line(struct git_graph *graph,struct strbuf *sb) 690{ 691switch(graph->state) { 692case GRAPH_PADDING: 693graph_output_padding_line(graph, sb); 694return0; 695case GRAPH_SKIP: 696graph_output_skip_line(graph, sb); 697return0; 698case GRAPH_PRE_COMMIT: 699graph_output_pre_commit_line(graph, sb); 700return0; 701case GRAPH_COMMIT: 702graph_output_commit_line(graph, sb); 703return1; 704case GRAPH_POST_MERGE: 705graph_output_post_merge_line(graph, sb); 706return0; 707case GRAPH_COLLAPSING: 708graph_output_collapsing_line(graph, sb); 709return0; 710} 711 712assert(0); 713return0; 714} 715 716voidgraph_padding_line(struct git_graph *graph,struct strbuf *sb) 717{ 718int i, j; 719 720if(graph->state != GRAPH_COMMIT) { 721graph_next_line(graph, sb); 722return; 723} 724 725/* 726 * Output the row containing this commit 727 * Iterate up to and including graph->num_columns, 728 * since the current commit may not be in any of the existing 729 * columns. (This happens when the current commit doesn't have any 730 * children that we have already processed.) 731 */ 732for(i =0; i < graph->num_columns; i++) { 733struct commit *col_commit = graph->columns[i].commit; 734if(col_commit == graph->commit) { 735strbuf_addch(sb,'|'); 736 737if(graph->num_parents <3) 738strbuf_addch(sb,' '); 739else{ 740int num_spaces = ((graph->num_parents -2) *2); 741for(j =0; j < num_spaces; j++) 742strbuf_addch(sb,' '); 743} 744}else{ 745strbuf_addstr(sb,"| "); 746} 747} 748 749graph_pad_horizontally(graph, sb); 750} 751 752intgraph_is_commit_finished(struct git_graph const*graph) 753{ 754return(graph->state == GRAPH_PADDING); 755} 756 757voidgraph_show_commit(struct git_graph *graph) 758{ 759struct strbuf msgbuf; 760int shown_commit_line =0; 761 762if(!graph) 763return; 764 765strbuf_init(&msgbuf,0); 766 767while(!shown_commit_line) { 768 shown_commit_line =graph_next_line(graph, &msgbuf); 769fwrite(msgbuf.buf,sizeof(char), msgbuf.len, stdout); 770if(!shown_commit_line) 771putchar('\n'); 772strbuf_setlen(&msgbuf,0); 773} 774 775strbuf_release(&msgbuf); 776} 777 778voidgraph_show_oneline(struct git_graph *graph) 779{ 780struct strbuf msgbuf; 781 782if(!graph) 783return; 784 785strbuf_init(&msgbuf,0); 786graph_next_line(graph, &msgbuf); 787fwrite(msgbuf.buf,sizeof(char), msgbuf.len, stdout); 788strbuf_release(&msgbuf); 789} 790 791voidgraph_show_padding(struct git_graph *graph) 792{ 793struct strbuf msgbuf; 794 795if(!graph) 796return; 797 798strbuf_init(&msgbuf,0); 799graph_padding_line(graph, &msgbuf); 800fwrite(msgbuf.buf,sizeof(char), msgbuf.len, stdout); 801strbuf_release(&msgbuf); 802} 803 804intgraph_show_remainder(struct git_graph *graph) 805{ 806struct strbuf msgbuf; 807int shown =0; 808 809if(!graph) 810return0; 811 812if(graph_is_commit_finished(graph)) 813return0; 814 815strbuf_init(&msgbuf,0); 816for(;;) { 817graph_next_line(graph, &msgbuf); 818fwrite(msgbuf.buf,sizeof(char), msgbuf.len, stdout); 819strbuf_setlen(&msgbuf,0); 820 shown =1; 821 822if(!graph_is_commit_finished(graph)) 823putchar('\n'); 824else 825break; 826} 827strbuf_release(&msgbuf); 828 829return shown; 830} 831 832 833voidgraph_show_strbuf(struct git_graph *graph,struct strbuf const*sb) 834{ 835char*p; 836 837if(!graph) { 838fwrite(sb->buf,sizeof(char), sb->len, stdout); 839return; 840} 841 842/* 843 * Print the strbuf line by line, 844 * and display the graph info before each line but the first. 845 */ 846 p = sb->buf; 847while(p) { 848size_t len; 849char*next_p =strchr(p,'\n'); 850if(next_p) { 851 next_p++; 852 len = next_p - p; 853}else{ 854 len = (sb->buf + sb->len) - p; 855} 856fwrite(p,sizeof(char), len, stdout); 857if(next_p && *next_p !='\0') 858graph_show_oneline(graph); 859 p = next_p; 860} 861} 862 863voidgraph_show_commit_msg(struct git_graph *graph, 864struct strbuf const*sb) 865{ 866int newline_terminated; 867 868if(!graph) { 869/* 870 * If there's no graph, just print the message buffer. 871 * 872 * The message buffer for CMIT_FMT_ONELINE and 873 * CMIT_FMT_USERFORMAT are already missing a terminating 874 * newline. All of the other formats should have it. 875 */ 876fwrite(sb->buf,sizeof(char), sb->len, stdout); 877return; 878} 879 880 newline_terminated = (sb->len && sb->buf[sb->len -1] =='\n'); 881 882/* 883 * Show the commit message 884 */ 885graph_show_strbuf(graph, sb); 886 887/* 888 * If there is more output needed for this commit, show it now 889 */ 890if(!graph_is_commit_finished(graph)) { 891/* 892 * If sb doesn't have a terminating newline, print one now, 893 * so we can start the remainder of the graph output on a 894 * new line. 895 */ 896if(!newline_terminated) 897putchar('\n'); 898 899graph_show_remainder(graph); 900 901/* 902 * If sb ends with a newline, our output should too. 903 */ 904if(newline_terminated) 905putchar('\n'); 906} 907}