Search in sources :

Example 1 with UIFile

use of org.apache.hop.git.model.UIFile in project hop by apache.

the class GitInfoExplorerFileTypeHandler method getStatusDescription.

private String getStatusDescription(GitGuiPlugin guiPlugin) {
    Map<String, UIFile> changedFiles = guiPlugin.getChangedFiles();
    Map<String, String> ignoredFiles = guiPlugin.getIgnoredFiles();
    UIFile file = changedFiles.get(explorerFile.getFilename());
    if (file == null) {
        String ignored = ignoredFiles.get(explorerFile.getFilename());
        if (ignored == null) {
            return "Not changed";
        } else {
            return "Ignored";
        }
    } else {
        switch(file.getChangeType()) {
            case ADD:
                return "Not added";
            case COPY:
                return "Copied";
            case MODIFY:
                return "Modified";
            case DELETE:
                return "Deleted";
            case RENAME:
                return "Renamed";
            default:
                return "Changed";
        }
    }
}
Also used : UIFile(org.apache.hop.git.model.UIFile)

Example 2 with UIFile

use of org.apache.hop.git.model.UIFile in project hop by apache.

the class GitGuiPlugin method filePainted.

/**
 * If we have a git project we can take a look and see if a file is changed.
 *
 * @param tree
 * @param treeItem
 * @param path
 * @param name
 */
@Override
public void filePainted(Tree tree, TreeItem treeItem, String path, String name) {
    GuiResource guiResource = GuiResource.getInstance();
    UIFile file = null;
    // Changed git file colored blue
    try {
        file = changedFiles.get(HopVfs.getFileObject(path).getName().getPath());
    } catch (HopFileException e) {
    // do nothing
    }
    if (file != null) {
        switch(file.getChangeType()) {
            case DELETE:
            case MODIFY:
            case RENAME:
            case COPY:
                treeItem.setForeground(colorStaged);
                break;
            case ADD:
                if (file.getIsStaged()) {
                    treeItem.setForeground(colorStaged);
                } else {
                    treeItem.setForeground(colorUnstaged);
                }
                break;
        }
    }
    String ignored = ignoredFiles.get(path);
    if (ignored != null) {
        treeItem.setForeground(colorIgnored);
    }
}
Also used : UIFile(org.apache.hop.git.model.UIFile) HopFileException(org.apache.hop.core.exception.HopFileException) GuiResource(org.apache.hop.ui.core.gui.GuiResource)

Example 3 with UIFile

use of org.apache.hop.git.model.UIFile in project hop by apache.

the class GitGuiPlugin method refreshChangedFiles.

private void refreshChangedFiles() {
    changedFiles = new HashMap<>();
    ignoredFiles = new HashMap<>();
    if (git != null) {
        // List the staged and unstaged files...
        // 
        List<UIFile> files = new ArrayList<>(git.getStagedFiles());
        files.addAll(git.getUnstagedFiles());
        for (UIFile file : files) {
            String path = getAbsoluteFilename(git.getDirectory(), file.getName());
            changedFiles.put(path, file);
        }
        Set<String> ignored = git.getIgnored(null);
        for (String ignore : ignored) {
            String filename = getAbsoluteFilename(git.getDirectory(), ignore);
            ignoredFiles.put(filename, ignore);
        }
    }
}
Also used : UIFile(org.apache.hop.git.model.UIFile)

Example 4 with UIFile

use of org.apache.hop.git.model.UIFile in project hop by apache.

the class GitInfoExplorerFileTypeHandler method refreshChangedFiles.

private void refreshChangedFiles() {
    GitGuiPlugin guiPlugin = GitGuiPlugin.getInstance();
    UIGit git = guiPlugin.getGit();
    List<UIFile> changedFiles;
    String selectedFile = wFile.getText();
    String rootFolder = git.getDirectory();
    boolean showStaged = true;
    // 
    if (wRevisions.table.getSelectionCount() == 0) {
        changedFiles = new ArrayList<>(guiPlugin.getChangedFiles().values());
    } else {
        String revisionId = wRevisions.table.getSelection()[0].getText(1);
        if (UIGit.WORKINGTREE.equals(revisionId)) {
            changedFiles = new ArrayList<>();
            for (UIFile changedFile : guiPlugin.getChangedFiles().values()) {
                if (isFilteredPath(rootFolder, changedFile.getName(), selectedFile)) {
                    changedFiles.add(changedFile);
                }
            }
        } else {
            showStaged = false;
            changedFiles = new ArrayList<>();
            try {
                RevCommit commit = git.resolve(revisionId);
                RevTree tree = commit.getTree();
                try (TreeWalk treeWalk = new TreeWalk(git.getGit().getRepository())) {
                    treeWalk.setRecursive(true);
                    treeWalk.reset(tree);
                    while (treeWalk.next()) {
                        String path = treeWalk.getPathString();
                        if (isFilteredPath(rootFolder, path, selectedFile)) {
                            changedFiles.add(new UIFile(path, DiffEntry.ChangeType.MODIFY, false));
                        }
                    }
                }
            } catch (Exception e) {
                LogChannel.UI.logError("Error getting changed file in revision " + revisionId, e);
            }
        }
    }
    wFiles.removeAll();
    for (UIFile file : changedFiles) {
        TableItem item = new TableItem(wFiles.table, SWT.NONE);
        item.setText(1, Const.NVL(file.getName(), ""));
        if (showStaged) {
            item.setText(2, Const.NVL(file.getChangeType().name(), ""));
            item.setText(3, file.getIsStaged() ? "Y" : "N");
        }
    }
    wFiles.optimizeTableView();
}
Also used : UIFile(org.apache.hop.git.model.UIFile) GitGuiPlugin(org.apache.hop.git.GitGuiPlugin) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) UIGit(org.apache.hop.git.model.UIGit) RevTree(org.eclipse.jgit.revwalk.RevTree) HopException(org.apache.hop.core.exception.HopException) HopFileException(org.apache.hop.core.exception.HopFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

UIFile (org.apache.hop.git.model.UIFile)4 HopFileException (org.apache.hop.core.exception.HopFileException)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 HopException (org.apache.hop.core.exception.HopException)1 GitGuiPlugin (org.apache.hop.git.GitGuiPlugin)1 UIGit (org.apache.hop.git.model.UIGit)1 GuiResource (org.apache.hop.ui.core.gui.GuiResource)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevTree (org.eclipse.jgit.revwalk.RevTree)1 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)1