git.h

Go to the documentation of this file.
00001 /*
00002         Author: Marco Costalba (C) 2005-2006
00003 
00004         Copyright: See COPYING file that comes with this distribution
00005 
00006 */
00007 #ifndef GIT_H
00008 #define GIT_H
00009 
00010 #include "qobject.h"
00011 #include "exceptionmanager.h"
00012 #include "common.h"
00013 
00014 class QRegExp;
00015 class QTextCodec;
00016 class Annotate;
00017 class Cache;
00018 class DataLoader;
00019 class Domain;
00020 class Lanes;
00021 class MyProcess;
00022 
00023 class FileHistory {
00024 public:
00025         FileHistory();
00026         ~FileHistory();
00027         void clear(SCRef name);
00028         QString fileName;
00029         RevMap revs;
00030         Lanes* lns;
00031         StrVect revOrder;
00032         uint firstFreeLane;
00033         QPtrList<QByteArray> rowData;
00034 };
00035 
00036 class Git : public QObject {
00037 Q_OBJECT
00038 public:
00039         explicit Git(QWidget* parent);
00040 
00041         enum BoolOption { // used as self-documenting boolean parameters
00042                 optFalse,
00043                 optSaveCache,
00044                 optGoDown,
00045                 optOnlyLoaded,
00046                 optDragDrop,
00047                 optFold,
00048                 optOnlyInIndex,
00049                 optCreate
00050         };
00051 
00052         enum RefType {
00053                 TAG        = 1,
00054                 BRANCH     = 2,
00055                 RMT_BRANCH = 4,
00056                 CUR_BRANCH = 8,
00057                 REF        = 16,
00058                 APPLIED    = 32,
00059                 UN_APPLIED = 64,
00060                 ANY_REF    = 127
00061         };
00062 
00063         void checkEnvironment();
00064         void userInfo(SList info);
00065         const QString getBaseDir(bool* c, SCRef wd, bool* ok = NULL, QString* gd = NULL);
00066         bool init(SCRef workDir, bool askForRange, QStringList* filterList, bool* quit);
00067         bool stop(bool saveCache);
00068         void setThrowOnStop(bool b);
00069         bool isThrowOnStopRaised(int excpId, SCRef curContext);
00070         void setLane(SCRef sha, FileHistory* fh);
00071         Annotate* startAnnotate(FileHistory* fh, QObject* guiObj);
00072         const FileAnnotation* lookupAnnotation(Annotate* ann, SCRef fileName, SCRef sha);
00073         void cancelAnnotate(Annotate* ann);
00074         bool startFileHistory(FileHistory* fh);
00075         void cancelDataLoading(const FileHistory* fh);
00076         void cancelProcess(MyProcess* p);
00077         bool isCommittingMerge() const { return isMergeHead; }
00078         bool isStGITStack() const { return isStGIT; }
00079         bool isPatchName(SCRef nm);
00080         bool isSameFiles(SCRef tree1Sha, SCRef tree2Sha);
00081         bool isBinaryFile(SCRef file);
00082         bool isNothingToCommit();
00083         bool isUnknownFiles() const { return (_wd.otherFiles.count() > 0); }
00084         bool isTextHighlighter() const { return isTextHighlighterFound; }
00085         bool isMainHistory(const FileHistory* fh) { return (fh == &revData); }
00086         MyProcess* getDiff(SCRef sha, QObject* receiver, SCRef diffToSha, bool combined);
00087         MyProcess* getFile(SCRef file, SCRef revSha, QObject* rcv, QByteArray* ro = NULL, QString* fSha = NULL);
00088         MyProcess* getHighlightedFile(SCRef file, SCRef revSha, QObject* rcv, QString* ro = NULL);
00089         bool saveFile(SCRef fileName, SCRef sha, SCRef path);
00090         void getFileFilter(SCRef path, QMap<QString, bool>& shaMap);
00091         bool getPatchFilter(SCRef exp, bool isRegExp, QMap<QString, bool>& shaMap);
00092         const RevFile* getFiles(SCRef sha, SCRef sha2 = "", bool all = false, SCRef path = "");
00093         bool getTree(SCRef ts, SList nm, SList sha, SList type, bool wd, SCRef treePath);
00094         static const QString getLocalDate(SCRef gitDate);
00095         const QString getDesc(SCRef sha, QRegExp& shortLogRE, QRegExp& longLogRE, bool showHeader);
00096         const QString getDefCommitMsg();
00097         const QString getLaneParent(SCRef fromSHA, uint laneNum);
00098         const QStringList getChilds(SCRef parent);
00099         const QStringList getNearTags(bool goDown, SCRef sha);
00100         const QStringList getDescendantBranches(SCRef sha);
00101         const QString getShortLog(SCRef sha);
00102         const QString getTagMsg(SCRef sha);
00103         const Rev* revLookup(SCRef sha, const FileHistory* fh = NULL) const;
00104         uint checkRef(SCRef sha, uint mask = ANY_REF) const;
00105         const QString getRevInfo(SCRef sha);
00106         const QString getRefSha(SCRef refName, RefType type = ANY_REF, bool askGit = true);
00107         const QStringList getRefName(SCRef sha, RefType type, QString* curBranch = NULL) const;
00108         const QStringList getAllRefNames(uint mask, bool onlyLoaded);
00109         const QStringList getAllRefSha(uint mask);
00110         void getWorkDirFiles(SList files, SList dirs, RevFile::StatusFlag status);
00111         QTextCodec* getTextCodec(bool* isGitArchive);
00112         bool formatPatch(SCList shaList, SCRef dirPath, SCRef remoteDir = "");
00113         bool updateIndex(SCList selFiles);
00114         bool commitFiles(SCList files, SCRef msg);
00115         bool makeTag(SCRef sha, SCRef tag, SCRef msg);
00116         bool deleteTag(SCRef sha);
00117         bool applyPatchFile(SCRef patchPath, bool fold, bool sign);
00118         bool resetCommits(int parentDepth);
00119         bool stgCommit(SCList selFiles, SCRef msg, SCRef patchName, bool fold);
00120         bool stgPush(SCRef sha);
00121         bool stgPop(SCRef sha);
00122         void setTextCodec(QTextCodec* tc);
00123         void addExtraFileInfo(QString* rowName, SCRef sha, SCRef diffToSha, bool allMergeFiles);
00124         void removeExtraFileInfo(QString* rowName);
00125         void formatPatchFileHeader(QString* rowName, SCRef sha, SCRef dts, bool cmb, bool all);
00126         int findFileIndex(const RevFile& rf, SCRef name);
00127         const QString filePath(const RevFile& rf, uint i) const {
00128 
00129                 return dirNamesVec[rf.dirs[i]] + fileNamesVec[rf.names[i]];
00130         }
00131         void setCurContext(Domain* d) { curDomain = d; }
00132         Domain* curContext() const { return curDomain; }
00133 
00134 signals:
00135         void newRevsAdded(const FileHistory*, const QValueVector<QString>&);
00136         void loadCompleted(const FileHistory*, const QString&);
00137         void cancelLoading(const FileHistory*);
00138         void cancelAllProcesses();
00139         void annotateReady(Annotate*, const QString&, bool, const QString&);
00140 
00141 public slots:
00142         void on_procDataReady(const QByteArray&);
00143         void on_eof() { filesLoadingPending = filesLoadingCurSha = ""; }
00144 
00145 private slots:
00146         void loadFileNames();
00147         void on_runAsScript_eof();
00148         void on_getHighlightedFile_eof();
00149         void on_newDataReady(const FileHistory*);
00150         void on_loaded(const FileHistory*, ulong,int,bool,const QString&,const QString&);
00151 private:
00152         friend class Annotate;
00153         friend class MainImpl;
00154         friend class DataLoader;
00155         friend class ConsoleImpl;
00156         friend class RevsView;
00157 
00158         struct Reference { // stores tag information associated to a revision
00159                 Reference() : type(0) {}
00160                 uint type;
00161                 QStringList branches;
00162                 QStringList remoteBranches;
00163                 QString     currentBranch;
00164                 QStringList tags;
00165                 QStringList refs;
00166                 QString     tagObj; // TODO support more then one obj
00167                 QString     tagMsg;
00168                 QString     stgitPatch;
00169         };
00170         typedef QMap<QString, Reference> RefMap;
00171         RefMap refsShaMap;
00172 
00173         struct WorkingDirInfo {
00174                 void clear() { diffIndex = diffIndexCached = ""; otherFiles.clear(); }
00175                 QString diffIndex;
00176                 QString diffIndexCached;
00177                 QStringList otherFiles;
00178         };
00179         WorkingDirInfo _wd;
00180 
00181         bool run(SCRef cmd, QString* out = NULL, QObject* rcv = NULL, SCRef buf = "", QStringList* env = 0);
00182         bool run(QByteArray* runOutput, SCRef cmd, QObject* rcv = NULL, SCRef buf = "", QStringList* env = 0);
00183         MyProcess* runAsync(SCRef cmd, QObject* rcv, SCRef buf = "", QStringList* env = 0);
00184         MyProcess* runAsScript(SCRef cmd, QObject* rcv = NULL, SCRef buf = "", QStringList* env = 0);
00185         bool allProcessDeleted();
00186         const QStringList getArgs(bool askForRange, bool* quit);
00187         bool getRefs();
00188         void parseStGitPatches(SCList patchNames, SCList patchShas);
00189         void clearRevs();
00190         void clearFileNames();
00191         bool startRevList(SCList args, FileHistory* fh);
00192         bool startUnappliedList();
00193         bool startParseProc(SCList initCmd, FileHistory* fh);
00194         int addChunk(FileHistory* fh, const QByteArray& ba, int ofs);
00195         void parseDiffFormat(RevFile& rf, SCRef buf);
00196         void parseDiffFormatLine(RevFile& rf, SCRef line, int parNum);
00197         void getDiffIndex();
00198         const QString getFileSha(SCRef file, SCRef revSha);
00199         const Rev* fakeWorkDirRev(SCRef parent, SCRef log, SCRef longLog, int idx, FileHistory* fh);
00200         const RevFile* fakeWorkDirRevFile(const WorkingDirInfo& wd);
00201         bool copyDiffIndex(FileHistory* fh, SCRef parent);
00202         const RevFile* insertNewFiles(SCRef sha, SCRef data);
00203         const RevFile* getAllMergeFiles(const Rev* r);
00204         bool isParentOf(SCRef par, SCRef child);
00205         bool isTreeModified(SCRef sha);
00206         void indexTree();
00207         void annotateExited(Annotate* ann);
00208         void updateDescMap(const Rev* r, uint i, QMap<QPair<uint, uint>,bool>& dm,
00209                            QMap<uint, QValueVector<int> >& dv);
00210         void mergeNearTags(bool down, Rev* p, const Rev* r, const QMap<QPair<uint, uint>, bool>&dm);
00211         void mergeBranches(Rev* p, const Rev* r);
00212         void updateLanes(Rev& c, Lanes& lns, SCRef sha);
00213         static void removeFiles(SCList selFiles, SCRef workDir, SCRef ext);
00214         static void restoreFiles(SCList selFiles, SCRef workDir, SCRef ext);
00215         bool mkPatchFromIndex(SCRef msg, SCRef patchFile);
00216         const QStringList getOthersFiles();
00217         const QStringList getOtherFiles(SCList selFiles, bool onlyInIndex);
00218         static const QString colorMatch(SCRef txt, QRegExp& regExp);
00219         void appendFileName(RevFile& rf, SCRef name);
00220         void populateFileNamesMap();
00221         static const QString quote(SCRef nm);
00222         static const QString quote(SCList sl);
00223         static const QStringList noSpaceSepHack(SCRef cmd);
00224         void removeDeleted(SCList selFiles);
00225         void setStatus(RevFile& rf, SCRef rowSt);
00226         void setExtStatus(RevFile& rf, SCRef rowSt, int parNum);
00227         void appendNamesWithId(QStringList& names, SCRef sha, SCList data, bool onlyLoaded);
00228         Reference* lookupReference(SCRef sha, bool create = false);
00229 
00230         EM_DECLARE(exGitStopped);
00231 
00232         Domain* curDomain;
00233         QString workDir; // workDir is always without trailing '/'
00234         QString gitDir;
00235         QString filesLoadingPending;
00236         QString filesLoadingCurSha;
00237         QString curRange;
00238         bool cacheNeedsUpdate;
00239         bool errorReportingEnabled;
00240         bool isMergeHead;
00241         bool isStGIT;
00242         bool isGIT;
00243         bool isTextHighlighterFound;
00244         bool loadingUnAppliedPatches;
00245         bool fileCacheAccessed;
00246         int patchesStillToFind;
00247         QString firstNonStGitPatch;
00248         RevFileMap revsFiles;
00249         StrVect fileNamesVec;
00250         StrVect dirNamesVec;
00251         QMap<QString, int> fileNamesMap; // quick lookup file name
00252         QMap<QString, int> dirNamesMap;  // quick lookup directory name
00253         FileHistory revData;
00254 };
00255 
00256 #endif

Generated on Fri Dec 7 21:57:37 2007 for QGit by  doxygen 1.5.3