use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.
the class HgAutoSparseState method loadHgManifest.
private void loadHgManifest() throws VersionControlCommandFailedException, InterruptedException {
if (!hgManifestLoaded) {
// Cache manifest data
try (InputStream is = new FileInputStream(hgCmdLine.extractRawManifest());
BufferedReader reader = new BufferedReader(new InputStreamReader(is, // doesn't care what the filesystem encoding is and just stores the raw bytes.
System.getProperty("file.encoding", "UTF-8")))) {
hgManifest = new HashMap<Path, ManifestInfo>();
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split("\0", 2);
if (parts.length != 2) {
// not a valid raw manifest line, skip
continue;
}
Path path = Paths.get(parts[0]);
String hash = "";
String flag = "";
try {
hash = parts[1].substring(0, 40);
flag = parts[1].substring(40);
} catch (IndexOutOfBoundsException e) {
// not a valid raw manifest line, skip
continue;
}
if (flag.equals("d")) {
// deletion entry, remove existing manifest entry from the map
hgManifest.remove(path);
continue;
}
Path directory = path.getParent();
hgDirectParents.add(directory);
while (directory != null) {
hgKnownDirectories.add(directory);
directory = directory.getParent();
}
hgManifest.put(path, ManifestInfo.of(hash, flag));
}
} catch (IOException e) {
throw new VersionControlCommandFailedException("Unable to load raw manifest into an inputstream");
}
hgManifestLoaded = true;
LOG.debug("Loaded %d manifest entries", hgManifest.size());
}
}
use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.
the class HgAutoSparseState method addToSparseProfile.
@Override
public void addToSparseProfile(Path path) {
Path relativePath = hgRoot.relativize(path);
// check if the path or a parent of it has already been added to the sparse profile
Path parent = relativePath;
while (parent != null) {
if (hgSparseSeen.contains(parent)) {
return;
}
parent = parent.getParent();
}
// Obtain hg manifest and directories
try {
loadHgManifest();
} catch (VersionControlCommandFailedException | InterruptedException e) {
LOG.debug("Failed to load the hg manifest");
return;
}
if (hgManifest.isEmpty()) {
return;
}
// is ignored.
if (!hgManifest.containsKey(relativePath) && !hgDirectParents.contains(relativePath)) {
LOG.debug("Not adding unknown file or directory %s to sparse profile", relativePath);
return;
}
// For files, add the direct parent directory instead, unless that's an ignored path
if (ignoredPaths.contains(relativePath)) {
// don't add the project directory directly
return;
}
if (hgManifest.containsKey(relativePath)) {
Path directory = relativePath.getParent();
if (directory != null && !ignoredPaths.contains(directory)) {
relativePath = directory;
}
}
hgSparseSeen.add(relativePath);
}
use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.
the class HgAutoSparseState method existsInManifest.
@Override
public boolean existsInManifest(Path path) {
try {
loadHgManifest();
} catch (VersionControlCommandFailedException | InterruptedException e) {
LOG.debug("Failed to load the manifest");
return false;
}
Path relativePath = hgRoot.relativize(path);
if (hgKnownDirectories.contains(relativePath)) {
return true;
}
ManifestInfo manifestInfo = getManifestInfoForFile(path);
return manifestInfo != null ? true : false;
}
use of com.facebook.buck.util.versioncontrol.VersionControlCommandFailedException in project buck by facebook.
the class AutoSparseIntegrationTest method assumeHgSparseInstalled.
private static void assumeHgSparseInstalled() {
// If hg sparse throws an exception, then skip tests.
Throwable exception = null;
try {
Path exportFile = Files.createTempFile("buck_autosparse_rules", "");
try (Writer writer = new BufferedWriter(new FileWriter(exportFile.toFile()))) {
// deliberately mostly empty
writer.write("[include]\n");
}
((HgCmdLineInterface) repoCmdline).exportHgSparseRules(exportFile);
} catch (VersionControlCommandFailedException | InterruptedException | IOException e) {
exception = e;
}
Assume.assumeNoException(exception);
}
Aggregations