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