package com.atlassian.bitbucket.mesh.git.builder.revlist;

import com.atlassian.bitbucket.mesh.git.commit.Commit;
import com.atlassian.bitbucket.mesh.git.content.MinimalChange;

/**
 * An implementation of {@link AbstractCommitRevListStdioHandler} which emits a single {@link Commit}.
 * <p>
 * This output handler assumes that the output has been limited by the command itself--it is not safe to use without
 * the {@code -1} flag on {@code git rev-list}.
 */
public class SingleCommitRevListStdioHandler extends AbstractCommitRevListStdioHandler<Commit> {

    private Commit commit;

    public SingleCommitRevListStdioHandler(String path, boolean withMessages, boolean withPath,
                                           int maxMessageLength) {
        super(withMessages, withPath, maxMessageLength, path);
    }

    @Override
    public Commit getResult() {
        return commit;
    }

    @Override
    protected boolean onCommit(Commit commit, MinimalChange ignored) {
        this.commit = commit;

        return false;
    }
}