Added missing Workspace.cpp/h
FossilOrigin-Name: 2e7553cddf1db1c9e22e883276829a8032dc9afb
This commit is contained in:
		
							
								
								
									
										12
									
								
								manifest
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								manifest
									
									
									
									
									
								
							| @@ -1,5 +1,5 @@ | ||||
| C Renamed\sRepoFile\sto\sWorkspaceFile | ||||
| D 2015-04-30T11:29:21.110 | ||||
| C Added\smissing\sWorkspace.cpp/h | ||||
| D 2015-04-30T11:37:04.334 | ||||
| F .travis.yml 77966888a81c4ceee1fcc79bce842c9667ad8a35 | ||||
| F debian/changelog eb4304dfcb6bb66850ec740838090eb50ce1249b | ||||
| F debian/compat b6abd567fa79cbe0196d093a067271361dc6ca8b | ||||
| @@ -206,6 +206,8 @@ F src/SettingsDialog.cpp a46cff5e5dd425e3dbdd15632abfd5829f5562b4 | ||||
| F src/SettingsDialog.h 4e2790f581e991c744ae9f86580f1972b8c7ff43 | ||||
| F src/Utils.cpp f78728e0817b1db23007ba0d2c5c26980ee7ebca | ||||
| F src/Utils.h 48ca8ab324068df2bf5120c961216c297b94cb45 | ||||
| F src/Workspace.cpp dd657ecc61161e2a14e821424a76220cfd4ca8ce | ||||
| F src/Workspace.h fa11507567ee6dc336e19d18dd9574da4823ae2f | ||||
| F src/main.cpp 2ac8badc2a63fa123ceae53382ce24cfe1b5a54b | ||||
| F tools/git-push.sh 62cc58434cae5b7bcd6bd9d4cce8b08739f31cd7 x | ||||
| F tools/pack.sh d7f38a498c4e9327fecd6a6e5ac27be270d43008 x | ||||
| @@ -215,7 +217,7 @@ F ui/CommitDialog.ui 6200f6cabdcf40a20812e811be28e0793f82516f | ||||
| F ui/FileActionDialog.ui 89bb4dc2d0b8adcd41adcb11ec65f2028a09a12d | ||||
| F ui/MainWindow.ui 8677f5c8bca5bf7561d5f64bfdd0cef5157c6ac7 | ||||
| F ui/SettingsDialog.ui 2b7c2870e0054b0f4106f495d85d02c0b814df8b | ||||
| P 4c84ad9b0b25c9a77d935f9598b6705498d8e0ae | ||||
| R 09e377e3947cb9dc34273000bdb7e135 | ||||
| P 8527bab97be43b2370eb03045dee3818fa8a2edf | ||||
| R a0658af9a44eb2edc8f67837992ca8ff | ||||
| U kostas | ||||
| Z acf05986975f53be7b8c33e091697cd2 | ||||
| Z c61114eaf068b6a2a510be12e212e0db | ||||
|   | ||||
| @@ -1 +1 @@ | ||||
| 8527bab97be43b2370eb03045dee3818fa8a2edf | ||||
| 2e7553cddf1db1c9e22e883276829a8032dc9afb | ||||
							
								
								
									
										186
									
								
								src/Workspace.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										186
									
								
								src/Workspace.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,186 @@ | ||||
