File: git.h

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (249 lines) | stat: -rw-r--r-- 8,560 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 The CodeLite Team
// file name            : git.h
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2011 by René Kraus (aka upCASE)
//
//////////////////////////////////////////////////////////////////////////////

#ifndef __git__
#define __git__

#include <wx/progdlg.h>

#include "plugin.h"
#include "asyncprocess.h"
#include "processreaderthread.h"
#include <queue>
#include <set>
#include <wx/progdlg.h>
#include "project.h" // wxStringSet_t
#include <map>
#include "overlaytool.h"
#include "cl_command_event.h"
#include "gitentry.h"

class gitAction
{
public:
    int action;
    wxString arguments;
    wxString workingDirectory;

public:
    gitAction() : action(0), arguments(""), workingDirectory("") {}
    gitAction(int act, const wxString &args) : action(act), arguments(args) {}
    ~gitAction() {}
};
class GitConsole;
class GitCommitListDlg;

class GitPlugin : public IPlugin
{
    typedef std::map<int, int> IntMap_t;
    enum {
        gitNone = 0,
        gitUpdateRemotes,
        gitListAll,
        gitListModified,
        gitListRemotes,
        gitAddFile,
        gitDeleteFile,
        gitDiffFile,
        gitDiffRepoCommit,
        gitDiffRepoShow,
        gitResetFile,
        gitResetRepo,
        gitPull,
        gitPush,
        gitCommit,
        gitBranchCreate,
        gitBranchCurrent,
        gitBranchList,
        gitBranchListRemote,
        gitBranchSwitch,
        gitBranchSwitchRemote,
        gitCommitList,
        gitRebase,
        gitGarbageCollection,
        gitClone,
        gitStatus,
        gitUndoAdd,
        gitRmFiles,
        gitApplyPatch,
        gitRevertCommit,
        gitStash,
        gitStashPop,
    };

    wxArrayString           m_localBranchList;
    wxArrayString           m_remoteBranchList;
    wxStringSet_t           m_trackedFiles;
    wxStringSet_t           m_modifiedFiles;
    bool                    m_addedFiles;
    wxArrayString           m_remotes;
    wxColour                m_colourTrackedFile;
    wxColour                m_colourDiffFile;
    wxString                m_pathGITExecutable;
    wxString                m_pathGITKExecutable;
    wxString                m_repositoryDirectory;
    wxString                m_currentBranch;
    std::queue<gitAction>   m_gitActionQueue;
    wxTimer                 m_progressTimer;
    wxString                m_progressMessage;
    wxString                m_commandOutput;
    bool                    m_bActionRequiresTreUpdate;
    IProcess *              m_process;
    wxEvtHandler *          m_eventHandler;
    wxWindow *              m_topWindow;
    clToolBar*              m_pluginToolbar;
    wxMenu*                 m_pluginMenu;
    GitImages               m_images;
    IntMap_t                m_treeImageMapping;
    int                     m_baseImageCount;
    GitConsole *            m_console;
    wxFileName              m_workspaceFilename;
    GitCommitListDlg *      m_commitListDlg;
    
private:
    void DoCreateTreeImages();
    void DoShowDiffViewer(const wxString &headFile, const wxString& fileName);
    
    void DoSetTreeItemImage(wxTreeCtrl* ctrl, const wxTreeItemId& item, OverlayTool::BmpType bmpType ) const;
    void InitDefaults();
    void AddDefaultActions();
    void LoadDefaultGitCommands(GitEntry& data, bool overwrite = false);
    void ProcessGitActionQueue();
    void ColourFileTree(wxTreeCtrl *tree, const wxStringSet_t& files, OverlayTool::BmpType bmpType) const;
    void CreateFilesTreeIDsMap(std::map<wxString, wxTreeItemId>& IDs, bool ifmodified = false) const;
    
    /// Workspace management
    bool IsWorkspaceOpened() const;
    wxString GetWorkspaceName() const;
    wxFileName GetWorkspaceFileName() const;
    
