Skip to content

Commit

Permalink
We are trying to fulfill each request 3 times before the error
Browse files Browse the repository at this point in the history
  • Loading branch information
bozaro committed Aug 22, 2015
1 parent 31351cf commit 724e0d3
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/main/java/git/lfs/migrate/GitConverter.java
Expand Up @@ -31,6 +31,7 @@
public class GitConverter {
@NotNull
private static final String GIT_ATTRIBUTES = ".gitattributes";
private static final int PASS_COUNT = 3;
@Nullable
private final URL lfs;
@NotNull
Expand Down Expand Up @@ -264,7 +265,7 @@ public ObjectId convert(@NotNull ObjectInserter inserter, @NotNull ConvertResolv
throw new IOException("Can't rename file: " + tmpFile + " -> " + lfsFile);
}
// Upload file.
checkAndUpload(loader, hash);
reply(() -> checkAndUpload(loader, hash));
// Create pointer.
StringWriter pointer = new StringWriter();
pointer.write("version https://git-lfs.github.com/spec/v1\n");
Expand Down Expand Up @@ -313,12 +314,22 @@ private void checkAndUpload(@NotNull ObjectLoader loader, @NotNull String hash)
}

// Upload data.
PutMethod put = new PutMethod(upload.get("href").getAsString());
Map<String, String> header = new HashMap<>();
final Map<String, String> header = new HashMap<>();
for (Map.Entry<String, JsonElement> entry : upload.get("header").getAsJsonObject().entrySet()) {
header.put(entry.getKey(), entry.getValue().getAsString());
}
upload(loader, hash, upload.get("href").getAsString(), header);
reply(() -> upload(loader, hash, upload.get("href").getAsString(), header));
}

private void reply(@NotNull UploadTask href) throws IOException {
for (int pass = 0; pass < PASS_COUNT - 1; ++pass) {
try {
href.exec();
return;
} catch (IOException ignored) {
}
}
href.exec();
}

private void upload(@NotNull ObjectLoader loader, @NotNull String hash, @NotNull String href, @NotNull Map<String, String> header) throws IOException {
Expand Down Expand Up @@ -405,6 +416,11 @@ public enum TaskType {
Simple, Root, Attribute, UploadLfs,
}

@FunctionalInterface
public interface UploadTask {
void exec() throws IOException;
}

public interface ConvertResolver {
@NotNull
ObjectId resolve(@NotNull TaskKey key);
Expand Down

0 comments on commit 724e0d3

Please sign in to comment.