use of git4idea.util.StringScanner in project intellij-community by JetBrains.
the class GitUtil method getPathsDiffBetweenRefs.
/**
* Returns absolute paths which have changed remotely comparing to the current branch, i.e. performs
* <code>git diff --name-only master..origin/master</code>
* <p/>
* Paths are absolute, Git-formatted (i.e. with forward slashes).
*/
@NotNull
public static Collection<String> getPathsDiffBetweenRefs(@NotNull Git git, @NotNull GitRepository repository, @NotNull String beforeRef, @NotNull String afterRef) throws VcsException {
List<String> parameters = Arrays.asList("--name-only", "--pretty=format:");
String range = beforeRef + ".." + afterRef;
GitCommandResult result = git.diff(repository, parameters, range);
if (!result.success()) {
LOG.info(String.format("Couldn't get diff in range [%s] for repository [%s]", range, repository.toLogString()));
return Collections.emptyList();
}
final Collection<String> remoteChanges = new HashSet<>();
for (StringScanner s = new StringScanner(result.getOutputAsJoinedString()); s.hasMoreData(); ) {
final String relative = s.line();
if (StringUtil.isEmptyOrSpaces(relative)) {
continue;
}
final String path = repository.getRoot().getPath() + "/" + unescapePath(relative);
remoteChanges.add(path);
}
return remoteChanges;
}
use of git4idea.util.StringScanner in project intellij-community by JetBrains.
the class GitMergeProvider method doGetBlobPathInRevision.
@Nullable
private FilePath doGetBlobPathInRevision(@NotNull final VirtualFile root, @NotNull final String blob, @NotNull VcsRevisionNumber revision, @Nullable VirtualFile file) {
final FilePath[] result = new FilePath[1];
final boolean[] pathAmbiguous = new boolean[1];
GitLineHandler h = new GitLineHandler(myProject, root, GitCommand.LS_TREE);
h.addParameters(revision.asString());
if (file != null) {
h.endOptions();
h.addRelativeFiles(Collections.singleton(file));
} else {
h.addParameters("-r");
h.endOptions();
}
h.addLineListener(new GitLineHandlerAdapter() {
@Override
public void onLineAvailable(String line, Key outputType) {
if (outputType != ProcessOutputTypes.STDOUT)
return;
if (!line.contains(blob))
return;
if (pathAmbiguous[0])
return;
try {
StringScanner s = new StringScanner(line);
// permissions
s.spaceToken();
// type
String type = s.spaceToken();
// blob
String recordBlob = s.tabToken();
FilePath file = VcsUtil.getFilePath(root, GitUtil.unescapePath(s.line()));
if (!"blob".equals(type))
return;
if (!blob.equals(recordBlob))
return;
if (result[0] == null) {
result[0] = file;
} else {
// there are multiple files with given content in this revision.
// we don't know which is right, so do not return any
pathAmbiguous[0] = true;
}
} catch (VcsException e) {
LOG.warn(e);
}
}
});
h.runInCurrentThread(null);
if (pathAmbiguous[0])
return null;
return result[0];
}
use of git4idea.util.StringScanner in project intellij-community by JetBrains.
the class GitMergeProvider method getAffectedBlobs.
@NotNull
private Trinity<String, String, String> getAffectedBlobs(@NotNull VirtualFile root, @NotNull VirtualFile file) {
try {
GitSimpleHandler h = new GitSimpleHandler(myProject, root, GitCommand.LS_FILES);
h.addParameters("--exclude-standard", "--unmerged", "-z");
h.endOptions();
h.addRelativeFiles(Collections.singleton(file));
String output = h.run();
StringScanner s = new StringScanner(output);
String lastBlob = null;
String currentBlob = null;
String originalBlob = null;
while (s.hasMoreData()) {
// permissions
s.spaceToken();
String blob = s.spaceToken();
// stage
int source = Integer.parseInt(s.tabToken());
// file name
s.boundedToken('