Example usage for org.eclipse.jgit.lib Repository getDirectory

List of usage examples for org.eclipse.jgit.lib Repository getDirectory

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository getDirectory.

Prototype


public File getDirectory() 

Source Link

Document

Get local metadata directory

Usage

From source file:org.eclipse.egit.ui.internal.commit.CommitHelper.java

License:Open Source License

private String getMergeResolveMessage(Repository mergeRepository) {
    File mergeMsg = new File(mergeRepository.getDirectory(), Constants.MERGE_MSG);
    FileReader reader;//  www  .j  a v a  2 s . c o m
    try {
        reader = new FileReader(mergeMsg);
        BufferedReader br = new BufferedReader(reader);
        try {
            StringBuilder message = new StringBuilder();
            String s;
            String newLine = newLine();
            while ((s = br.readLine()) != null)
                message.append(s).append(newLine);
            return message.toString();
        } catch (IOException e) {
            throw new IllegalStateException(e);
        } finally {
            try {
                br.close();
            } catch (IOException e) {
                // Empty
            }
        }
    } catch (FileNotFoundException e) {
        return NLS.bind(UIText.CommitHelper_couldNotFindMergeMsg, Constants.MERGE_MSG);
    }
}

From source file:org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager.java

License:Open Source License

/**
 * @param repository/*from w  w w.  j a v  a  2s . c  o  m*/
 * @param state
 */
public static void persistState(Repository repository, CommitMessageComponentState state) {
    IDialogSettings dialogSettings = getDialogSettings();
    String[] values = new String[] { Boolean.toString(state.getAmend()), state.getAuthor(),
            state.getCommitMessage(), state.getCommitter(), state.getHeadCommit().getName().toString() };
    dialogSettings.put(repository.getDirectory().getAbsolutePath(), values);
}

From source file:org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager.java

License:Open Source License

/**
 * @param repository//from w  w  w .ja v a 2  s.co m
 * @return state
 */
public static CommitMessageComponentState loadState(Repository repository) {
    IDialogSettings dialogSettings = getDialogSettings();
    String[] values = dialogSettings.getArray(repository.getDirectory().getAbsolutePath());
    if (values == null || values.length < MEMBER_COUNT)
        return null;
    CommitMessageComponentState state = new CommitMessageComponentState();
    state.setAmend(Boolean.parseBoolean(values[0]));
    state.setAuthor(values[1]);
    state.setCommitMessage(values[2]);
    state.setCommitter(values[3]);
    state.setHeadCommit(ObjectId.fromString(values[4]));
    return state;
}

From source file:org.eclipse.egit.ui.internal.dialogs.CommitMessageComponentStateManager.java

License:Open Source License

/**
 * @param repository// w  w w .  ja v a  2s  . c  o  m
 */
