NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
FileRevisions Class Reference

#include <filerevisions.hpp>

Collaboration diagram for FileRevisions:

Public Member Functions

 FileRevisions (const wxString &revisionPath)
 Constructor. Will try to create the missing folders on-the-fly. More...
 
size_t getRevisionCount ()
 Returns the number of available revisions. More...
 
wxArrayString getRevisionList ()
 This method returns a log-like list of revisions. More...
 
wxString getCurrentRevision ()
 This method returns the revision identifier of the current revision. More...
 
size_t addRevision (const wxString &revisionContent)
 This method adds a new revision. More...
 
size_t addExternalRevision (const wxString &filePath)
 This method adds an external modification as new revision. More...
 
void undoRevision ()
 This method removes the last added revision. More...
 
void renameFile (const wxString &oldName, const wxString &newName, const wxString &newRevPath)
 This method handles renames of the corresponding file. More...
 
void moveFile (const wxString &oldPath, const wxString &newPath, const wxString &newRevPath)
 This method handles moves of the corresponding file. More...
 
wxString getRevision (size_t nRevision)
 Returns the contents of the selected revision. More...
 
wxString getRevision (wxString revString)
 Returns the contents of the selected revision. More...
 
wxString compareRevisions (const wxString &rev1, const wxString &rev2)
 This member function compares two revisions with each other and returns the differnces as unified diff. More...
 
void restoreRevision (size_t nRevision, const wxString &targetFile)
 This method will restore the contents of the selected revision. More...
 
void restoreRevision (const wxString &revString, const wxString &targetFile)
 This method will restore the contents of the selected revision. More...
 
size_t tagRevision (size_t nRevision, const wxString &tagComment)
 Allows the user to tag a selected revision with the passed comment. More...
 
size_t tagRevision (const wxString &revString, const wxString &tagComment)
 Allows the user to tag a selected revision with the passed comment. More...
 

Private Member Functions

std::vector< wxString > vectorize (wxString fileContent)
 Converts a single-string file into a vector of strings. More...
 
wxString convertLineEndings (const wxString &content)
 This method converts line end characters. More...
 
wxString readRevision (const wxString &revString)
 This method returns the contents of the selected revision. More...
 
wxString getLastContentModification (const wxString &revString)
 This method returns the last modification revision identifier. More...
 
wxString getLastRevisionRoot (const wxString &revString)
 This method returns the revision identifier of the last revision root. More...
 
wxString diff (const wxString &revision1, const wxString &revisionID1, const wxString &revision2, const wxString &revisionID2)
 This method calculates the differences between two files. More...
 
wxString createDiff (const wxString &revisionContent)
 This method creates the file differences between the file contents and the current revision root. More...
 
wxString createMerge (const wxString &diffFile)
 This method merges the diff file into the current revision root. More...
 
wxString readExternalFile (const wxString &filePath)
 This method reads an external file into a string. More...
 
size_t createNewRevision (const wxString &revContent, const wxString &comment)
 This method creates a new revision. More...
 
size_t createNewTag (const wxString &revString, const wxString &comment)
 This method creates a new tag for the passed revision. More...
 
void fileMove (const wxString &newRevPath, const wxString &comment)
 This method handles all file move operations. More...
 
size_t getMaxDiffFileSize (size_t nFileSize)
 This member function returns the maximal Diff file size. More...
 

Private Attributes

wxFileName m_revisionPath
 

Detailed Description

Definition at line 26 of file filerevisions.hpp.

Constructor & Destructor Documentation

◆ FileRevisions()

FileRevisions::FileRevisions ( const wxString &  revisionPath)

Constructor. Will try to create the missing folders on-the-fly.

Parameters
revisionPathconst wxString&

Definition at line 39 of file filerevisions.cpp.

References m_revisionPath.

Member Function Documentation

◆ addExternalRevision()

size_t FileRevisions::addExternalRevision ( const wxString &  filePath)

This method adds an external modification as new revision.

Parameters
filePathconst wxString&
Returns
size_t

The revision is only appended, if its a real file contents change. Therefore the content of the external modification is compared to the current revision available in the list and only appended, if they are different. This will avoid creating revisions resulting from file meta data updates.

Definition at line 795 of file filerevisions.cpp.

References convertLineEndings(), createNewRevision(), diff(), getCurrentRevision(), getRevision(), and readExternalFile().

Here is the call graph for this function:

◆ addRevision()

size_t FileRevisions::addRevision ( const wxString &  revisionContent)

