// Implementation of FileRev.
#include <clientapi.h>
#include "changesorter.h"
#include "filehead.h"
#include "filelogcache.h"
FileRev::FileRev
( StrBuf nrev, FileHead* parent, StrBuf nchange, RevType rtype, StrBuf da )
:hasarrow( false ), revball( NULL ), rev( nrev ), change( nchange ),
date( da ), fh( parent ), type( rtype ), prev( NULL ), next( NULL ),
fromcheck( false ), intocheck( false ), fromarrows( NULL ),
fromtexts( NULL ), intotexts( NULL )
{
}
// Add a FileRevArrow, doing necessary checks to ensure that
// "contrib" levels make sense and that there aren't any
// duplicates.
void FileRev::AddFromArrow( FileRev* rev, ArrowType at )
{
if ( !rev ) return;
// Do a quick check to avoid duplicates.
for ( FileRevArrow* test = fromarrows ; test ; test = test->next )
if ( test->ptr == rev ) return; // duplicate
fh->flc->numarrows++;
// sanity check for "impure" integs
if ( ( type == EDIT || type == ADD ) && ( at != edit ) ) at = impure;
FileRevArrow* newarrow = new FileRevArrow;
newarrow->ptr = rev;
newarrow->type = at;
switch ( at )
{
case edit:
case branch:
case copy:
newarrow->contrib = all; break;
case ignore:
newarrow->contrib = none; break;
case impure:
case merge:
newarrow->contrib = some; break;
}
newarrow->next = fromarrows;
fromarrows = newarrow;
// Tweak "contrib" levels.
// Any arrow pointing into an edit should at best be "some".
if ( type == EDIT && newarrow->contrib == all )
newarrow->contrib = some;
// Any arrow to xor from a delete should be a "none".
if ( ( type == DEL ) != ( rev->type == DEL ) )
newarrow->contrib = none;
// Downgrade "contrib" of other arrows as needed.
for ( FileRevArrow* scan = fromarrows->next ; scan ; scan = scan->next )
{
switch ( fromarrows->contrib )
{
case all:
scan->contrib = none; break;
case some:
if ( scan->contrib == all ) scan->contrib = some; break;
}
}
}
// Add a FileRevText - a text version of an integ record.
void FileRev::AddFromText
( StrBuf &infile, StrBuf &inrev, ArrowType atype, char* data )
{
FileTextArrow* newtext = new FileTextArrow;
newtext->file.Set( infile );
newtext->rev.Set( inrev );
newtext->type = atype;
newtext->record.Set( data );
newtext->next = fromtexts;
fromtexts = newtext;
}
// Ditto, but mark it as an "into" rather than "from"
void FileRev::AddIntoText
( StrBuf& infile, StrBuf& inrev, ArrowType atype, char* data )
{
FileTextArrow* newtext = new FileTextArrow;
newtext->file.Set( infile );
newtext->rev.Set( inrev );
newtext->type = atype;
newtext->record.Set( data );
newtext->next = intotexts;
intotexts = newtext;
}
FileRev::~FileRev()
{
FileRevArrow* rmg;
while ( fromarrows )
{
rmg = fromarrows->next;
delete fromarrows;
fromarrows = rmg;
}
if ( next ) delete next;
}