public static void deleteState(Repository repository) {
    IDialogSettings dialogSettings = getDialogSettings();
    String key = repository.getDirectory().getAbsolutePath();
    if (dialogSettings != null && dialogSettings.getArray(key) != null)
        dialogSettings.put(key, new String[] { EMPTY });
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchOperationUI.java

License:Open Source License

/**
 * @param repository//from w  ww .  j ava  2 s.c  om
 * @param config
 * @param timeout
 * @param dryRun
 *
 */
public FetchOperationUI(Repository repository, RemoteConfig config, int timeout, boolean dryRun) {
    this.repository = repository;
    op = new FetchOperation(repository, config, timeout, dryRun);
    sourceString = NLS.bind("{0} - {1}", repository.getDirectory() //$NON-NLS-1$
            .getParentFile().getName(), config.getName());

}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

/**
 * @param repository//from   w  w  w  . j  a  v  a  2 s.  c om
 * @return a styled string for the repository
 * @throws IOException
 */
protected StyledString getStyledTextFor(Repository repository) throws IOException {
    File directory = repository.getDirectory();
    StyledString string = new StyledString();
    if (!repository.isBare())
        string.append(directory.getParentFile().getName());
    else
        string.append(directory.getName());

    String branch = Activator.getDefault().getRepositoryUtil().getShortBranch(repository);
    if (branch != null) {
        string.append(' ');
        string.append('[', StyledString.DECORATIONS_STYLER);
        string.append(branch, StyledString.DECORATIONS_STYLER);

        RepositoryState repositoryState = repository.getRepositoryState();
        if (repositoryState != RepositoryState.SAFE) {
            string.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }

        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
        if (trackingStatus != null
                && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
            String formattedTrackingStatus = formatBranchTrackingStatus(trackingStatus);
            string.append(' ');
            string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }

    string.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
    string.append(directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER);

    return string;
}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

private String getSimpleTextFor(Repository repository) {
    File directory;//from ww  w. j  a  v a  2 s .c om
    if (!repository.isBare())
        directory = repository.getDirectory().getParentFile();
    else
        directory = repository.getDirectory();
    StringBuilder sb = new StringBuilder();
    sb.append(directory.getName());
    sb.append(" - "); //$NON-NLS-1$
    sb.append(directory.getAbsolutePath());
    return sb.toString();
}

From source file:org.eclipse.egit.ui.internal.GitLabels.java

License:Open Source License

private static String getRepositoryAbsolutePath(Repository repository) {
    return repository.getDirectory().getAbsolutePath();
}

From source file:org.eclipse.egit.ui.internal.history.GitHistoryPage.java

License:Open Source License

void initAndStartRevWalk(boolean forceNewWalk) throws IllegalStateException {
    try {// ww w.  ja v a2  s .c  o m
        if (trace)
            GitTraceLocation.getTrace().traceEntry(GitTraceLocation.HISTORYVIEW.getLocation());

        cancelRefreshJob();
        Repository db = input.getRepository();
        AnyObjectId headId;
        try {
            headId = db.resolve(Constants.HEAD);
        } catch (IOException e) {
            throw new IllegalStateException(NLS.bind(UIText.GitHistoryPage_errorParsingHead,
                    Activator.getDefault().getRepositoryUtil().getRepositoryName(db)));
        }
        if (headId == null)
            throw new IllegalStateException(NLS.bind(UIText.GitHistoryPage_errorParsingHead,
                    Activator.getDefault().getRepositoryUtil().getRepositoryName(db)));

        List<String> paths = buildFilterPaths(input.getItems(), input.getFileList(), db);

        if (forceNewWalk || pathChange(pathFilters, paths) || currentWalk == null
                || !headId.equals(currentHeadId)) {
            // TODO Do not dispose SWTWalk just because HEAD changed
            // In theory we should be able to update the graph and
            // not dispose of the SWTWalk, even if HEAD was reset to
            // HEAD^1 and the old HEAD commit should not be visible.
            //
            currentHeadId = headId;
            if (currentWalk != null)
                currentWalk.release();
            currentWalk = new SWTWalk(db);
            currentWalk.sort(RevSort.COMMIT_TIME_DESC, true);
            currentWalk.sort(RevSort.BOUNDARY, true);
            highlightFlag = currentWalk.newFlag("highlight"); //$NON-NLS-1$
        } else {
            currentWalk.reset();
        }

        try {
            if (store.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_ALL_BRANCHES)) {
                markStartAllRefs(Constants.R_HEADS);
                markStartAllRefs(Constants.R_REMOTES);
            } else
                currentWalk.markStart(currentWalk.parseCommit(headId));
        } catch (IOException e) {
            throw new IllegalStateException(NLS.bind(UIText.GitHistoryPage_errorReadingHeadCommit, headId,
                    db.getDirectory().getAbsolutePath()), e);
        }

        final TreeWalk fileWalker = new TreeWalk(db);
        fileWalker.setRecursive(true);
        if (paths.size() > 0) {
            pathFilters = paths;
            currentWalk.setTreeFilter(
                    AndTreeFilter.create(PathFilterGroup.createFromStrings(paths), TreeFilter.ANY_DIFF));
            fileWalker.setFilter(currentWalk.getTreeFilter().clone());

        } else {
            pathFilters = null;
            currentWalk.setTreeFilter(TreeFilter.ALL);
            fileWalker.setFilter(TreeFilter.ANY_DIFF);
        }
        fileViewer.setTreeWalk(db, fileWalker);
        fileViewer.refresh();
        fileViewer.addSelectionChangedListener(commentViewer);
        commentViewer.setTreeWalk(fileWalker);
        commentViewer.setDb(db);
        commentViewer.refresh();

        final SWTCommitList list;
        list = new SWTCommitList(graph.getControl().getDisplay());
        list.source(currentWalk);
        final GenerateHistoryJob rj = new GenerateHistoryJob(this, list);
        rj.addJobChangeListener(new JobChangeAdapter() {
            @Override
            public void done(final IJobChangeEvent event) {
                final Control graphctl = graph.getControl();
                if (job != rj || graphctl.isDisposed())
                    return;
                graphctl.getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        if (job == rj)
                            job = null;
                    }
                });
            }
        });
        job = rj;
        if (trace)
            GitTraceLocation.getTrace().trace(GitTraceLocation.HISTORYVIEW.getLocation(),
                    "Scheduling GenerateHistoryJob"); //$NON-NLS-1$
        schedule(rj);
    } finally {
        if (trace)
            GitTraceLocation.getTrace().traceExit(GitTraceLocation.HISTORYVIEW.getLocation());

    }
}