This method adds a new revision.

Parameters
revisionContentconst wxString&
Returns
size_t

If there's no revisions file yet, this method will create a new one containing the revisions content's as so-called "initial revision".

Definition at line 748 of file filerevisions.cpp.

References COMPRESSIONLEVEL, convertLineEndings(), createDiff(), createNewRevision(), getCurrentRevision(), getMaxDiffFileSize(), getRevision(), and m_revisionPath.

Here is the call graph for this function:

◆ compareRevisions()

wxString FileRevisions::compareRevisions ( const wxString &  rev1,
const wxString &  rev2 
)

This member function compares two revisions with each other and returns the differnces as unified diff.

Parameters
rev1const wxString&
rev2const wxString&
Returns
wxString

Definition at line 658 of file filerevisions.cpp.

References diff(), and getRevision().

Referenced by RevisionDialog::compareRevisions().

Here is the call graph for this function:

◆ convertLineEndings()

wxString FileRevisions::convertLineEndings ( const wxString &  content)
private

This method converts line end characters.

Parameters
contentconst wxString&
Returns
wxString

Windows line ending characters (CR LF) are converted into unix line endings (LF), which are used by the internal ZIP file system

Definition at line 89 of file filerevisions.cpp.

Referenced by addExternalRevision(), addRevision(), createMerge(), diff(), and restoreRevision().

◆ createDiff()

wxString FileRevisions::createDiff ( const wxString &  revisionContent)
private

This method creates the file differences between the file contents and the current revision root.

Parameters
revisionContentconst wxString&
Returns
wxString

The file differences are created in the private FileRevisions::diff() method- The current revision root is detected automatically.

Definition at line 277 of file filerevisions.cpp.

References diff(), getCurrentRevision(), getLastRevisionRoot(), getRevision(), getRevisionCount(), and toString().

Referenced by addRevision().

Here is the call graph for this function:

◆ createMerge()

wxString FileRevisions::createMerge ( const wxString &  diffFile)
private

This method merges the diff file into the current revision root.

Parameters
diffFileconst wxString&
Returns
wxString

The passed diff file is used to determine the revision root, which it is based upon. Both files are vectorized first, then the changes noted in the revision file are applied to the contents of the revision root, which is merged back into a single-string file afterwards.

Definition at line 298 of file filerevisions.cpp.

References convertLineEndings(), getRevision(), and vectorize().

Referenced by readRevision().

Here is the call graph for this function:

◆ createNewRevision()

size_t FileRevisions::createNewRevision ( const wxString &  revContent,
const wxString &  comment 
)
private

This method creates a new revision.

Parameters
revContentconst wxString&
commentconst wxString&
Returns
size_t

The revision is appended to the already available list of revisions at the end. The contents of the revision are stored completely in the target ZIP file.

Definition at line 389 of file filerevisions.cpp.

References COMPRESSIONLEVEL, getRevisionCount(), m_revisionPath, and toString().

Referenced by addExternalRevision(), addRevision(), fileMove(), and restoreRevision().

Here is the call graph for this function:

◆ createNewTag()

size_t FileRevisions::createNewTag ( const wxString &  revString,
const wxString &  comment 
)
private

This method creates a new tag for the passed revision.

Parameters
revStringconst wxString&
commentconst wxString&
Returns
size_t

The new tag is appended directly below the corresponding revision. After the new tag, the remaing parts of the file are appended

Definition at line 440 of file filerevisions.cpp.

References COMPRESSIONLEVEL, getRevisionCount(), m_revisionPath, and toString().

Referenced by tagRevision().

Here is the call graph for this function:

◆ diff()

wxString FileRevisions::diff ( const wxString &  revision1,
const wxString &  revisionID1,
const wxString &  revision2,
const wxString &  revisionID2 
)
private

This method calculates the differences between two files.

Parameters
revision1const wxString&
revisionID1const wxString&
revision2const wxString&
revisionID2const wxString&
Returns
wxString

The file differences are created by the DTL libary found in the "common" folder. The differences are returned in unified format, i.e. containing sequences of changes starting with a "@@ -a,b +c,d @@" section

Definition at line 241 of file filerevisions.cpp.

References dtl::Diff< elem, sequence, comparator >::compose(), dtl::Diff< elem, sequence, comparator >::composeUnifiedHunks(), convertLineEndings(), dtl::Diff< elem, sequence, comparator >::printUnifiedFormat(), and vectorize().

