CFx SDK Documentation  2022 SP0
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_
unsigned short OdUInt16
#define TFDLL_EXPORT
Definition: Tf.h:41
OdArray< OdDbHandle > OdDbHandleArray
OdTfMergePolicy
@ kOdTfMergePreferTheirs
@ kOdTfMergeManual
@ kOdTfMergePreferMine
FIRSTDLL_EXPORT_STATIC static const OdString kEmpty
Definition: OdString.h:98
@ kInitUniversalTime
Definition: OdTimeStamp.h:48
DwgVersion
Definition: OdaDefs.h:46
TFDLL_EXPORT void exportDwg(OdDbDatabase *pDb, OdStreamBuf *pStreamBuf, OdDb::DwgVersion fileVersion, bool saveThumbnailImage=false)
TFDLL_EXPORT void compressRevisionData(OdTfStorage *strg, OdUInt16 referenceDistance=10)
TFDLL_EXPORT void getBranchTip(OdTfStorage *strg, const OdString &branch, OdTfCommitInfo &, OdTfDigest &)
TFDLL_EXPORT OdDbDatabasePtr checkout(OdTfStorage *strg, OdDbHostAppServices *pHostApp, const OdString &localBranch, const OdString &sourceBranch=L"master", bool partial=false)
TFDLL_EXPORT void applyPatch(OdTfStorage *strg, OdStreamBuf *s, const OdString &branch)
TFDLL_EXPORT OdDbObjectIdArray getLocalChanges(OdDbDatabase *pDb)
std::map< OdDbHandle, ChangeType > ChangeList
TFDLL_EXPORT void getRevisionDifference(OdTfStorage *pTf, const OdTfDigest &newRevision, const OdTfDigest &oldRevision, ChangeList &result)
TFDLL_EXPORT void exportDxf(OdDbDatabase *pDb, OdStreamBuf *pStreamBuf, OdDb::DwgVersion fileVersion, bool saveThumbnailImage=false, int dxfPrecision=16)
TFDLL_EXPORT bool merge(OdDbDatabase *pDb, OdDbHandleArray &conflicts, OdTfMergePolicy mp=kOdTfMergePreferTheirs, const OdString &branch=OdString::kEmpty, bool noFastForward=false)
TFDLL_EXPORT void switchBranch(OdDbDatabase *pDb, const OdString &sourceBranch=OdString::kEmpty, const OdString &localBranch=OdString::kEmpty, OdTfDigest *revision=0, bool hard=true)
TFDLL_EXPORT OdTfStoragePtr open(const OdString &path, const OdString &strgClassName=L"TFSQLStorage", const OdString &appToLoad=L"TfSQLStorage")
TFDLL_EXPORT void resetBranch(OdTfStorage *strg, const OdString &branch, const OdTfDigest &)
TFDLL_EXPORT void commit(OdDbDatabase *pDb, const OdTfCommitInfo &message, const OdString &mergeCommitOtherBranch=OdString::kEmpty, OdTfDigest *mergeCommitOtherParent=0, const OdDbObjectIdArray *objectsToSave=0)
TFDLL_EXPORT void getBranchList(OdTfStorage *pTf, std::map< OdString, OdTfDigest > &)
TFDLL_EXPORT OdTfCommitInfo getCommitInfo(OdTfStorage *strg, const OdTfDigest &)
TFDLL_EXPORT OdTfStorage * getDatabaseStorage(OdDbDatabase *pDb, OdString *currentBranch=0)
TFDLL_EXPORT OdStreamBufPtr makePatch(OdTfStorage *strg, const OdTfDigest &from, const OdTfDigest &to)
OdTimeStamp date
OdTfCommitInfo(const OdString &author=L"", const OdString &message=L"", const OdTimeStamp &date=OdTimeStamp(OdTimeStamp::kInitUniversalTime), OdStreamBuf *arbitraryUserData=0)
OdStreamBufPtr userData
OdArray< OdTfDigest > parents
Definition: TfIO.h:9