1.5 Choose your starting point

Book can be downloaded from here

1.5.1 Example 5

From git repo, checkout 4a12f89865 and merge aaf633c2ad. 29.

Listing 1.80:example 5 - CB in builtin/gc.c
686<<<<<<< HEAD 
687if (gc_write_commit_graph && 
688    write_commit_graph_reachable(get_object_directory(), 
689                                 !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
690                                 NULL)) 
691        return 1; 
692||||||| 9c9b961d7e 
693if (gc_write_commit_graph && 
694    write_commit_graph_reachable(get_object_directory(), 
695                                 !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0, 
696                                 NULL)) 
697        return 1; 
698======= 
699prepare_repo_settings(the_repository); 
700if (the_repository->settings.gc_write_commit_graph == 1) 
701        write_commit_graph_reachable(get_object_directory(), 
702                                     !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0, 
703                                     NULL); 
704>>>>>>> aaf633c2ad

30

Following the same technique we have used so far, start working from UB (with markers, for clarity):

Listing 1.81:example 5 - UB in CB
686<<<<<<< HEAD 
687if (gc_write_commit_graph && 
688    write_commit_graph_reachable(get_object_directory(), 
689                                 !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
690                                 NULL)) 
691        return 1; 
692||||||| 9c9b961d7e

Let’s get the dML:

Listing 1.82:example 5 - MB and LB in CB
692||||||| 9c9b961d7e 
693if (gc_write_commit_graph && 
694    write_commit_graph_reachable(get_object_directory(), 
695                                 !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0, 
696                                 NULL)) 
697        return 1; 
698======= 
699prepare_repo_settings(the_repository); 
700if (the_repository->settings.gc_write_commit_graph == 1) 
701        write_commit_graph_reachable(get_object_directory(), 
702                                     !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0, 
703                                     NULL); 
704>>>>>>> aaf633c2ad

dML: A call to prepare_repo_settings() was prepended (line 699), the conditional statement was modified so that the standalone variable gc_write_commit_graph from line 694 is now part of a struct * on line 700. The call to write_commit_graph_reachable() originally used as part of the conditional statement (line 694) is now part of the if-true section of the conditional (line 701) so adjusted formatting and finally removed the return statement (present on line 697).

Let’s replicate all those changes on UB.

Listing 1.83:example 5 - Step 1 - Prepend call
686<<<<<<< HEAD 
687prepare_repo_settings(the_repository); 
688if (gc_write_commit_graph && 
689    write_commit_graph_reachable(get_object_directory(), 
690                                 !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
691                                 NULL)) 
692        return 1; 
693||||||| 9c9b961d7e

Listing 1.84:example 5 - Step 2 - adjust conditional
686<<<<<<< HEAD 
687prepare_repo_settings(the_repository); 
688if (the_repository->settings.gc_write_commit_graph == 1) 
689    write_commit_graph_reachable(get_object_directory(), 
690                                 !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
691                                 NULL); 
692        return 1; 
693||||||| 9c9b961d7e

Listing 1.85:example 5 - Step 3 - adjust formatting
686<<<<<<< HEAD 
687prepare_repo_settings(the_repository); 
688if (the_repository->settings.gc_write_commit_graph == 1) 
689        write_commit_graph_reachable(get_object_directory(), 
690                                     !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
691                                     NULL); 
692        return 1; 
693||||||| 9c9b961d7e

Listing 1.86:example 5 - Step 4 - Remove return
686<<<<<<< HEAD 
687prepare_repo_settings(the_repository); 
688if (the_repository->settings.gc_write_commit_graph == 1) 
689        write_commit_graph_reachable(get_object_directory(), 
690                                     !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
691                                     NULL); 
692||||||| 9c9b961d7e

Final result:

Listing 1.87:example 5 - final result
681if (pack_garbage.nr > 0) { 
682        close_object_store(the_repository->objects); 
683        clean_pack_garbage(); 
684
685 
686prepare_repo_settings(the_repository); 
687if (the_repository->settings.gc_write_commit_graph == 1) 
688        write_commit_graph_reachable(get_object_directory(), 
689                                     !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
690                                     NULL); 
691 
692if (auto_gc && too_many_loose_objects())

1.5.2 Example 5... from LB

All in all, 4 modifications had to be carried out on the UB to solve the conflict. Now, we are not forced to work from UB. We can choose to work from LB instead.

Let’s start over:

Listing 1.88:example 5 - LB in CB
698======= 
699prepare_repo_settings(the_repository); 
700if (the_repository->settings.gc_write_commit_graph == 1) 
701        write_commit_graph_reachable(get_object_directory(), 
702                                     !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0, 
703                                     NULL); 
704>>>>>>> aaf633c2ad

Let’s do the dMU analysis this time:

Listing 1.89:example 5 - UB and MB in CB
686<<<<<<< HEAD 
687if (gc_write_commit_graph && 
688    write_commit_graph_reachable(get_object_directory(), 
689                                 !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
690                                 NULL)) 
691        return 1; 
692||||||| 9c9b961d7e 
693if (gc_write_commit_graph && 
694    write_commit_graph_reachable(get_object_directory(), 
695                                 !quiet && !daemonized ? COMMIT_GRAPH_PROGRESS : 0, 
696                                 NULL)) 
697        return 1; 
698=======

dMU: The original COMMIT_GRAPH_PROGRESS on line 695 is now COMMIT_GRAPH_WRITE_PROGRESS on line 689. 31

Let’s replicate this change on LB:

Listing 1.90:example 5 - Step 1
698======= 
699prepare_repo_settings(the_repository); 
700if (the_repository->settings.gc_write_commit_graph == 1) 
701        write_commit_graph_reachable(get_object_directory(), 
702                                     !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
703                                     NULL); 
704>>>>>>> aaf633c2ad

And we are done! Final result:

Listing 1.91:example 5 - final result
681if (pack_garbage.nr > 0) { 
682        close_object_store(the_repository->objects); 
683        clean_pack_garbage(); 
684
685 
686prepare_repo_settings(the_repository); 
687if (the_repository->settings.gc_write_commit_graph == 1) 
688        write_commit_graph_reachable(get_object_directory(), 
689                                     !quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0, 
690                                     NULL); 
691 
692if (auto_gc && too_many_loose_objects())

Which is exactly like the previous conflict resolution we tried. The only thing is that we had to work less because we started from the block of code that was more different from MB. Less changes to detect and bring over... and therefore less opportunities to mess up.

Copyright 2020 Edmundo Carmona Antoranz