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 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2014 Eran Ifrah
// 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 "asyncprocess.h"
#include "clCodeLiteRemoteProcess.hpp"
#include "clTabTogglerHelper.h"
#include "cl_command_event.h"
#include "gitentry.h"
#include "gitui.h"
#include "ieditor.h"
#include "overlaytool.h"
#include "plugin.h"
#include "processreaderthread.h"
#include "project.h" // wxStringSet_t
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <wx/progdlg.h>
class clTreeCtrl;
class clCommandProcessor;
class GitBlameDlg;
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;
struct GitCmd {
wxString baseCommand;
size_t processFlags;
GitCmd(const wxString& cmd, size_t console)
: baseCommand(cmd)
, processFlags(console)
{
}
GitCmd()
: processFlags(IProcessCreateDefault)
{
}
typedef std::vector<GitCmd> Vec_t;
};
class GitPlugin : public IPlugin
{
friend class GitConsole;
friend class GitCommitListDlg;
friend class GitCommitDlg;
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,
gitBlame,
gitBlameSummary,
gitRevlist,
gitRebase,
gitGarbageCollection,
gitClone,
gitStatus,
gitUndoAdd,
gitRmFiles,
gitApplyPatch,
gitRevertCommit,
gitStash,
gitStashPop,
gitConfig,
};
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_userEnteredRepositoryDirectory;
wxString m_currentBranch;
std::list<gitAction> m_gitActionQueue;
wxTimer m_progressTimer;
wxString m_progressMessage;
wxString m_commandOutput;
bool m_bActionRequiresTreUpdate;
IProcess* m_process;
wxEvtHandler* m_eventHandler;
clToolBar* m_pluginToolbar;
wxMenu* m_pluginMenu;
IntMap_t m_treeImageMapping;
int m_baseImageCount;
GitConsole* m_console;
wxString m_workspace_file;
GitCommitListDlg* m_commitListDlg;
wxArrayString m_filesSelected;
wxString m_selectedFolder;
clCommandProcessor* m_commandProcessor;
clTabTogglerHelper::Ptr_t m_tabToggler;
GitBlameDlg* m_gitBlameDlg;
std::unordered_map<wxString, std::vector<wxString>>
m_blameMap; // contains file: comment per line (extracted from the 'git blame' info)
size_t m_configFlags = 0;
wxString m_lastBlameMessage;
bool m_isRemoteWorkspace = false;
wxString m_remoteWorkspaceAccount;
clCodeLiteRemoteProcess m_remoteProcess;
wxString m_codeliteRemoteScriptPath;
private:
void StartCodeLiteRemote();
void ClearCodeLiteRemoteInfo();
void DoCreateTreeImages();
void DoShowDiffViewer(const wxString& headFile, const wxString& fileName);
void DoExecuteCommands(const GitCmd::Vec_t& commands, const wxString& workingDir);
bool DoExecuteCommandSync(const wxString& command, wxString* commandOutput,
const wxString& workingDir = wxEmptyString);
void DoSetTreeItemImage(clTreeCtrl* ctrl, const wxTreeItemId& item, OverlayTool::BmpType bmpType) const;
void InitDefaults();
void AddDefaultActions();
void LoadDefaultGitCommands(GitEntry& data, bool overwrite = false);
void ProcessGitActionQueue();
void ColourFileTree(clTreeCtrl* tree, const wxStringSet_t& files, OverlayTool::BmpType bmpType) const;
void CreateFilesTreeIDsMap(std::map<wxString, wxTreeItemId>& IDs, bool ifmodified = false) const;
void DoShowCommitDialog(const wxString& diff, wxString& commitArgs);
void DoRefreshView(bool ensureVisible);
/// Workspace management
bool IsWorkspaceOpened() const;
wxString GetCommitMessageFile() const;
wxString FindRepositoryRoot(const wxString& starting_dir) 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, bool useFileAsBase = false);
void DoSetRepoPath(const wxString& repo_path = wxEmptyString);
void DoRecoverFromGitCommandError(bool clear_queue = true);
void DoLoadBlameInfo(bool clearCache);
void DoUpdateBlameInfo(const wxString& info, const wxString& fullpath);
void DoAnyFileModified();
DECLARE_EVENT_TABLE()
// Event handlers
void OnProgressTimer(wxTimerEvent& Event);
void OnProcessTerminated(clProcessEvent& event);
void OnProcessOutput(clProcessEvent& event);
void OnFileMenu(clContextMenuEvent& event);
void OnFolderMenu(clContextMenuEvent& event);
void OnFileCreated(clFileSystemEvent& event);
void OnReplaceInFiles(clFileSystemEvent& event);
void OnEditorChanged(wxCommandEvent& event);
void OnFileSaved(clCommandEvent& e);
void OnFileModifiedExternally(clFileSystemEvent& e);
void OnFilesAddedToProject(clCommandEvent& e);
void OnFilesRemovedFromProject(clCommandEvent& e);
void OnWorkspaceLoaded(clWorkspaceEvent& e);
void OnWorkspaceClosed(clWorkspaceEvent& e);
void OnWorkspaceConfigurationChanged(wxCommandEvent& e);
void OnMainFrameTitle(clCommandEvent& 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 OnRebase(wxCommandEvent& e);
void OnPull(wxCommandEvent& e);
void OnResetRepository(wxCommandEvent& e);
void OnStartGitk(wxCommandEvent& e);
void OnStartGitkUI(wxUpdateUIEvent& e);
void OnListModified(wxCommandEvent& e);
void OnGitBlame(wxCommandEvent& e);
void OnRefresh(wxCommandEvent& e);
void OnGarbageColletion(wxCommandEvent& e);
void OnOpenMSYSGit(wxCommandEvent& e);
void OnActiveProjectChanged(clProjectSettingsEvent& event);
void OnFileCommitListSelected(wxCommandEvent& e);
void OnFileGitBlame(wxCommandEvent& event);
void OnAppActivated(wxCommandEvent& event);
void OnUpdateNavBar(clCodeCompletionEvent& event);
void OnEditorClosed(wxCommandEvent& event);
void OnEnableGitRepoExists(wxUpdateUIEvent& e);
void OnClone(wxCommandEvent& e);
void OnSftpFileSaved(clCommandEvent& event);
// Event handlers from folder context menu
void OnFolderPullRebase(wxCommandEvent& event);
void OnFolderCommit(wxCommandEvent& event);
void OnFolderPush(wxCommandEvent& event);
void OnFolderStash(wxCommandEvent& event);
void OnFolderStashPop(wxCommandEvent& event);
void OnFolderGitBash(wxCommandEvent& event);
// Respond to local events
void OnGitActionDone(clSourceControlEvent& event);
bool HandleErrorsOnRemoteRepo(const wxString& output) const;
// Remote callbacks
void OnFindPath(clCommandEvent& event);
public:
GitPlugin(IManager* manager);
virtual ~GitPlugin();
const wxString& GetRepositoryPath() const { return m_repositoryDirectory; }
void WorkspaceClosed();
bool IsRemoteWorkspace() const { return m_isRemoteWorkspace; }
/**
* @brief create git process and return the process handle
*/
IProcess* AsyncRunGit(wxEvtHandler* handler, const wxString& git_args, size_t create_flags,
const wxString& working_directory, bool logMessage = false);
/**
* @brief create a git process and direct the output to a callback
*/
void AsyncRunGitWithCallback(const wxString& git_args, std::function<void(const wxString&)> callback,
size_t create_flags, const wxString& working_directory, bool logMessage = false);
/**
* @brief is git enabled for the current workspace?
*/
bool IsGitEnabled() const;
/**
* @brief open a file. The path is relative to the workspace location
*/
IEditor* OpenFile(const wxString& relativePathFile);
/**
* @brief fetch the next 100 commits (skip 'skip' first commits)
* and show them in the commit list dialog
* @param skip number of first commits to skip
*/
void FetchNextCommits(int skip, const wxString& args);
GitConsole* GetConsole() { return m_console; }
IProcess* GetProcess() { return m_process; }
clCommandProcessor* GetFolderProcess() { return m_commandProcessor; }
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();
/**
* @brief display a message in the console
* used by outside classes e.g. GitDiffDlg
* @param message to display
*/
void DisplayMessage(const wxString& message) const;
void DoGitBlame(const wxString& args); // Called by OnGitBlame or the git blame dialog
wxString GetEditorRelativeFilepath() const; // Called by OnGitBlame or the git blame dialog
void OnGitBlameRevList(const wxString& arg, const wxString& filepath,
const wxString& commit = ""); // Called by the git blame dialog
/**
* @brief simple git command executioin completed. Display its output etc
*/
void OnCommandOutput(clCommandEvent& event);
void OnCommandEnded(clCommandEvent& event);
//--------------------------------------------
// Abstract methods
//--------------------------------------------
virtual void CreateToolBar(clToolBarGeneric* toolbar);
virtual void CreatePluginMenu(wxMenu* pluginsMenu);
virtual void HookPopupMenu(wxMenu* menu, MenuType type);
virtual void UnPlug();
};
#endif // git
|