void Gitarre::CheckRepoState(int i) { Repository *repo = Repos[i]; StatusCbData cbData = { this, i, Gitarre::Update }; git_strarray *pathspec = pathspecAll (); git_status_options cbOptns = { 1, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS, *pathspec }; git_status_foreach_ext (repo->GetGitRepo(), &cbOptns, Gitarre::sStatusCb, (void *)&cbData); git_strarray_free (pathspec); }
void Gitarre::DisplayRepo(int i) { Repository *repo = Repos[i]; QTreeWidgetItem *item = new QTreeWidgetItem (QStringList (repo->GetName())); RepoView->insertTopLevelItem(i, item); if (repo->GetGitRepo ()) { StatusCbData cbData = { this, i, Gitarre::Add }; git_strarray *pathspec = pathspecAll (); git_status_options cbOptns = { 1, GIT_STATUS_SHOW_INDEX_AND_WORKDIR, GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS | GIT_STATUS_OPT_RECURSE_IGNORED_DIRS, *pathspec }; git_status_foreach_ext (repo->GetGitRepo(), &cbOptns, Gitarre::sStatusCb, (void *)&cbData); git_strarray_free (pathspec); // AddSubfolders (i, item, repo->GetDir()); } else item->setForeground(0, QBrush (QColor(Qt::red))); update (); }
void Gitarre::onRepoViewItemChanged (QTreeWidgetItem * current, QTreeWidgetItem * previous) { PurgeRepoViewContextMenu (); int topLevelIndex = RepoView->indexOfTopLevelItem(current); if (topLevelIndex != -1) // item is a top level item { Repository *repo = Repos [topLevelIndex]; // create context menu for the specific item if (repo->GetGitRepo()) { RepoView->addAction(CommitRepoAction); RepoView->addAction(PushRepoAction); CommitAction->setEnabled(true); PushAction->setEnabled(true); } else { RepoView->addAction(FindRepoAction); CommitAction->setEnabled(false); PushAction->setEnabled(false); } RepoView->addAction(RemoveSeparator); RepoView->addAction(RemoveRepoAction); // refresh remotes menu if (current != previous) RefreshRemotesMenu (repo); } else // provide the corresponding top level index { QTreeWidgetItem *parent = current; // move all the way up the item hierarchy while (parent->parent()) // while item "parent" has a parent parent = parent->parent(); // set parent to its parent topLevelIndex = RepoView->indexOfTopLevelItem(parent); } Repository *repo = Repos [topLevelIndex]; QTextDocument *doc = repo->GetIgnoreDocument(); if (IgnoreEditor->document() != doc) { IgnoreEditor->setDocument(doc); UpdateIgnoreEditorTab (doc->isModified()); } }
int Gitarre::StatusCb (const char *path, unsigned int status_flags, int i, StatusCbMode mode) { if (mode == Gitarre::Add || ( mode == Gitarre::Update && ( (status_flags & GIT_STATUS_WT_NEW) || (status_flags & GIT_STATUS_WT_DELETED) ))) { Repository *repo = Repos[i]; git_repository *gitRepo = repo->GetGitRepo(); QString repoPath = repo->GetPath(); QString relPath (path); // Split path into hierarchy QStringList hier = relPath.split ("/"); // For every hierarchy member, check whether directory exists and was added to RepoView QString absoluteDirPath = repoPath; QTreeWidgetItem *item = RepoView->topLevelItem(i); for (int j = 0; j < hier.size() - 1; ++j) { absoluteDirPath += QString ('/') + hier[j]; QTreeWidgetItem *foundItem = findChildItem (item, hier[j]); if (!foundItem) { foundItem = new QTreeWidgetItem (QStringList (hier[j])); foundItem->setIcon (0, QIcon::fromTheme ("folder")); QDir absoluteDir (absoluteDirPath); if (!absoluteDir.exists()) foundItem->setForeground(0, QBrush (ColorDeleted)); else { // TODO: This is not working for some reason; find alternative way to address (maybe via .gitignore directly?) int ignored; git_status_should_ignore (&ignored, gitRepo, absoluteDirPath.toStdString().c_str()); if (ignored) foundItem->setForeground(0, QBrush (ColorIgnored)); } item->addChild(foundItem); } item = foundItem; } if (mode == Gitarre::Add || ( mode == Gitarre::Update && !(status_flags & GIT_STATUS_WT_DELETED))) { QTreeWidgetItem *child = NULL; if (mode == Gitarre::Update) { child = findChildItem (item, hier.back()); } if (!child) { QTreeWidgetItem *child = new QTreeWidgetItem (QStringList (hier.back())); child->setIcon(0, QIcon::fromTheme ("text-x-generic")); if (status_flags & GIT_STATUS_IGNORED) child->setForeground(0, QBrush (ColorIgnored)); else if (status_flags & GIT_STATUS_WT_DELETED) child->setForeground(0, QBrush (ColorDeleted)); else if (status_flags & GIT_STATUS_WT_NEW) child->setForeground(0, QBrush (ColorNew)); item->addChild(child); if (mode == Gitarre::Update) item->sortChildren(0, Qt::AscendingOrder); } } else // only option is mode == Gitarre::Update && status_flags & GIT_STATUS_WT_DELETED { QTreeWidgetItem *child = findChildItem (item, hier.back()); if (!child) { QTreeWidgetItem *child = new QTreeWidgetItem (QStringList (hier.back())); child->setIcon(0, QIcon::fromTheme ("text-x-generic")); item->addChild(child); item->sortChildren(0, Qt::AscendingOrder); } child->setForeground(0, QBrush (ColorDeleted)); } } return 0; }