From source file:org.eclipse.egit.ui.internal.history.GitHistoryPage.java

License:Open Source License

private ArrayList<String> buildFilterPaths(final IResource[] inResources, final File[] inFiles,
        final Repository db) throws IllegalStateException {
    final ArrayList<String> paths;
    if (inResources != null) {
        paths = new ArrayList<String>(inResources.length);
        for (final IResource r : inResources) {
            final RepositoryMapping map = RepositoryMapping.getMapping(r);
            if (map == null)
                continue;
            if (db != map.getRepository()) {
                throw new IllegalStateException(UIText.AbstractHistoryCommanndHandler_NoUniqueRepository);
            }//from w  ww .  j  a  v a  2 s  .  c  o m

            if (showAllFilter == ShowFilter.SHOWALLFOLDER) {
                final String path;
                // if the resource's parent is the workspace root, we will
                // get nonsense from map.getRepoRelativePath(), so we
                // check here and use the project instead
                if (r.getParent() instanceof IWorkspaceRoot)
                    path = map.getRepoRelativePath(r.getProject());
                else
                    path = map.getRepoRelativePath(r.getParent());
                if (path != null && path.length() > 0)
                    paths.add(path);
            } else if (showAllFilter == ShowFilter.SHOWALLPROJECT) {
                final String path = map.getRepoRelativePath(r.getProject());
                if (path != null && path.length() > 0)
                    paths.add(path);
            } else if (showAllFilter == ShowFilter.SHOWALLREPO) {
                // nothing
            } else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */ {
                final String path = map.getRepoRelativePath(r);
                if (path != null && path.length() > 0)
                    paths.add(path);
            }
        }
    } else if (inFiles != null) {
        IPath workdirPath = new Path(db.getWorkTree().getPath());
        IPath gitDirPath = new Path(db.getDirectory().getPath());
        int segmentCount = workdirPath.segmentCount();
        paths = new ArrayList<String>(inFiles.length);
        for (File file : inFiles) {
            IPath filePath;
            if (showAllFilter == ShowFilter.SHOWALLFOLDER) {
                filePath = new Path(file.getParentFile().getPath());
            } else if (showAllFilter == ShowFilter.SHOWALLPROJECT || showAllFilter == ShowFilter.SHOWALLREPO) {
                // we don't know of projects here -> treat as SHOWALLREPO
                continue;
            } else /* if (showAllFilter == ShowFilter.SHOWALLRESOURCE) */ {
                filePath = new Path(file.getPath());
            }

            if (gitDirPath.isPrefixOf(filePath)) {
                throw new IllegalStateException(
                        NLS.bind(UIText.GitHistoryPage_FileOrFolderPartOfGitDirMessage, filePath.toOSString()));
            }

            IPath pathToAdd = filePath.removeFirstSegments(segmentCount).setDevice(null);
            if (!pathToAdd.isEmpty()) {
                paths.add(pathToAdd.toString());
            }
        }
    } else {
        paths = new ArrayList<String>(0);
    }
    return paths;
}