| #include "Workspace.h" | ||||
| #include <QCoreApplication> | ||||
| #include "Utils.h" | ||||
|  | ||||
| //----------------------------------------------------------------------------- | ||||
| Workspace::~Workspace() | ||||
| { | ||||
| 	clearState(); | ||||
| } | ||||
|  | ||||
| //------------------------------------------------------------------------------ | ||||
| void Workspace::clearState() | ||||
| { | ||||
| 	// Dispose RepoFiles | ||||
| 	foreach(WorkspaceFile *r, getFiles()) | ||||
| 		delete r; | ||||
|  | ||||
| 	getFiles().clear(); | ||||
| 	getPaths().clear(); | ||||
| } | ||||
|  | ||||
| //------------------------------------------------------------------------------ | ||||
| bool Workspace::scanDirectory(QFileInfoList &entries, const QString& dirPath, const QString &baseDir, const QString ignoreSpec, const bool &abort, Bridge::UICallback &uiCallback) | ||||
| { | ||||
| 	QDir dir(dirPath); | ||||
|  | ||||
| 	uiCallback.updateProcess(dirPath); | ||||
|  | ||||
| 	QFileInfoList list = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot); | ||||
| 	for (int i=0; i<list.count(); ++i) | ||||
| 	{ | ||||
| 		if(abort) | ||||
| 			return false; | ||||
|  | ||||
| 		QFileInfo info = list[i]; | ||||
| 		QString filepath = info.filePath(); | ||||
| 		QString rel_path = filepath; | ||||
| 		rel_path.remove(baseDir+PATH_SEPARATOR); | ||||
|  | ||||
| 		// Skip ignored files | ||||
| 		if(!ignoreSpec.isEmpty() && QDir::match(ignoreSpec, rel_path)) | ||||
| 			continue; | ||||
|  | ||||
| 		if (info.isDir()) | ||||
| 		{ | ||||
| 			if(!scanDirectory(entries, filepath, baseDir, ignoreSpec, abort, uiCallback)) | ||||
| 				return false; | ||||
| 		} | ||||
| 		else | ||||
| 			entries.push_back(info); | ||||
| 	} | ||||
| 	return true; | ||||
| } | ||||
|  | ||||
| //------------------------------------------------------------------------------ | ||||
| void Workspace::scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModified, bool scanUnchanged, const QString &ignoreGlob, Bridge::UICallback &uiCallback, bool &operationAborted) | ||||
| { | ||||
| 	// Scan all workspace files | ||||
| 	QFileInfoList all_files; | ||||
| 	QString wkdir = fossil().getCurrentWorkspace(); | ||||
|  | ||||
| 	if(wkdir.isEmpty()) | ||||
| 		return; | ||||
|  | ||||
| 	// Retrieve the status of files tracked by fossil | ||||
| 	QStringList res; | ||||
| 	if(!fossil().listFiles(res)) | ||||
| 		return; | ||||
|  | ||||
| 	bool scan_files = scanLocal; | ||||
|  | ||||
| 	clearState(); | ||||
|  | ||||
| 	operationAborted = false; | ||||
|  | ||||
| 	uiCallback.beginProcess(""); | ||||
| 	if(scan_files) | ||||
| 	{ | ||||
| 		QCoreApplication::processEvents(); | ||||
|  | ||||
| 		QString ignore; | ||||
| 		// If we should not be showing ignored files, fill in the ignored spec | ||||
| 		if(!scanIgnored) | ||||
| 		{ | ||||
| 			// QDir expects multiple specs being separated by a semicolon | ||||
| 			ignore = ignoreGlob; | ||||
| 			ignore.replace(',',';'); | ||||
| 		} | ||||
|  | ||||
| 		if(!scanDirectory(all_files, wkdir, wkdir, ignore, operationAborted, uiCallback)) | ||||
| 			goto _done; | ||||
|  | ||||
| 		for(QFileInfoList::iterator it=all_files.begin(); it!=all_files.end(); ++it) | ||||
| 		{ | ||||
| 			QString filename = it->fileName(); | ||||
| 			QString fullpath = it->absoluteFilePath(); | ||||
|  | ||||
| 			// Skip fossil files | ||||
| 			if(filename == FOSSIL_CHECKOUT1 || filename == FOSSIL_CHECKOUT2 || (!fossil().getRepositoryFile().isEmpty() && QFileInfo(fullpath) == QFileInfo(fossil().getRepositoryFile()))) | ||||
| 				continue; | ||||
|  | ||||
| 			WorkspaceFile *rf = new WorkspaceFile(*it, WorkspaceFile::TYPE_UNKNOWN, wkdir); | ||||
| 			getFiles().insert(rf->getFilePath(), rf); | ||||
| 			getPaths().insert(rf->getPath()); | ||||
| 		} | ||||
| 	} | ||||
| 	uiCallback.endProcess(); | ||||
|  | ||||
| 	uiCallback.beginProcess(QObject::tr("Updating...")); | ||||
|  | ||||
| 	// Update Files and Directories | ||||
|  | ||||
| 	for(QStringList::iterator line_it=res.begin(); line_it!=res.end(); ++line_it) | ||||
| 	{ | ||||
| 		QString line = (*line_it).trimmed(); | ||||
| 		if(line.length()==0) | ||||
| 			continue; | ||||
|  | ||||
| 		QString status_text = line.left(10).trimmed(); | ||||
| 		QString fname = line.right(line.length() - 10).trimmed(); | ||||
| 		WorkspaceFile::Type type = WorkspaceFile::TYPE_UNKNOWN; | ||||
|  | ||||
| 		// Generate a RepoFile for all non-existant fossil files | ||||
| 		// or for all files if we skipped scanning the workspace | ||||
| 		bool add_missing = !scan_files; | ||||
|  | ||||
| 		if(status_text=="EDITED") | ||||
| 			type = WorkspaceFile::TYPE_EDITTED; | ||||
| 		else if(status_text=="ADDED") | ||||
| 			type = WorkspaceFile::TYPE_ADDED; | ||||
| 		else if(status_text=="DELETED") | ||||
| 		{ | ||||
| 			type = WorkspaceFile::TYPE_DELETED; | ||||
| 			add_missing = true; | ||||
| 		} | ||||
| 		else if(status_text=="MISSING") | ||||
| 		{ | ||||
| 			type = WorkspaceFile::TYPE_MISSING; | ||||
| 			add_missing = true; | ||||
| 		} | ||||
| 		else if(status_text=="RENAMED") | ||||
| 			type = WorkspaceFile::TYPE_RENAMED; | ||||
| 		else if(status_text=="UNCHANGED") | ||||
| 			type = WorkspaceFile::TYPE_UNCHANGED; | ||||
| 		else if(status_text=="CONFLICT") | ||||
| 			type = WorkspaceFile::TYPE_CONFLICTED; | ||||
|  | ||||
| 		// Filter unwanted file types | ||||
| 		if( ((type & WorkspaceFile::TYPE_MODIFIED) && !scanModified) || | ||||
| 			((type & WorkspaceFile::TYPE_UNCHANGED) && !scanUnchanged)) | ||||
| 		{ | ||||
| 			getFiles().remove(fname); | ||||
| 			continue; | ||||
| 		} | ||||
| 		else | ||||
| 			add_missing = true; | ||||
|  | ||||
| 		Workspace::filemap_t::iterator it = getFiles().find(fname); | ||||
|  | ||||
| 		WorkspaceFile *rf = 0; | ||||
| 		if(add_missing && it==getFiles().end()) | ||||
| 		{ | ||||
| 			QFileInfo info(wkdir+QDir::separator()+fname); | ||||
| 			rf = new WorkspaceFile(info, type, wkdir); | ||||
| 			getFiles().insert(rf->getFilePath(), rf); | ||||
| 		} | ||||
|  | ||||
| 		if(!rf) | ||||
| 		{ | ||||
| 			it = getFiles().find(fname); | ||||
| 			Q_ASSERT(it!=getFiles().end()); | ||||
| 			rf = *it; | ||||
| 		} | ||||
|  | ||||
| 		rf->setType(type); | ||||
|  | ||||
| 		QString path = rf->getPath(); | ||||
| 		getPaths().insert(path); | ||||
| 	} | ||||
|  | ||||
| 	// Load the stash | ||||
| 	fossil().stashList(getStashes()); | ||||
| _done: | ||||
| 	uiCallback.endProcess(); | ||||
| } | ||||
|  | ||||
							
								
								
									
										135
									
								
								src/Workspace.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								src/Workspace.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,135 @@ | ||||
