Example usage for org.eclipse.jgit.lib ObjectId getName

List of usage examples for org.eclipse.jgit.lib ObjectId getName

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ObjectId getName.

Prototype

public final String getName() 

Source Link

Document

Get string form of the SHA-1, in lower case hexadecimal.

Usage

From source file:com.google.gerrit.sshd.commands.BanCommitCommand.java

License:Apache License

@Override
protected void run() throws Failure {
    try {// w  w w  .  j  av  a2  s  . c o m
        BanCommit.Input input = BanCommit.Input
                .fromCommits(Lists.transform(commitsToBan, new Function<ObjectId, String>() {
                    @Override
                    public String apply(ObjectId oid) {
                        return oid.getName();
                    }
                }));
        input.reason = reason;

        BanResultInfo r = banCommit.apply(new ProjectResource(projectControl), input);
        printCommits(r.newlyBanned, "The following commits were banned");
        printCommits(r.alreadyBanned, "The following commits were already banned");
        printCommits(r.ignored, "The following ids do not represent commits and were ignored");
    } catch (RestApiException | IOException | InterruptedException e) {
        throw die(e);
    }
}

From source file:com.googlesource.gerrit.plugins.xdocs.XDocLoader.java

License:Apache License

private String getHtml(String formatterName, StringFormatter f, Repository repo, ObjectLoader loader,
        Project.NameKey project, String path, ObjectId revId)
        throws MethodNotAllowedException, IOException, GitAPIException {
    byte[] bytes = loader.getBytes(Integer.MAX_VALUE);
    boolean isBinary = RawText.isBinary(bytes);
    if (formatterName.equals(Formatters.RAW_FORMATTER) && isBinary) {
        throw new MethodNotAllowedException();
    }/*  w  ww.  j  ava2  s.c  o m*/
    String raw = new String(bytes, UTF_8);
    String abbrRevId = getAbbrRevId(repo, revId);
    if (!isBinary) {
        raw = replaceMacros(repo, project, revId, abbrRevId, raw);
    }
    return f.format(project.get(), path, revId.getName(), abbrRevId, getFormatterConfig(formatterName), raw);
}

From source file:com.googlesource.gerrit.plugins.xdocs.XDocLoader.java

License:Apache License

private String getHtml(String formatterName, StreamFormatter f, Repository repo, ObjectLoader loader,
        Project.NameKey project, String path, ObjectId revId) throws IOException {
    try (InputStream raw = loader.openStream()) {
        return f.format(project.get(), path, revId.getName(), getAbbrRevId(repo, revId),
                getFormatterConfig(formatterName), raw);
    }/*  w  ww .  j av a2  s  .  c  om*/
}

From source file:com.googlesource.gerrit.plugins.xdocs.XDocServlet.java

License:Apache License

private static String computeETag(Project.NameKey project, ObjectId revId, String file, ObjectId revIdB,
        DiffMode diffMode) {/* ww  w  .  j av  a 2s  . c  o m*/
    Hasher hasher = Hashing.md5().newHasher();
    hasher.putUnencodedChars(project.get());
    if (revId != null) {
        hasher.putUnencodedChars(revId.getName());
    }
    hasher.putUnencodedChars(file);
    if (diffMode != DiffMode.NO_DIFF) {
        hasher.putUnencodedChars(revIdB.getName()).putUnencodedChars(diffMode.name());
    }
    return hasher.hash().toString();
}

From source file:com.madgag.agit.CommitViewerActivity.java

License:Open Source License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.commit_navigation_animation_layout);

    relationAnimations.put(PARENT, new RelationAnimations(push_child_out, pull_parent_in));
    relationAnimations.put(CHILD, new RelationAnimations(push_parent_out, pull_child_in));

    currentCommitView = (CommitView) findViewById(R.id.commit_nav_current_commit);
    nextCommitView = (CommitView) findViewById(R.id.commit_nav_next_commit);

    CommitSelectedListener commitSelectedListener = new CommitSelectedListener() {
        public void onCommitSelected(Relation relation, PlotCommit<PlotLane> commit) {
            setCommit(commit, relation);
        }/*from  ww  w  .j a v  a  2s  . c  o  m*/
    };
    try {
        ObjectId revisionId = GitIntents.commitIdFrom(getIntent()); // intent.getStringExtra("commit");
        Log.d(TAG, revisionId.getName());
        PlotWalk revWalk = generatePlotWalk();

        commit = (PlotCommit<PlotLane>) revWalk.parseCommit(revisionId);

        setup(currentCommitView, commitSelectedListener, revWalk);
        setup(nextCommitView, commitSelectedListener, revWalk);

        currentCommitView.setCommit(commit);
        setCurrentCommitViewVisible();
    } catch (Exception e) {
        Log.e(TAG, "Problem my friend", e);
    }
}

From source file:com.mangosolutions.rcloud.rawgist.repository.git.BareCommitCommand.java

