use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitChangeUtils method getDiff.
@NotNull
public static Collection<Change> getDiff(@NotNull Project project, @NotNull VirtualFile root, @Nullable String oldRevision, @Nullable String newRevision, @Nullable Collection<FilePath> dirtyPaths) throws VcsException {
LOG.assertTrue(oldRevision != null || newRevision != null, "Both old and new revisions can't be null");
String range;
GitRevisionNumber newRev;
GitRevisionNumber oldRev;
if (newRevision == null) {
// current revision at the right
range = oldRevision + "..";
oldRev = resolveReference(project, root, oldRevision);
newRev = null;
} else if (oldRevision == null) {
// current revision at the left
range = ".." + newRevision;
oldRev = null;
newRev = resolveReference(project, root, newRevision);
} else {
range = oldRevision + ".." + newRevision;
oldRev = resolveReference(project, root, oldRevision);
newRev = resolveReference(project, root, newRevision);
}
String output = getDiffOutput(project, root, range, dirtyPaths);
Collection<Change> changes = new ArrayList<>();
parseChanges(project, root, newRev, oldRev, output, changes, Collections.<String>emptySet());
return changes;
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitChangeUtils method resolveReference.
/**
* Load actual revision number with timestamp basing on a reference: name of a branch or tag, or revision number expression.
*/
@NotNull
public static GitRevisionNumber resolveReference(@NotNull Project project, @NotNull VirtualFile vcsRoot, @NotNull String reference) throws VcsException {
GitSimpleHandler handler = createRefResolveHandler(project, vcsRoot, reference);
String output = handler.run();
StringTokenizer stk = new StringTokenizer(output, "\n\r \t", false);
if (!stk.hasMoreTokens()) {
try {
GitSimpleHandler dh = new GitSimpleHandler(project, vcsRoot, GitCommand.LOG);
dh.addParameters("-1", "HEAD");
dh.setSilent(true);
String out = dh.run();
LOG.info("Diagnostic output from 'git log -1 HEAD': [" + out + "]");
dh = createRefResolveHandler(project, vcsRoot, reference);
out = dh.run();
LOG.info("Diagnostic output from 'git rev-list -1 --timestamp HEAD': [" + out + "]");
} catch (VcsException e) {
LOG.info("Exception while trying to get some diagnostics info", e);
}
throw new VcsException(String.format("The string '%s' does not represent a revision number. Output: [%s]\n Root: %s", reference, output, vcsRoot));
}
Date timestamp = GitUtil.parseTimestampWithNFEReport(stk.nextToken(), handler, output);
return new GitRevisionNumber(stk.nextToken(), timestamp);
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitPushOperation method collectUpdatedFiles.
private void collectUpdatedFiles(@NotNull UpdatedFiles updatedFiles, @NotNull GitRepository repository, @NotNull String preUpdatePosition) {
MergeChangeCollector collector = new MergeChangeCollector(myProject, repository.getRoot(), new GitRevisionNumber(preUpdatePosition));
ArrayList<VcsException> exceptions = new ArrayList<>();
collector.collect(updatedFiles, exceptions);
for (VcsException exception : exceptions) {
LOG.info(exception);
}
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitMergeProvider method loadRevisions.
@Override
@NotNull
public MergeData loadRevisions(@NotNull final VirtualFile file) throws VcsException {
final MergeData mergeData = new MergeData();
final VirtualFile root = GitUtil.getGitRoot(file);
final FilePath path = VcsUtil.getFilePath(file.getPath());
VcsRunnable runnable = new VcsRunnable() {
@Override
@SuppressWarnings({ "ConstantConditions" })
public void run() throws VcsException {
GitFileRevision original = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + ORIGINAL_REVISION_NUM));
GitFileRevision current = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + yoursRevision(root)));
GitFileRevision last = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + theirsRevision(root)));
try {
try {
mergeData.ORIGINAL = original.getContent();
} catch (Exception ex) {
/// This could happen in case if rebasing.
try {
mergeData.ORIGINAL = file.contentsToByteArray();
} catch (IOException e) {
LOG.error(e);
mergeData.ORIGINAL = ArrayUtil.EMPTY_BYTE_ARRAY;
}
}
mergeData.CURRENT = loadRevisionCatchingErrors(current);
mergeData.LAST = loadRevisionCatchingErrors(last);
// TODO: can be done once for a root
mergeData.CURRENT_REVISION_NUMBER = findCurrentRevisionNumber(root);
mergeData.LAST_REVISION_NUMBER = findLastRevisionNumber(root);
mergeData.ORIGINAL_REVISION_NUMBER = findOriginalRevisionNumber(root, mergeData.CURRENT_REVISION_NUMBER, mergeData.LAST_REVISION_NUMBER);
Trinity<String, String, String> blobs = getAffectedBlobs(root, file);
mergeData.CURRENT_FILE_PATH = getBlobPathInRevision(root, file, blobs.getFirst(), mergeData.CURRENT_REVISION_NUMBER);
mergeData.ORIGINAL_FILE_PATH = getBlobPathInRevision(root, file, blobs.getSecond(), mergeData.ORIGINAL_REVISION_NUMBER);
mergeData.LAST_FILE_PATH = getBlobPathInRevision(root, file, blobs.getThird(), mergeData.LAST_REVISION_NUMBER);
} catch (IOException e) {
throw new IllegalStateException("Failed to load file content", e);
}
}
};
VcsUtil.runVcsProcessWithProgress(runnable, GitBundle.message("merge.load.files"), false, myProject);
return mergeData;
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitMergeProvider method resolveMergeHead.
@Nullable
private GitRevisionNumber resolveMergeHead(@NotNull VirtualFile root) {
try {
return GitRevisionNumber.resolve(myProject, root, MERGE_HEAD);
} catch (VcsException e) {
// this may be not a bug, just cherry-pick
LOG.info("Couldn't resolve the MERGE_HEAD in " + root + ": " + e.getMessage());
}
try {
return GitRevisionNumber.resolve(myProject, root, CHERRY_PICK_HEAD);
} catch (VcsException e) {
LOG.info("Couldn't resolve the CHERRY_PICK_HEAD in " + root + ": " + e.getMessage());
}
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
assert repository != null;
File rebaseApply = repository.getRepositoryFiles().getRebaseApplyDir();
GitRevisionNumber rebaseRevision = readRevisionFromFile(new File(rebaseApply, "original-commit"));
if (rebaseRevision != null)
return rebaseRevision;
File rebaseMerge = repository.getRepositoryFiles().getRebaseMergeDir();
GitRevisionNumber mergeRevision = readRevisionFromFile(new File(rebaseMerge, "stopped-sha"));
if (mergeRevision != null)
return mergeRevision;
return null;
}
Aggregations