Referenced by addExternalRevision(), compareRevisions(), and createDiff().

Here is the call graph for this function:

◆ fileMove()

void FileRevisions::fileMove ( const wxString &  newRevPath,
const wxString &  comment 
)
private

This method handles all file move operations.

Parameters
newRevPathconst wxString&
commentconst wxString&
Returns
void

File move operations are move and rename operations. Those are reflected in the name and the location of the revisions file.

Definition at line 497 of file filerevisions.cpp.

References createNewRevision(), getCurrentRevision(), and m_revisionPath.

Referenced by moveFile(), and renameFile().

Here is the call graph for this function:

◆ getCurrentRevision()

wxString FileRevisions::getCurrentRevision ( )

This method returns the revision identifier of the current revision.

Returns
wxString

It excludes all tags, which are attached to the current revision, because they do not contain any file changes.

Definition at line 588 of file filerevisions.cpp.

References getRevisionList().

Referenced by addExternalRevision(), addRevision(), createDiff(), fileMove(), and RevisionDialog::populateRevisionList().

Here is the call graph for this function:

◆ getLastContentModification()

wxString FileRevisions::getLastContentModification ( const wxString &  revString)
private

This method returns the last modification revision identifier.

Parameters
revStringconst wxString&
Returns
wxString

The last content modification (no tag and no file move operation) is returned. The algorithm starts his search from the passed revision identifier string backwards in history.

Definition at line 161 of file filerevisions.cpp.

References getRevisionList().

Referenced by getRevision().

Here is the call graph for this function:

◆ getLastRevisionRoot()

wxString FileRevisions::getLastRevisionRoot ( const wxString &  revString)
private

This method returns the revision identifier of the last revision root.

Parameters
revStringconst wxString&
Returns
wxString

The revision model is based upon comparing the new revisions with a revision root and saving only the difference between those two. The root revision may change upon time, because if the difference between the root and the current item is larger than the current item, the current item is the new revision root. Revision root items are marked by the absence of any ZIP comment except of the initial revision, which is the first root

Definition at line 202 of file filerevisions.cpp.

References getRevisionList().

Referenced by createDiff().

Here is the call graph for this function:

◆ getMaxDiffFileSize()

size_t FileRevisions::getMaxDiffFileSize ( size_t  nFileSize)
private

This member function returns the maximal Diff file size.

Parameters
nFileSizesize_t The size of the stored file
Returns
size_t

Definition at line 519 of file filerevisions.cpp.

References getRevisionCount().

Referenced by addRevision().

Here is the call graph for this function:

◆ getRevision() [1/2]

wxString FileRevisions::getRevision ( size_t  nRevision)

Returns the contents of the selected revision.

Parameters
nRevisionsize_t
Returns
wxString

If the selected revision is not a content modification revision, the algorithm will search for the last previous revision containing file changes.

Definition at line 612 of file filerevisions.cpp.

References getRevision(), m_revisionPath, and toString().

Referenced by addExternalRevision(), addRevision(), compareRevisions(), createDiff(), createMerge(), getRevision(), restoreRevision(), and RevisionDialog::showRevision().

Here is the call graph for this function:

◆ getRevision() [2/2]

wxString FileRevisions::getRevision ( wxString  revString)

Returns the contents of the selected revision.

Parameters
revStringwxString
Returns
wxString

If the selected revision is not a content modification revision, the algorithm will search for the last previous revision containing file changes.

Definition at line 631 of file filerevisions.cpp.

References getLastContentModification(), m_revisionPath, and readRevision().

Here is the call graph for this function:

◆ getRevisionCount()

size_t FileRevisions::getRevisionCount ( )

Returns the number of available revisions.

Returns
size_t

Definition at line 534 of file filerevisions.cpp.

References m_revisionPath.

Referenced by createDiff(), createNewRevision(), createNewTag(), getMaxDiffFileSize(), and undoRevision().

◆ getRevisionList()

wxArrayString FileRevisions::getRevisionList ( )

This method returns a log-like list of revisions.

Returns
wxArrayString

The returned string array can be used to display a log of all revisions done to the corresponding file. The list contains actual revisions, tags and file move operations. The list contains date-time and comments of the revisions. These are tab-separated from the revision identifiers.

Definition at line 557 of file filerevisions.cpp.

References m_revisionPath.

Referenced by getCurrentRevision(), getLastContentModification(), getLastRevisionRoot(), and RevisionDialog::populateRevisionList().

◆ moveFile()