private void insertChangeId(ObjectId treeId) {
    ObjectId firstParentId = null;/*from  w ww. j ava  2 s  .  com*/
    if (!parents.isEmpty()) {
        firstParentId = parents.get(0);
    }
    ObjectId changeId = ChangeIdUtil.computeChangeId(treeId, firstParentId, author, committer, message);
    message = ChangeIdUtil.insertId(message, changeId);
    if (changeId != null) {
        message = message.replaceAll("\nChange-Id: I" //$NON-NLS-1$
                + ObjectId.zeroId().getName() + "\n", //$NON-NLS-1$
                "\nChange-Id: I" //$NON-NLS-1$
                        + changeId.getName() + "\n"); //$NON-NLS-1$
    }
}

From source file:com.mangosolutions.rcloud.rawgist.repository.git.ReadGistOperation.java

private FileContent readContent(Repository repository, TreeWalk treeWalk) {

    ObjectId objectId = treeWalk.getObjectId(0);
    String fileName = treeWalk.getPathString();
    FileContent content = fileContentCache.load(objectId.getName(), fileName);
    if (content == null) {
        content = new FileContent();
        try {/*  ww w . j a va  2  s.  co m*/
            content.setFilename(fileName);
            ObjectLoader loader = repository.open(objectId);

            content.setContent(new String(loader.getBytes(), Charsets.UTF_8));
            content.setSize(loader.getSize());
            content.setTruncated(false);
            String language = FilenameUtils.getExtension(fileName);
            if (!GitGistRepository.B64_BINARY_EXTENSION.equals(language) && !StringUtils.isEmpty(language)) {
                content.setLanguage(language);
            }
            content.setType(MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(fileName));
            fileContentCache.save(objectId.getName(), fileName, content);
        } catch (IOException e) {
            GistError error = new GistError(GistErrorCode.ERR_GIST_CONTENT_NOT_READABLE,
                    "Could not read content of {} for gist {}", fileName, gistId);
            logger.error(error.getFormattedMessage() + " with path {}", this.layout.getRootFolder(), e);
            throw new GistRepositoryError(error, e);
        }
    }
    return content;
}

From source file:com.microsoft.gittf.core.config.ChangesetCommitMap.java

License:Open Source License

public void setChangesetCommit(int changesetID, ObjectId commitID, boolean forceHWMUpdate) throws IOException {
    Check.isTrue(changesetID >= 0, "changesetID >= 0"); //$NON-NLS-1$
    Check.notNull(commitID, "commitID"); //$NON-NLS-1$

    ensureConfigUptoDate();/*from  w ww  . j  a  v  a  2  s  .  c om*/

    cleanupPreviousEntries(changesetID);

    configFile.setString(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.COMMIT_SUBSECTION,
            MessageFormat.format(ConfigurationConstants.COMMIT_CHANGESET_FORMAT, Integer.toString(changesetID)),
            commitID.getName());

    configFile.setInt(ConfigurationConstants.CONFIGURATION_SECTION, ConfigurationConstants.CHANGESET_SUBSECTION,
            MessageFormat.format(ConfigurationConstants.CHANGESET_COMMIT_FORMAT, commitID.getName()),
            changesetID);

    /* Update the high water mark automatically */
    if ((changesetID > getLastBridgedChangesetID(false)) || forceHWMUpdate) {
        configFile.setInt(ConfigurationConstants.CONFIGURATION_SECTION,
                ConfigurationConstants.CHANGESET_SUBSECTION, ConfigurationConstants.CHANGESET_HIGHWATER,
                changesetID);
    }

    configFile.save();

    TagUtil.createTFSChangesetTag(repository, commitID, changesetID);
}

From source file:com.microsoft.gittf.core.config.ChangesetCommitMap.java

License:Open Source License

/**
 * Gets the changeset id that this commit refers to
 * //  w ww.j  a v a2s.co m
 * @param commitID
 *        the commit id
 * @return
 */
public int getChangesetID(ObjectId commitID) {
    Check.notNull(commitID, "commitID"); //$NON-NLS-1$

    ensureConfigUptoDate();

    return configFile.getInt(ConfigurationConstants.CONFIGURATION_SECTION,
            ConfigurationConstants.CHANGESET_SUBSECTION,
            MessageFormat.format(ConfigurationConstants.CHANGESET_COMMIT_FORMAT, commitID.getName()), -1);
}

From source file:com.microsoft.gittf.core.tasks.FetchTask.java

License:Open Source License

private boolean writeFetchHead(final ObjectId commitID, final int changesetID) throws IOException {
    Ref fetchHeadRef = repository.getRef(Constants.FETCH_HEAD);
    boolean referencesEqual = fetchHeadRef == null ? false : fetchHeadRef.getObjectId().equals(commitID);

    if (referencesEqual) {
        return false;
    }//from www.j  a va 2  s  .c  o m

    final File refFile = new File(repository.getDirectory(), Constants.FETCH_HEAD);
    final LockFile lockFile = new LockFile(refFile, repository.getFS());

    if (lockFile.lock()) {
        try {
            BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(lockFile.getOutputStream(), Charset.forName("UTF-8"))); //$NON-NLS-1$

            try {
                writer.append(MessageFormat.format("{0}\t\t{1}", commitID.getName(), //$NON-NLS-1$
                        Messages.formatString("FetchTask.RefLogFormat", //$NON-NLS-1$
                                Integer.toString(changesetID))));
            } finally {
                writer.close();
            }

            lockFile.commit();
        } finally {
            lockFile.unlock();
        }
    }

    return true;
}