Alternative implementation

Suppose the following repository

Action Path Copy src path Copy src revision
Revision 1
A /trunk    
A /branches    
A /tags    
Revision 2
A /trunk/foo.txt    
A /trunk/bar.txt    
Revision 3
D /trunk    
Revision 4
A /branches/1.0 /trunk 2

In this algorithm log messages are first stored without processing them. When the user wants to show a graph the cache information is processed only for that file.

Persist log messages

First all log messages are stored without processing them.

Change paths table

Path Revision id Copy src revision Copy src path Action File id
/trunk 1 NULL NULL A NULL
/branches 1 NULL NULL A NULL
/tags 1 NULL NULL A NULL
/trunk/foo.txt 2 NULL NULL A NULL
/trunk/bar.txt 2 NULL NULL A NULL
/trunk 3 NULL NULL D NULL
/branches/1.0 4 2 /trunk A NULL

Find first log message

Suppose the user wants to see the graph for /branches/1.0/foo.txt at revision 4. We ask the repository for the first log message of the selected file. In our case

Revision number Action Path Copy src path Copy src revision
2 A /trunk/foo.txt    

Now we now that the graph for /branches/1.0/foo.txt starts at revision 2 with the path /trunk/foo.txt

Calculate graph information

This step calculates all the information for the graph of the selected file.

All revisions (starting in this case at revision 2) are iterated.

Revision 2

This is the first revision of the file. We create a new file_id for this file. And we update the change path when the file was added for the first time.

Files table

File id Revision from Revision to Path
1 2 NULL /trunk/foo.txt

Change paths table

Path Revision id Copy src revision Copy src path Action File id
/trunk 1 NULL NULL A NULL
/branches 1 NULL NULL A NULL
/tags 1 NULL NULL A NULL
/trunk/foo.txt 2 NULL NULL A 1
/trunk/bar.txt 2 NULL NULL A NULL
/trunk 3 NULL NULL D NULL
/branches/1.0 4 2 /trunk A NULL

Revision 3

Action Path Copy src path Copy src revision
D /trunk    

A parent directory is deleted, so we mark /trunk/foo.txt as deleted. We also add a row in the change paths table.

Files table

File id Revision from Revision to Path
1 2 3 /trunk/foo.txt

Change paths table

Path Revision id Copy src revision Copy src path Action File id
/trunk 1 NULL NULL A NULL
/branches 1 NULL NULL A NULL
/tags 1 NULL NULL A NULL
/trunk/foo.txt 2 NULL NULL A 1
/trunk/bar.txt 2 NULL NULL A NULL
/trunk 3 NULL NULL D NULL
/trunk/foo.txt 3 NULL NULL D 1
/branches/1.0 4 2 /trunk A NULL

Revision 4

Action Path Copy src path Copy src revision
A /branches/1.0 /trunk 2

A parent directory is copied

Files table

File id Revision from Revision to Path
1 2 3 /trunk/foo.txt
1 4 NULL /branches/1.0/foo.txt

Change paths table

Path Revision id Copy src revision Copy src path Action File id
/trunk 1 NULL NULL A NULL
/branches 1 NULL NULL A NULL
/tags 1 NULL NULL A NULL
/trunk/foo.txt 2 NULL NULL A 1
/trunk/bar.txt 2 NULL NULL A NULL
/trunk 3 NULL NULL D NULL
/trunk/foo.txt 3 NULL NULL D 1
/branches/1.0 4 2 /trunk A NULL
/branches/1.0/foo.txt 4 2 /trunk/foo.txt A 1

As you can see at the end we have only calculated the branching information of the selected file. The result is: just one file id in the files and change paths table.