    void FinishGitListAction(const gitAction& ga);
    void ListBranchAction(const gitAction& ga);
    void GetCurrentBranchAction(const gitAction& ga);
    void UpdateFileTree();

    void ShowProgress(const wxString& message, bool pulse = true);
    void HideProgress();
    void DoCleanup();
    void DoAddFiles(const wxArrayString &files);
    void DoResetFiles(const wxArrayString &files);
    void DoGetFileViewSelectedFiles( wxArrayString &files, bool relativeToRepo );
    void DoShowDiffsForFiles(const wxArrayString &files);
    
    DECLARE_EVENT_TABLE()
    
    // Event handlers
    void OnInitDone(wxCommandEvent& e);
    void OnProgressTimer(wxTimerEvent& Event);
    void OnProcessTerminated(wxCommandEvent &event);
    void OnProcessOutput(wxCommandEvent &event);

    void OnFileSaved(clCommandEvent& e);
    void OnFilesAddedToProject(clCommandEvent& e);
    void OnFilesRemovedFromProject(clCommandEvent& e);
    void OnWorkspaceLoaded(wxCommandEvent& e);
    void OnWorkspaceClosed(wxCommandEvent &e);
    void OnWorkspaceConfigurationChanged(wxCommandEvent &e);
    void OnSetGitRepoPath(wxCommandEvent &e);
    void OnSettings(wxCommandEvent &e);
    void OnFileDiffSelected(wxCommandEvent &e);
    void OnFileResetSelected(wxCommandEvent &e);
    void OnFileAddSelected(wxCommandEvent &e);
    void OnFileDeleteSelected(wxCommandEvent &e);
    void OnSwitchLocalBranch(wxCommandEvent &e);
    void OnSwitchRemoteBranch(wxCommandEvent &e);
    void OnCreateBranch(wxCommandEvent &e);
    void OnCommit(wxCommandEvent &e);
    void OnCommitList(wxCommandEvent& e);
    void OnShowDiffs(wxCommandEvent& e);
    void OnApplyPatch(wxCommandEvent& e);
    void OnPush(wxCommandEvent &e);
    void OnPull(wxCommandEvent &e);
    void OnResetRepository(wxCommandEvent &e);
    void OnStartGitk(wxCommandEvent& e);
    void OnStartGitkUI(wxUpdateUIEvent& e);
    void OnListModified(wxCommandEvent& e);
    void OnRefresh(wxCommandEvent& e);
    void OnGarbageColletion(wxCommandEvent& e);
#if 0
    void OnBisectStart(wxCommandEvent& e);
    void OnBisectGood(wxCommandEvent& e);
    void OnBisectBad(wxCommandEvent& e);
    void OnBisectReset(wxCommandEvent& e);
#endif
    void OnEnableGitRepoExists(wxUpdateUIEvent &e);
    void OnClone(wxCommandEvent &e);

public:
    GitPlugin(IManager *manager);
    ~GitPlugin();

    const wxString& GetRepositoryDirectory() const {
        return m_repositoryDirectory;
    }
    IProcess* GetProcess() {
        return m_process;
    }

    IManager* GetManager() {
        return m_mgr;
    }
    
    void ShowDiff(const wxArrayString &files) {
        DoShowDiffsForFiles(files);
    }
    
    void ApplyPatch(const wxString &filename, const wxString &extraFlags);
    void AddFiles(const wxArrayString &files) {
        DoAddFiles(files);
    }
    
    void RevertCommit(const wxString &commitId);
    
    void ResetFiles(const wxArrayString &files) {
        DoResetFiles(files);
    }

    void UndoAddFiles(const wxArrayString& files);

    void RefreshFileListView();

    //--------------------------------------------
    //Abstract methods
    //--------------------------------------------
    virtual clToolBar *CreateToolBar(wxWindow *parent);
    virtual void CreatePluginMenu(wxMenu *pluginsMenu);
    virtual void HookPopupMenu(wxMenu *menu, MenuType type);
    virtual void UnPlug();
};

#endif //git