1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
/*
Author: Marco Costalba (C) 2005-2007
Copyright: See COPYING file that comes with this distribution
*/
#ifndef GIT_H
#define GIT_H
#include "exceptionmanager.h"
#include "common.h"
class QRegularExpression;
class QTextCodec;
class Annotate;
//class DataLoader;
class Domain;
class FileHistory;
class Lanes;
class MyProcess;
class Git : public QObject {
Q_OBJECT
public:
explicit Git(QObject* parent);
// used as self-documenting boolean parameters
static const bool optSaveCache = true;
static const bool optGoDown = true; //CT TODO private, enum
static const bool optOnlyLoaded = true;
static const bool optDragDrop = true;
static const bool optFold = true;
static const bool optAmend = true; //CT TODO enum
static const bool optOnlyInIndex = true; //CT TODO private, enum
static const int shortHashLenDefault = 7;
enum RefType {
TAG = 1,
BRANCH = 2,
RMT_BRANCH = 4,
CUR_BRANCH = 8,
REF = 16,
APPLIED = 32,
UN_APPLIED = 64,
ANY_REF = 127
};
struct TreeEntry {
TreeEntry(SCRef n, SCRef s, SCRef t) : name(n), sha(s), type(t) {}
bool operator<(const TreeEntry&) const;
QString name;
QString sha;
QString type;
};
typedef QList<TreeEntry> TreeInfo;
void setDefaultModel(FileHistory* fh) { revData = fh; }
void checkEnvironment();
void userInfo(SList info);
const QStringList getGitConfigList(bool global);
bool getGitDBDir(SCRef wd, QString& gd, bool& changed);
bool getBaseDir(SCRef wd, QString& bd, bool& changed);
bool init(SCRef wd, bool range, const QStringList* args, bool overwrite, bool* quit);
void stop(bool saveCache);
void setThrowOnStop(bool b);
bool isThrowOnStopRaised(int excpId, SCRef curContext);
void setLane(SCRef sha, FileHistory* fh);
Annotate* startAnnotate(FileHistory* fh, QObject* guiObj);
const FileAnnotation* lookupAnnotation(Annotate* ann, SCRef sha);
void cancelAnnotate(Annotate* ann);
bool startFileHistory(SCRef sha, SCRef startingFileName, FileHistory* fh);
void cancelDataLoading(const FileHistory* fh);
void cancelProcess(MyProcess* p);
bool isCommittingMerge() const { return isMergeHead; }
bool isStGITStack() const { return isStGIT; }
bool isPatchName(SCRef nm);
bool isSameFiles(SCRef tree1Sha, SCRef tree2Sha);
static bool isImageFile(SCRef file);
static bool isBinaryFile(SCRef file);
bool isNothingToCommit();
bool isUnknownFiles() const { return (workingDirInfo.otherFiles.count() > 0); }
bool isTextHighlighter() const { return isTextHighlighterFound; }
const QString textHighlighterVersion() const { return textHighlighterVersionFound; }
bool isMainHistory(const FileHistory* fh) { return (fh == revData); }
bool isContiguous(const QStringList &revs);
MyProcess* getDiff(SCRef sha, QObject* receiver, SCRef diffToSha, bool combined);
const QString getWorkDirDiff(SCRef fileName = "");
MyProcess* getFile(SCRef fileSha, QObject* receiver, QByteArray* result, SCRef fileName);
MyProcess* getHighlightedFile(SCRef fileSha, QObject* receiver, QString* result, SCRef fileName);
const QString getFileSha(SCRef file, SCRef revSha);
bool saveFile(SCRef fileSha, SCRef fileName, SCRef path);
void getFileFilter(SCRef path, ShaSet& shaSet) const;
bool getPatchFilter(SCRef exp, bool isRegExp, ShaSet& shaSet);
const RevFile* getFiles(SCRef sha, SCRef sha2 = "", bool all = false, SCRef path = "");
bool getTree(SCRef ts, TreeInfo& ti, bool wd, SCRef treePath);
static const QString getLocalDate(SCRef gitDate);
const QString getCurrentBranchName() const {return curBranchName;}
const QString getDesc(SCRef sha, QRegularExpression& slogRE, QRegularExpression& lLogRE, bool showH, FileHistory* fh);
const QString getLastCommitMsg();
const QString getNewCommitMsg();
const QString getLaneParent(SCRef fromSHA, int laneNum);
const QStringList getChildren(SCRef parent);
const QStringList getNearTags(bool goDown, SCRef sha);
const QStringList getDescendantBranches(SCRef sha, bool shaOnly = false);
const QString getShortLog(SCRef sha);
const QString getTagMsg(SCRef sha);
const Rev* revLookup(const ShaString& sha, const FileHistory* fh = NULL) const;
const Rev* revLookup(SCRef sha, const FileHistory* fh = NULL) const;
uint checkRef(const ShaString& sha, uint mask = ANY_REF) const;
uint checkRef(SCRef sha, uint mask = ANY_REF) const;
const QString getRevInfo(SCRef sha);
int getShortHashLength();
const QString getRefSha(SCRef refName, RefType type = ANY_REF, bool askGit = true);
const QStringList getRefNames(SCRef sha, uint mask = ANY_REF) const;
const QStringList getAllRefNames(uint mask, bool onlyLoaded);
const QStringList getAllRefSha(uint mask);
const QStringList sortShaListByIndex(SCList shaList);
//const QString refAsShortHash(SCRef sha);
void getWorkDirFiles(SList files, SList dirs, RevFile::StatusFlag status);
QTextCodec* getTextCodec(bool* isGitArchive);
bool formatPatch(SCList shaList, SCRef dirPath, SCRef remoteDir = "");
bool updateIndex(SCList selFiles);
bool commitFiles(SCList files, SCRef msg, bool amend);
bool applyPatchFile(SCRef patchPath, bool fold, bool sign);
bool resetCommits(int parentDepth);
bool merge(SCRef into, SCList sources, QString* error=NULL);
bool stgCommit(SCList selFiles, SCRef msg, SCRef patchName, bool fold);
bool stgPush(SCRef sha);
bool stgPop(SCRef sha);
void setTextCodec(QTextCodec* tc);
void addExtraFileInfo(QString* rowName, SCRef sha, SCRef diffToSha, bool allMergeFiles);
void removeExtraFileInfo(QString* rowName);
void formatPatchFileHeader(QString* rowName, SCRef sha, SCRef dts, bool cmb, bool all);
int findFileIndex(const RevFile& rf, SCRef name);
const QString filePath(const RevFile& rf, uint i) const {
return dirNamesVec[rf.dirAt(i)] + fileNamesVec[rf.nameAt(i)];
}
int shortHashLength() const { return shortHashLen; }
void setCurContext(Domain* d) { curDomain = d; }
Domain* curContext() const { return curDomain; }
signals:
void newRevsAdded(const FileHistory*, const QVector<ShaString>&);
void loadCompleted(const FileHistory*, const QString&);
void cancelLoading(const FileHistory*);
void cancelAllProcesses();
void annotateReady(Annotate*, bool, const QString&);
void fileNamesLoad(int, int);
void changeFont(const QFont&);
public slots:
void procReadyRead(const QByteArray&);
void procFinished();
private slots:
void loadFileCache();
void loadFileNames();
void on_runAsScript_eof();
void on_getHighlightedFile_eof();
void on_newDataReady(const FileHistory*);
void on_loaded(FileHistory*, ulong,int,bool,const QString&,const QString&);
private:
friend class MainImpl;
friend class DataLoader;
friend class ConsoleImpl;
friend class RevsView;
struct Reference { // stores tag information associated to a revision
Reference() : type(0) {}
uint type;
QStringList branches;
QStringList remoteBranches;
QStringList tags;
QStringList refs;
QString tagObj; // TODO support more then one obj
QString tagMsg;
QString stgitPatch;
};
typedef QHash<ShaString, Reference> RefMap;
struct WorkingDirInfo {
void clear() { diffIndex = diffIndexCached = ""; otherFiles.clear(); }
QString diffIndex;
QString diffIndexCached;
QStringList otherFiles;
};
WorkingDirInfo workingDirInfo;
struct LoadArguments { // used to pass arguments to init2()
QStringList args;
bool filteredLoading;
QStringList filterList;
};
LoadArguments loadArguments;
struct FileNamesLoader {
FileNamesLoader() : rf(NULL) {}
RevFile* rf;
QVector<int> rfDirs;
QVector<int> rfNames;
};
FileNamesLoader fileLoader;
void init2();
bool run(SCRef cmd, QString* out = NULL, QObject* rcv = NULL, SCRef buf = "");
bool run(QByteArray* runOutput, SCRef cmd, QObject* rcv = NULL, SCRef buf = "");
MyProcess* runAsync(SCRef cmd, QObject* rcv, SCRef buf = "");
MyProcess* runAsScript(SCRef cmd, QObject* rcv = NULL, SCRef buf = "");
const QStringList getArgs(bool* quit, bool repoChanged);
bool getRefs();
void parseStGitPatches(SCList patchNames, SCList patchShas);
void clearRevs();
void clearFileNames();
bool startRevList(SCList args, FileHistory* fh);
bool startUnappliedList();
bool startParseProc(SCList initCmd, FileHistory* fh, SCRef buf);
bool tryFollowRenames(FileHistory* fh);
bool populateRenamedPatches(SCRef sha, SCList nn, FileHistory* fh, QStringList* on, bool bt);
bool filterEarlyOutputRev(FileHistory* fh, Rev* rev);
int addChunk(FileHistory* fh, const QByteArray& ba, int ofs);
void parseDiffFormat(RevFile& rf, SCRef buf, FileNamesLoader& fl);
void parseDiffFormatLine(RevFile& rf, SCRef line, int parNum, FileNamesLoader& fl);
void getDiffIndex();
Rev* fakeRevData(SCRef sha, SCList parents, SCRef author, SCRef date, SCRef log,
SCRef longLog, SCRef patch, int idx, FileHistory* fh);
const Rev* fakeWorkDirRev(SCRef parent, SCRef log, SCRef longLog, int idx, FileHistory* fh);
const RevFile* fakeWorkDirRevFile(const WorkingDirInfo& wd);
bool copyDiffIndex(FileHistory* fh, SCRef parent);
const RevFile* insertNewFiles(SCRef sha, SCRef data);
const RevFile* getAllMergeFiles(const Rev* r);
bool runDiffTreeWithRenameDetection(SCRef runCmd, QString* runOutput);
bool isParentOf(SCRef par, SCRef child);
bool isTreeModified(SCRef sha);
void indexTree();
void updateDescMap(const Rev* r, uint i, QHash<QPair<uint, uint>,bool>& dm,
QHash<uint, QVector<int> >& dv);
void mergeNearTags(bool down, Rev* p, const Rev* r, const QHash<QPair<uint, uint>, bool>&dm);
void mergeBranches(Rev* p, const Rev* r);
void updateLanes(Rev& c, Lanes& lns, SCRef sha);
bool mkPatchFromWorkDir(SCRef msg, SCRef patchFile, SCList files);
const QStringList getOthersFiles();
const QStringList getOtherFiles(SCList selFiles, bool onlyInIndex);
const QString getNewestFileName(SCList args, SCRef fileName);
static const QString colorMatch(SCRef txt, QRegularExpression& regExp);
void appendFileName(RevFile& rf, SCRef name, FileNamesLoader& fl);
void flushFileNames(FileNamesLoader& fl);
void populateFileNamesMap();
const QString formatList(SCList sl, SCRef name, bool inOneLine = true);
static const QString quote(SCRef nm);
static const QString quote(SCList sl);
static const QStringList noSpaceSepHack(SCRef cmd);
void removeDeleted(SCList selFiles);
void setStatus(RevFile& rf, SCRef rowSt);
void setExtStatus(RevFile& rf, SCRef rowSt, int parNum, FileNamesLoader& fl);
void appendNamesWithId(QStringList& names, SCRef sha, SCList data, bool onlyLoaded);
Reference* lookupReference(const ShaString& sha);
Reference* lookupOrAddReference(const ShaString& sha);
EM_DECLARE(exGitStopped);
Domain* curDomain;
QString workDir; // workDir is always without trailing '/'
QString gitDir;
QString filesLoadingPending;
QString filesLoadingCurSha;
QString curBranchName;
int filesLoadingStartOfs;
bool cacheNeedsUpdate;
bool errorReportingEnabled;
bool isMergeHead;
bool isStGIT;
bool isGIT;
bool isTextHighlighterFound;
QString textHighlighterVersionFound;
bool loadingUnAppliedPatches;
bool fileCacheAccessed;
int patchesStillToFind;
int shortHashLen;
QString firstNonStGitPatch;
RevFileMap revsFiles;
QVector<QByteArray> revsFilesShaBackupBuf;
RefMap refsShaMap;
QVector<QByteArray> shaBackupBuf;
StrVect fileNamesVec;
StrVect dirNamesVec;
QHash<QString, int> fileNamesMap; // quick lookup file name
QHash<QString, int> dirNamesMap; // quick lookup directory name
FileHistory* revData;
};
#endif
|