void FileRevisions::moveFile ( const wxString &  oldPath,
const wxString &  newPath,
const wxString &  newRevPath 
)

This method handles moves of the corresponding file.

Parameters
oldPathconst wxString&
newPathconst wxString&
newRevPathconst wxString&
Returns
void

This change is reflected on the revisions file, which is also moved as well.

Definition at line 885 of file filerevisions.cpp.

References fileMove().

Here is the call graph for this function:

◆ readExternalFile()

wxString FileRevisions::readExternalFile ( const wxString &  filePath)
private

This method reads an external file into a string.

Parameters
filePathconst wxString&
Returns
wxString

The method is used to include external modifications into the set of revisions, if these are actual modifications. The file is read with windows line endings (CR LF)

Definition at line 357 of file filerevisions.cpp.

Referenced by addExternalRevision().

◆ readRevision()

wxString FileRevisions::readRevision ( const wxString &  revString)
private

This method returns the contents of the selected revision.

Parameters
revStringconst wxString&
Returns
wxString

The UTF8 multi-byte characters in the ZIP file are converted automatically in wide chars during reading the file. Also, the line ending characters are converted to windows line endings (CR LF)

Definition at line 111 of file filerevisions.cpp.

References createMerge(), and m_revisionPath.

Referenced by getRevision().

Here is the call graph for this function:

◆ renameFile()

void FileRevisions::renameFile ( const wxString &  oldName,
const wxString &  newName,
const wxString &  newRevPath 
)

This method handles renames of the corresponding file.

Parameters
oldNameconst wxString&
newNameconst wxString&
newRevPathconst wxString&
Returns
void

This change is reflected on the revisions file, which is also renamed as well.

Definition at line 868 of file filerevisions.cpp.

References fileMove().

Here is the call graph for this function:

◆ restoreRevision() [1/2]

void FileRevisions::restoreRevision ( const wxString &  revString,
const wxString &  targetFile 
)

This method will restore the contents of the selected revision.

Parameters
revStringconst wxString&
targetFileconst wxString&
Returns
void

The contents of the revision are written to the file, which has been selected as second argument.

Definition at line 696 of file filerevisions.cpp.

References convertLineEndings(), createNewRevision(), and getRevision().

Here is the call graph for this function:

◆ restoreRevision() [2/2]

void FileRevisions::restoreRevision ( size_t  nRevision,
const wxString &  targetFile 
)

This method will restore the contents of the selected revision.

Parameters
nRevisionsize_t
targetFileconst wxString&
Returns
void

The contents of the revision are written to the file, which has been selected as second argument.

Definition at line 674 of file filerevisions.cpp.

References convertLineEndings(), createNewRevision(), getRevision(), and toString().

Referenced by RevisionDialog::OnMenuEvent().

Here is the call graph for this function:

◆ tagRevision() [1/2]

size_t FileRevisions::tagRevision ( const wxString &  revString,
const wxString &  tagComment 
)

Allows the user to tag a selected revision with the passed comment.

Parameters
revStringconst wxString&
tagCommentconst wxString&
Returns
size_t

Definition at line 732 of file filerevisions.cpp.

References createNewTag().

Here is the call graph for this function:

◆ tagRevision() [2/2]

size_t FileRevisions::tagRevision ( size_t  nRevision,
const wxString &  tagComment 
)

Allows the user to tag a selected revision with the passed comment.

Parameters
nRevisionsize_t
tagCommentconst wxString&
Returns
size_t

Definition at line 716 of file filerevisions.cpp.

References createNewTag(), and toString().

Referenced by RevisionDialog::OnMenuEvent().

Here is the call graph for this function:

◆ undoRevision()

void FileRevisions::undoRevision ( )

This method removes the last added revision.

Returns
void

Definition at line 822 of file filerevisions.cpp.

References COMPRESSIONLEVEL, getRevisionCount(), m_revisionPath, and toString().

Here is the call graph for this function:

◆ vectorize()

std::vector< wxString > FileRevisions::vectorize ( wxString  fileContent)
private

Converts a single-string file into a vector of strings.

Parameters
fileContentwxString
Returns
std::vector<wxString>

The file is split at the line break character so that each component of the vector is a single line of the passed file

Definition at line 55 of file filerevisions.cpp.

Referenced by createMerge(), and diff().

Member Data Documentation

◆ m_revisionPath

wxFileName FileRevisions::m_revisionPath
private

The documentation for this class was generated from the following files: