Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch commit, add and files methods in HgRepository #109

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 58 additions & 12 deletions vcs/src/main/java/org/openjdk/skara/vcs/hg/HgRepository.java
Expand Up @@ -640,8 +640,7 @@ public Optional<byte[]> show(Path path, Hash hash) throws IOException {
}
}

@Override
public List<FileEntry> files(Hash hash, List<Path> paths) throws IOException {
private List<FileEntry> allFiles(Hash hash, List<Path> paths) throws IOException {
var ext = Files.createTempFile("ext", ".py");
copyResource(EXT_PY, ext);

Expand All @@ -666,6 +665,26 @@ public List<FileEntry> files(Hash hash, List<Path> paths) throws IOException {
}
}

@Override
public List<FileEntry> files(Hash hash, List<Path> paths) throws IOException {
if (paths.isEmpty()) {
return allFiles(hash, paths);
}

var entries = new ArrayList<FileEntry>();
var batchSize = 64;
var start = 0;
while (start < paths.size()) {
var end = start + batchSize;
if (end > paths.size()) {
end = paths.size();
}
entries.addAll(allFiles(hash, paths.subList(start, end)));
start = end;
}
return entries;
}

@Override
public List<StatusEntry> status(Hash from, Hash to) throws IOException {
var ext = Files.createTempFile("ext", ".py");
Expand Down Expand Up @@ -938,28 +957,55 @@ public void move(Path from, Path to) throws IOException {
}
}

@Override
public void remove(List<Path> paths) throws IOException {
var cmd = new ArrayList<>(List.of("hg", "rm"));
for (var p : paths) {
cmd.add(p.toString());
@FunctionalInterface
private static interface Operation {
void execute(List<Path> args) throws IOException;
}

private void batch(Operation op, List<Path> args) throws IOException {
var batchSize = 64;
var start = 0;
while (start < args.size()) {
var end = start + batchSize;
if (end > args.size()) {
end = args.size();
}
op.execute(args.subList(start, end));
start = end;
}
}

private void addAll(List<Path> paths) throws IOException {
var cmd = new ArrayList<>(List.of("hg", "add"));
for (var path : paths) {
cmd.add(path.toString());
}
try (var p = capture(cmd)) {
await(p);
}
}

@Override
public void add(List<Path> paths) throws IOException {
var cmd = new ArrayList<>(List.of("hg", "add"));
for (var p : paths) {
cmd.add(p.toString());
private void removeAll(List<Path> paths) throws IOException {
var cmd = new ArrayList<>(List.of("hg", "rm"));
for (var path : paths) {
cmd.add(path.toString());
}
try (var p = capture(cmd)) {
await(p);
}
}


@Override
public void remove(List<Path> paths) throws IOException {
batch(this::removeAll, paths);
}

@Override
public void add(List<Path> paths) throws IOException {
batch(this::addAll, paths);
}

@Override
public void addremove() throws IOException {
try (var p = capture("hg", "addremove")) {
Expand Down