| #ifndef WORKSPACE_H | ||||
| #define WORKSPACE_H | ||||
|  | ||||
| #include <QStandardItemModel> | ||||
| #include <QFileInfo> | ||||
| #include <QDir> | ||||
| #include <QSet> | ||||
| #include <QMap> | ||||
|  | ||||
| #include "Bridge.h" | ||||
|  | ||||
| ////////////////////////////////////////////////////////////////////////// | ||||
| // RepoFile | ||||
| ////////////////////////////////////////////////////////////////////////// | ||||
| struct WorkspaceFile | ||||
| { | ||||
| 	enum Type | ||||
| 	{ | ||||
| 		TYPE_UNKNOWN		= 1<<0, | ||||
| 		TYPE_UNCHANGED		= 1<<1, | ||||
| 		TYPE_EDITTED		= 1<<2, | ||||
| 		TYPE_ADDED			= 1<<3, | ||||
| 		TYPE_DELETED		= 1<<4, | ||||
| 		TYPE_MISSING		= 1<<5, | ||||
| 		TYPE_RENAMED		= 1<<6, | ||||
| 		TYPE_CONFLICTED		= 1<<7, | ||||
| 		TYPE_MODIFIED		= TYPE_EDITTED|TYPE_ADDED|TYPE_DELETED|TYPE_MISSING|TYPE_RENAMED|TYPE_CONFLICTED, | ||||
| 		TYPE_REPO			= TYPE_UNCHANGED|TYPE_MODIFIED, | ||||
| 		TYPE_ALL			= TYPE_UNKNOWN|TYPE_REPO | ||||
| 	}; | ||||
|  | ||||
| 	WorkspaceFile(const QFileInfo &info, Type type, const QString &repoPath) | ||||
| 	{ | ||||
| 		FileInfo = info; | ||||
| 		FileType = type; | ||||
| 		FilePath = getRelativeFilename(repoPath); | ||||
| 		Path = FileInfo.absolutePath(); | ||||
|  | ||||
| 		// Strip the workspace path from the path | ||||
| 		Q_ASSERT(Path.indexOf(repoPath)==0); | ||||
| 		Path = Path.mid(repoPath.length()+1); | ||||
| 	} | ||||
|  | ||||
| 	bool isType(Type t) const | ||||
| 	{ | ||||
| 		return FileType == t; | ||||
| 	} | ||||
|  | ||||
| 	void setType(Type t) | ||||
| 	{ | ||||
| 		FileType = t; | ||||
| 	} | ||||
|  | ||||
| 	Type getType() const | ||||
| 	{ | ||||
| 		return FileType; | ||||
| 	} | ||||
|  | ||||
| 	QFileInfo getFileInfo() const | ||||
| 	{ | ||||
| 		return FileInfo; | ||||
| 	} | ||||
|  | ||||
| 	const QString &getFilePath() const | ||||
| 	{ | ||||
| 		return FilePath; | ||||
| 	} | ||||
|  | ||||
| 	QString getFilename() const | ||||
| 	{ | ||||
| 		return FileInfo.fileName(); | ||||
| 	} | ||||
|  | ||||
| 	const QString &getPath() const | ||||
| 	{ | ||||
| 		return Path; | ||||
| 	} | ||||
|  | ||||
| 	QString getRelativeFilename(const QString &path) | ||||
| 	{ | ||||
| 		QString abs_base_dir = QDir(path).absolutePath(); | ||||
|  | ||||
| 		QString relative = FileInfo.absoluteFilePath(); | ||||
| 		int index = relative.indexOf(abs_base_dir); | ||||
| 		if(index<0) | ||||
| 			return QString(""); | ||||
|  | ||||
| 		return relative.right(relative.length() - abs_base_dir.length()-1); | ||||
| 	} | ||||
|  | ||||
| private: | ||||
| 	QFileInfo	FileInfo; | ||||
| 	Type		FileType; | ||||
| 	QString		FilePath; | ||||
| 	QString		Path; | ||||
| }; | ||||
|  | ||||
|  | ||||
| typedef QSet<QString> stringset_t; | ||||
|  | ||||
| class Workspace | ||||
| { | ||||
| public: | ||||
| 	~Workspace(); | ||||
|  | ||||
| 	typedef QList<WorkspaceFile*> filelist_t; | ||||
| 	typedef QMap<QString, WorkspaceFile*> filemap_t; | ||||
|  | ||||
| 	void				clearState(); | ||||
|  | ||||
| 	Bridge &			fossil() { return bridge; } | ||||
| 	const Bridge &		fossil() const { return bridge; } | ||||
|  | ||||
| 	static bool			scanDirectory(QFileInfoList &entries, const QString& dirPath, const QString &baseDir, const QString ignoreSpec, const bool& abort, Bridge::UICallback &uiCallback); | ||||
| 	void				scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModified, bool scanUnchanged, const QString &ignoreGlob, Bridge::UICallback &uiCallback, bool &operationAborted); | ||||
|  | ||||
| 	QStandardItemModel	&getFileModel() { return repoFileModel; } | ||||
| 	QStandardItemModel	&getDirModel() { return repoDirModel; } | ||||
| 	QStandardItemModel	&getStashModel() { return repoStashModel; } | ||||
| 	filemap_t			&getFiles() { return workspaceFiles; } | ||||
| 	stringset_t			&getPaths() { return pathSet; } | ||||
| 	stashmap_t			&getStashes() { return stashMap; } | ||||
|  | ||||
| private: | ||||
| 	Bridge				bridge; | ||||
| 	filemap_t			workspaceFiles; | ||||
| 	stringset_t			pathSet; | ||||
| 	stashmap_t			stashMap; | ||||
|  | ||||
| 	QStandardItemModel	repoFileModel; | ||||
| 	QStandardItemModel	repoDirModel; | ||||
| 	QStandardItemModel	repoStashModel; | ||||
| }; | ||||
|  | ||||
| #endif // WORKSPACE_H | ||||
		Reference in New Issue
	
	Block a user