Previous Topic: Generate a List Version ReportNext Topic: Take Snapshot Process


List Version Examples

The following List Version examples are based on versions of a shopping list. You can apply this algorithm to any kind of code. The original example list looks like this:

list1
tomatoes
potatoes
corn

Example 1: Delete a Line

Remove potatoes from the list and it looks like this:

list2
tomatoes
corn

The List Version report would display the following output when list1 is compared to list2:

2d1
< potatoes

This output indicates that you must delete line 2 to make the first list like the second. The line to be deleted displays below the command. The less than sign (<) indicates that this line is from list1.

Example 2: Add a Line

Then instead of leaving out potatoes, add spinach to the list. The second list now looks like this:

list2
tomatoes
potatoes
spinach
corn

The output of differencing this list against list1 would look like this:

2a3
> spinach

This output indicates that you need to add a line to list1 after line 2. The line to be added is from the second list, as indicated by the greater than sign (>), and is listed below the instruction.

Example 3: Change a Line

In the third example, you buy peas instead of potatoes. The revised shopping list now looks like this:

list2
tomatoes
peas
corn

The output of differencing this list against list1 would look like this:

2c2
< potatoes
---
> peas

This output indicates that line 2 needs to be changed. The line from the first file (< potatoes) needs to be changed to be like the line from the second file (> peas). The three hyphens indicate the end of the text in the first list and the start of the text in the second list that should replace it.

Example 4: Change Several Lines

In the fourth example, you remove the old list and replace it with fruit:

list2
apples
pears
bananas

The output of differencing this list against list1 would look like this:

1,3c1,3
< tomatoes
< potatoes
< corn
---
> apples
> pears
> bananas

This output indicates that a range of lines (1-3) in the first list must be changed and replaced with a similar range of lines from the second.