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

Make fetchAll the opposite of pushAll #905

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
Expand Up @@ -269,7 +269,7 @@ private Repository cloneAndSyncFork(Path to) throws IOException {
}

// Must fetch once to update refs/heads
repo.fetchAll(false);
repo.fetchAllRemotes(false);

return repo;
}
Expand Down
Expand Up @@ -89,7 +89,7 @@ public Collection<WorkItem> run(Path scratchPath) {

if (shouldMirrorEverything) {
log.info("Pulling " + from.name());
repo.fetchAll(false);
repo.fetchAll(from.url(), false);
log.info("Pushing to " + to.name());
repo.pushAll(to.url());
} else {
Expand Down
Expand Up @@ -265,7 +265,7 @@ public Collection<WorkItem> run(Path scratchPath) {
.stream()
.filter(ref -> branches.matcher(ref.name()).matches())
.collect(Collectors.toList());
localRepo.fetchAll(true);
localRepo.fetchAll(repository.url(), true);

var history = UpdateHistory.create(tagStorageBuilder, historyPath.resolve("tags"), branchStorageBuilder, historyPath.resolve("branches"));
var errors = new ArrayList<Throwable>();
Expand Down
Expand Up @@ -80,7 +80,7 @@ public Collection<WorkItem> run(Path scratchPath) {
.orElseThrow(() -> new RuntimeException("Repository in " + dir + " has vanished"));
}

repo.fetchAll(false);
repo.fetchAllRemotes(false);
var depsFile = repo.root().resolve(depsFileName);

var orderedBranches = orderedBranches(repo, depsFile);
Expand Down
Expand Up @@ -95,7 +95,7 @@ private void refreshSeed(boolean allowStale) throws IOException {
IOException lastException = null;
for (int counter = 0; counter < 5; counter++) {
try {
seedRepo.fetch(hostedRepository.url(), "+*:*", true);
seedRepo.fetchAll(hostedRepository.url(), true);
} catch (IOException e) {
if (!allowStale) {
lastException = e;
Expand Down
10 changes: 7 additions & 3 deletions vcs/src/main/java/org/openjdk/skara/vcs/Repository.java
Expand Up @@ -45,10 +45,14 @@ default Hash fetch(URI uri, String refspec) throws IOException {
return fetch(uri, refspec, true);
}
Hash fetch(URI uri, String refspec, boolean includeTags) throws IOException;
default void fetchAll() throws IOException {
fetchAll(false);
default void fetchAll(URI uri) throws IOException {
fetchAll(uri, true);
}
void fetchAll(boolean includeTags) throws IOException;
void fetchAll(URI uri, boolean includeTags) throws IOException;
default void fetchAllRemotes() throws IOException {
fetchAllRemotes(false);
}
void fetchAllRemotes(boolean includeTags) throws IOException;
void fetchRemote(String remote) throws IOException;
void pushAll(URI uri) throws IOException;
void push(Hash hash, URI uri, String ref, boolean force) throws IOException;
Expand Down
14 changes: 13 additions & 1 deletion vcs/src/main/java/org/openjdk/skara/vcs/git/GitRepository.java
Expand Up @@ -469,7 +469,19 @@ public Hash fetch(URI uri, String refspec, boolean includeTags) throws IOExcepti
}

@Override
public void fetchAll(boolean includeTags) throws IOException {
public void fetchAll(URI uri, boolean includeTags) throws IOException {
var cmd = new ArrayList<>(List.of("git", "fetch", "--recurse-submodules=on-demand", "--prune", uri.toString()));
cmd.add("+refs/heads/*:refs/heads/*");
if (includeTags) {
cmd.add("+refs/tags/*:refs/tags/*");
}
try (var p = capture(cmd)) {
await(p);
}
}

@Override
public void fetchAllRemotes(boolean includeTags) throws IOException {
var cmd = new ArrayList<String>();
cmd.addAll(List.of("git", "fetch", "--recurse-submodules=on-demand"));
cmd.add("--prune");
Expand Down
14 changes: 13 additions & 1 deletion vcs/src/main/java/org/openjdk/skara/vcs/hg/HgRepository.java
Expand Up @@ -448,6 +448,18 @@ public Hash fetch(URI uri, String refspec, boolean includeTags) throws IOExcepti
return fetch(uri != null ? uri.toString() : null, refspec);
}

@Override
public void fetchAll(URI uri, boolean includeTags) throws IOException {
// Ignore includeTags, Mercurial always fetches tags
var cmd = new ArrayList<String>();
cmd.add("hg");
cmd.add("pull");
cmd.add(uri.toString());
try (var p = capture(cmd)) {
await(p);
}
}

private Hash fetch(String from, String refspec) throws IOException {
var oldHeads = new HashSet<Hash>(heads());

Expand Down Expand Up @@ -478,7 +490,7 @@ private Hash fetch(String from, String refspec) throws IOException {
}

@Override
public void fetchAll(boolean includeTags) throws IOException {
public void fetchAllRemotes(boolean includeTags) throws IOException {
// Ignore includeTags, Mercurial always fetches tags
var pullPaths = new ArrayList<URI>();
try (var p = capture("hg", "paths")) {
Expand Down