CFx SDK Documentation  2020SP3
TfRevisionControl.h
Go to the documentation of this file.
1 #ifndef _TFREVISIONCONTROL_H_INCLUDED_
2 #define _TFREVISIONCONTROL_H_INCLUDED_
3 
4 #include <Tf/Tf.h>
5 #include <Tf/TfIO.h>
6 #include "TfSchemaManager.h"
7 //#include "OdTfStorage.h"
8 
9 #define STL_USING_MAP
10 #include "OdaSTL.h"
11 
12 // Merge policy determines conflict resolution action, when automatic resolution fails
13 // "manual" assumes some kind of user interaction - not implemented yet
15 {
19 };
20 
21 // Structure describing a commit in revision control database
23 {
24  OdTimeStamp date; // Commit timestamp
25  OdString message; // Commit message
26  OdString author; // Commit author
27  OdArray<OdTfDigest> parents; // Parent commits (one for usual commit, several for merge (first is from the branch _into_ which the merge was done))
29  OdTfCommitInfo(const OdString& author = L"", const OdString& message = L"", const OdTimeStamp& date = OdTimeStamp(OdTimeStamp::kInitUniversalTime), OdStreamBuf* arbitraryUserData = 0);
30 };
31 
33 
35 {
36  // Open the revision control database or create an empty one
37  TFDLL_EXPORT OdTfStoragePtr open(const OdString& path, const OdString& strgClassName = L"TFSQLStorage", const OdString& appToLoad = L"TfSQLStorage");
38 
39  // Without optional parameters this function is expected to be used for the initial import (automatically switches to "master" branch)
40  // Extended version imports given database as if its current state is the next revision of the given branch
41  // (expected to be used when integrating changes made in third-party editors)
42  TFDLL_EXPORT void import(OdTfStorage* strg, OdDbDatabase* pDb, const OdString& branch = L"master", const OdTfCommitInfo& message = OdTfCommitInfo());
43 
44  // checkout: read database from storage "sourceBranch" setting "localBranch" as current for commit
45  // source branch will be saved as default merge source (like remote tracking, for 'pull')
46  // if 'partial' is false, all the objects are loaded in memory. If they will be eventually loaded anyway, it is much faster not to use 'partial' flag
47  TFDLL_EXPORT OdDbDatabasePtr checkout(OdTfStorage* strg, OdDbHostAppServices* pHostApp, const OdString& localBranch, const OdString& sourceBranch = L"master", bool partial = false);
48 
49  // checkout: create a link between an empty database and storage. Update database from storage "sourceBranch" setting "localBranch" as current for commit.
50  // if 'partial' is false, all the objects are loaded in memory. If they will be eventually loaded anyway, it is much faster not to use 'partial' flag
51  // Note: database must be empty(created by default)
52  // (this function does essentially the same as previous)
53  TFDLL_EXPORT void checkout(OdDbDatabase* pDb, OdTfStorage* strg, OdDbHostAppServices* pHostApp, const OdString& localBranch, const OdString& sourceBranch = L"master", bool partial = false);
54 
55  // commit: save changes in the database to the storage, create commit object and shift current branch
56  // Optional parameters (except the last) are for the merge commits (record the result of a merge operation)
57  // The last parameter is an optional list of objects to save (partial commit)
58  TFDLL_EXPORT void commit(OdDbDatabase* pDb, const OdTfCommitInfo& message, const OdString& mergeCommitOtherBranch = OdString::kEmpty, OdTfDigest* mergeCommitOtherParent = 0, const OdDbObjectIdArray* objectsToSave = 0);
59 
60  // Merge changes from the branch to the database.
61  // Empty branch name means "merge from the branch that this database was checked out from" (like 'git pull')
62  // returns 'false' if merge was fast forward (no merge commit necessary)
63  // merge does not automatically commit changes, only runtime database is changed
64  // if 'noFastForward' flag is true, and the remote branch is directly above or below this one in commit graph, then do nothing
65  TFDLL_EXPORT bool merge(OdDbDatabase* pDb, OdDbHandleArray& conflicts, OdTfMergePolicy mp = kOdTfMergePreferTheirs, const OdString& branch = OdString::kEmpty, bool noFastForward = false);
66 
67  // returns the commit and digest of the commit pointed by the branch
69 
71  // Collect all the changes made from one revision to another.
72  // First revision is supposed to be the ancestor of a second (not necessarily direct)
73  // This function is called on local repository to implement "git push"-like functionality
74  // together with the following "applyPatch" function.
75  // In the terms of push: "from" revision is the tip of a remote branch and "to" is a tip of a local remote tracking branch
76  // This function does not automatically fast forward local replica of a remote branch (if there is any)
78 
79  // apply on remote repository patch received from local repository (created by makePatch() above)
80  // "branch" is a name of a branch to fast forward
81  // applyPatch will fail if the branch tip is not at the same revision as the patch start (makePatch "from" parameter)
82  TFDLL_EXPORT void applyPatch(OdTfStorage* strg, OdStreamBuf* s, const OdString& branch);
83 
84  // If the database was checked out from revision control storage - return it, otherwise return 0
85  // optionally return the database current branch (commit target)
87 
88  // Set branch tip to the given hash. If no other branch points to the current top, and you don't have it saved, it will be inaccessible.
89  // If no branch with this name existed, it will be created
90  TFDLL_EXPORT void resetBranch(OdTfStorage* strg, const OdString& branch, const OdTfDigest&);
91 
92  // Switch database to specific revision, or unrelated branch (like 'git reset <commit>')
93  // Source branch is a branch we are switching to (where the data will be taken from)
94  // Local branch is a branch that we will commit to from now on (usually is equal to the source branch, unless you want to create a new one at this point)
95  // if no revision is specified, top revision of the source branch is used
96  // if no source branch is specified, the initial checkout branch is reused (consider using 'merge' instead)
97  // if local branch parameter is empty it is set to be equal to the sourceBranch
98  // if "hard" is false and there are local (non-committed) changes, operation will fail, otherwise local changes will be silently overwritten
99  TFDLL_EXPORT void switchBranch(OdDbDatabase* pDb, const OdString& sourceBranch = OdString::kEmpty, const OdString& localBranch = OdString::kEmpty, OdTfDigest* revision = 0, bool hard = true);
100 
101  // get the list of objects changed since the last commit
103 
104  // these simple wrappers over OdDbDatabase::writeFile preserve database connection to the Teigha file storage
105  // (simply calling writeFile() would sever that connection)
106  TFDLL_EXPORT void exportDwg(OdDbDatabase* pDb, OdStreamBuf* pStreamBuf, OdDb::DwgVersion fileVersion, bool saveThumbnailImage = false);
107  TFDLL_EXPORT void exportDxf(OdDbDatabase* pDb, OdStreamBuf* pStreamBuf, OdDb::DwgVersion fileVersion, bool saveThumbnailImage = false, int dxfPrecision = 16);
108 
110  {
114  };
115  typedef std::map<OdDbHandle, ChangeType> ChangeList;
116  // enumerate the handles of the differing objects between revisions (revisions may actually be unrelated)
117  TFDLL_EXPORT void getRevisionDifference(OdTfStorage* pTf, const OdTfDigest& newRevision, const OdTfDigest& oldRevision, ChangeList& result);
118 
119  // List of the branches in the revision control database
120  TFDLL_EXPORT void getBranchList(OdTfStorage* pTf, std::map<OdString, OdTfDigest>&);
121 
122 
123  //TFDLL_EXPORT OdStreamBufPtr convertToActual(OdStreamBuf* inputStream, OdStreamBuf* schemaStream, OdTfBinarySchemaIteratorImpl* pActualSchemaIt);
124 
128  TFDLL_EXPORT void compressRevisionData(OdTfStorage * strg, OdUInt16 referenceDistance = 10);
129 };
130 
131 /*
132 class TiXmlDocument;
133 class TFDLL_EXPORT OdTfSchemaManager : public OdRxObject
134 {
135  TiXmlDocument* m_pSchema;
136 public:
137  ODRX_DECLARE_MEMBERS(OdTfSchemaManager);
138  OdTfSchemaManager();
139  ~OdTfSchemaManager();
140  void registerSchema(const OdString& schema);
141  void loadFromFile(const OdString& filename);
142  TiXmlDocument* getSchema();
143 };
144 
145 typedef OdSmartPtr<OdTfSchemaManager> OdTfSchemaManagerPtr;
146 
147 TFDLL_EXPORT OdTfSchemaManagerPtr odrxGetSchemaManager();
148 */
149 
150 #endif //_TFREVISIONCONTROL_H_INCLUDED_
OdTfCommitInfo::parents
OdArray< OdTfDigest > parents
Definition: TfRevisionControl.h:27
OdTfRevisionControl::open
TFDLL_EXPORT OdTfStoragePtr open(const OdString &path, const OdString &strgClassName=L"TFSQLStorage", const OdString &appToLoad=L"TfSQLStorage")
OdTfRevisionControl::getLocalChanges
TFDLL_EXPORT OdDbObjectIdArray getLocalChanges(OdDbDatabase *pDb)
OdString
Definition: OdString.h:95
OdDbDatabase
Definition: DbDatabase.h:421
OdTfCommitInfo::OdTfCommitInfo
OdTfCommitInfo(const OdString &author=L"", const OdString &message=L"", const OdTimeStamp &date=OdTimeStamp(OdTimeStamp::kInitUniversalTime), OdStreamBuf *arbitraryUserData=0)
OdTfRevisionControl::applyPatch
TFDLL_EXPORT void applyPatch(OdTfStorage *strg, OdStreamBuf *s, const OdString &branch)
OdTfDigest
Definition: TfIO.h:9
OdTimeStamp
Definition: OdTimeStamp.h:42
TFDLL_EXPORT
#define TFDLL_EXPORT
Definition: Tf.h:41
kOdTfMergePreferMine
@ kOdTfMergePreferMine
Definition: TfRevisionControl.h:17
OdaSTL.h
kOdTfMergeManual
@ kOdTfMergeManual
Definition: TfRevisionControl.h:18
OdTfRevisionControl::getDatabaseStorage
TFDLL_EXPORT OdTfStorage * getDatabaseStorage(OdDbDatabase *pDb, OdString *currentBranch=0)
kOdTfMergePreferTheirs
@ kOdTfMergePreferTheirs
Definition: TfRevisionControl.h:16
OdArray< OdTfDigest >
OdTfCommitInfo::date
OdTimeStamp date
Definition: TfRevisionControl.h:24
OdTfRevisionControl::kObjectDeleted
@ kObjectDeleted
Definition: TfRevisionControl.h:112
OdTfCommitInfo
Definition: TfRevisionControl.h:23
OdUInt16
unsigned short OdUInt16
Definition: OdPlatformSettings.h:760
OdTfRevisionControl::exportDwg
TFDLL_EXPORT void exportDwg(OdDbDatabase *pDb, OdStreamBuf *pStreamBuf, OdDb::DwgVersion fileVersion, bool saveThumbnailImage=false)
OdTfRevisionControl::commit
TFDLL_EXPORT void commit(OdDbDatabase *pDb, const OdTfCommitInfo &message, const OdString &mergeCommitOtherBranch=OdString::kEmpty, OdTfDigest *mergeCommitOtherParent=0, const OdDbObjectIdArray *objectsToSave=0)
TfSchemaManager.h
OdTfRevisionControl::ChangeType
ChangeType
Definition: TfRevisionControl.h:110
OdTfRevisionControl::getBranchList
TFDLL_EXPORT void getBranchList(OdTfStorage *pTf, std::map< OdString, OdTfDigest > &)
OdDb::DwgVersion
DwgVersion
Definition: OdaDefs.h:46
OdTfRevisionControl::merge
TFDLL_EXPORT bool merge(OdDbDatabase *pDb, OdDbHandleArray &conflicts, OdTfMergePolicy mp=kOdTfMergePreferTheirs, const OdString &branch=OdString::kEmpty, bool noFastForward=false)
OdTimeStamp::kInitUniversalTime
@ kInitUniversalTime
Definition: OdTimeStamp.h:48
OdTfRevisionControl::resetBranch
TFDLL_EXPORT void resetBranch(OdTfStorage *strg, const OdString &branch, const OdTfDigest &)
OdSmartPtr< OdStreamBuf >
OdTfRevisionControl::kObjectAdded
@ kObjectAdded
Definition: TfRevisionControl.h:111
OdTfMergePolicy
OdTfMergePolicy
Definition: TfRevisionControl.h:15
OdTfRevisionControl::getCommitInfo
TFDLL_EXPORT OdTfCommitInfo getCommitInfo(OdTfStorage *strg, const OdTfDigest &)
OdTfCommitInfo::message
OdString message
Definition: TfRevisionControl.h:25
OdDbHostAppServices
Definition: DbHostAppServices.h:65
OdTfRevisionControl::switchBranch
TFDLL_EXPORT void switchBranch(OdDbDatabase *pDb, const OdString &sourceBranch=OdString::kEmpty, const OdString &localBranch=OdString::kEmpty, OdTfDigest *revision=0, bool hard=true)
OdTfRevisionControl::exportDxf
TFDLL_EXPORT void exportDxf(OdDbDatabase *pDb, OdStreamBuf *pStreamBuf, OdDb::DwgVersion fileVersion, bool saveThumbnailImage=false, int dxfPrecision=16)
OdTfRevisionControl::checkout
TFDLL_EXPORT OdDbDatabasePtr checkout(OdTfStorage *strg, OdDbHostAppServices *pHostApp, const OdString &localBranch, const OdString &sourceBranch=L"master", bool partial=false)
OdTfCommitInfo::author
OdString author
Definition: TfRevisionControl.h:26
OdTfRevisionControl::ChangeList
std::map< OdDbHandle, ChangeType > ChangeList
Definition: TfRevisionControl.h:115
OdTfRevisionControl
Definition: TfRevisionControl.h:35
OdStreamBuf
Definition: OdStreamBuf.h:67
OdTfRevisionControl::makePatch
TFDLL_EXPORT OdStreamBufPtr makePatch(OdTfStorage *strg, const OdTfDigest &from, const OdTfDigest &to)
OdTfCommitInfo::userData
OdStreamBufPtr userData
Definition: TfRevisionControl.h:28
OdTfRevisionControl::getRevisionDifference
TFDLL_EXPORT void getRevisionDifference(OdTfStorage *pTf, const OdTfDigest &newRevision, const OdTfDigest &oldRevision, ChangeList &result)
OdString::kEmpty
FIRSTDLL_EXPORT_STATIC static const OdString kEmpty
Definition: OdString.h:98
Tf.h
OdTfRevisionControl::kObjectModified
@ kObjectModified
Definition: TfRevisionControl.h:113
OdTfRevisionControl::compressRevisionData
TFDLL_EXPORT void compressRevisionData(OdTfStorage *strg, OdUInt16 referenceDistance=10)
TfIO.h
OdDbHandleArray
OdArray< OdDbHandle > OdDbHandleArray
Definition: TfRevisionControl.h:32
OdTfStorage
Definition: TfIO.h:56
OdTfRevisionControl::getBranchTip
TFDLL_EXPORT void getBranchTip(OdTfStorage *strg, const OdString &branch, OdTfCommitInfo &, OdTfDigest &)