Skip to content

Commit faa4d1f

Browse files
authored
Merge pull request #978 from launchableinc/LCHIB-544
[LCHIB-544] proactively watch out for shallow clones and warn users
2 parents 4dacffd + 93f3a4b commit faa4d1f

File tree

3 files changed

+52
-28
lines changed

3 files changed

+52
-28
lines changed

launchable/jar/exe_deploy.jar

266 Bytes
Binary file not shown.

src/main/java/com/launchableinc/ingest/commits/CommitGraphCollector.java

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.launchableinc.ingest.commits;
22

3-
import static com.google.common.collect.ImmutableList.toImmutableList;
4-
import static java.util.Arrays.*;
5-
63
import com.fasterxml.jackson.core.JsonFactory;
74
import com.fasterxml.jackson.core.JsonGenerator;
85
import com.fasterxml.jackson.core.JsonParser;
@@ -11,26 +8,6 @@
118
import com.fasterxml.jackson.databind.node.ObjectNode;
129
import com.google.common.collect.ImmutableList;
1310
import com.google.common.io.CharStreams;
14-
import java.io.ByteArrayInputStream;
15-
import java.io.ByteArrayOutputStream;
16-
import java.io.Closeable;
17-
import java.io.IOException;
18-
import java.io.InputStreamReader;
19-
import java.io.OutputStream;
20-
import java.io.UncheckedIOException;
21-
import java.net.URL;
22-
import java.nio.charset.StandardCharsets;
23-
import java.util.ArrayList;
24-
import java.util.Arrays;
25-
import java.util.Collection;
26-
import java.util.List;
27-
import java.util.Objects;
28-
import java.util.concurrent.TimeUnit;
29-
import java.util.function.Consumer;
30-
import java.util.function.Supplier;
31-
import java.util.stream.Collectors;
32-
import java.util.zip.GZIPInputStream;
33-
import java.util.zip.GZIPOutputStream;
3411
import org.apache.http.Header;
3512
import org.apache.http.HttpResponse;
3613
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -58,6 +35,30 @@
5835
import org.slf4j.Logger;
5936
import org.slf4j.LoggerFactory;
6037

38+
import java.io.ByteArrayInputStream;
39+
import java.io.ByteArrayOutputStream;
40+
import java.io.Closeable;
41+
import java.io.IOException;
42+
import java.io.InputStreamReader;
43+
import java.io.OutputStream;
44+
import java.io.UncheckedIOException;
45+
import java.net.URL;
46+
import java.nio.charset.StandardCharsets;
47+
import java.util.ArrayList;
48+
import java.util.Collection;
49+
import java.util.List;
50+
import java.util.Objects;
51+
import java.util.Set;
52+
import java.util.concurrent.TimeUnit;
53+
import java.util.function.Consumer;
54+
import java.util.function.Supplier;
55+
import java.util.stream.Collectors;
56+
import java.util.zip.GZIPInputStream;
57+
import java.util.zip.GZIPOutputStream;
58+
59+
import static com.google.common.collect.ImmutableList.*;
60+
import static java.util.Arrays.*;
61+
6162
/**
6263
* Compares what commits the local repository and the remote repository have, then send delta over.
6364
*/
@@ -293,10 +294,12 @@ final class ByRepository implements AutoCloseable {
293294
private final Repository git;
294295

295296
private final ObjectReader objectReader;
297+
private final Set<ObjectId> shallowCommits;
296298

297-
ByRepository(Repository git) {
299+
ByRepository(Repository git) throws IOException {
298300
this.git = git;
299301
this.objectReader = git.newObjectReader();
302+
this.shallowCommits = objectReader.getShallowCommits();
300303
}
301304

302305
/**
@@ -411,12 +414,18 @@ private JSCommit transform(RevCommit r) throws IOException {
411414
ConfigConstants.CONFIG_KEY_ALGORITHM,
412415
SupportedAlgorithm.HISTOGRAM);
413416

417+
414418
if (LCHIB544) {
415419
System.err.printf("Commit %s parents=%s%n",
416420
r.name(),
417421
stream(r.getParents()).map(AnyObjectId::name).collect(Collectors.joining(",")));
418422
}
419423

424+
if (shallowCommits.contains(r)) {
425+
c.setShallow(true);
426+
warnMissingObject();
427+
}
428+
420429
for (RevCommit p : r.getParents()) {
421430
CountingDiffFormatter diff = new CountingDiffFormatter(git);
422431
List<DiffEntry> files = diff.scan(p.getTree(), r.getTree());
@@ -431,10 +440,7 @@ private JSCommit transform(RevCommit r) throws IOException {
431440
p.abbreviate(7).name(),
432441
r.abbreviate(7).name()
433442
);
434-
if (!warnMissingObject) {
435-
warnMissingObject = true;
436-
System.err.println("See https://www.launchableinc.com/missing-git-object-during-commit-collection");
437-
}
443+
warnMissingObject();
438444
} catch (IOException e) {
439445
logger.warn("Failed to process a change to a file", e);
440446
}
@@ -449,6 +455,13 @@ private JSCommit transform(RevCommit r) throws IOException {
449455
return c;
450456
}
451457

458+
private void warnMissingObject() {
459+
if (!warnMissingObject) {
460+
warnMissingObject = true;
461+
System.err.println("See https://www.launchableinc.com/missing-git-object-during-commit-collection");
462+
}
463+
}
464+
452465
@Override
453466
public void close() {
454467
objectReader.close();

src/main/java/com/launchableinc/ingest/commits/JSCommit.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class JSCommit {
3434
/** Commit message. */
3535
private String message;
3636

37+
/** This object was marked as shallow and therefore its parent commits are not available. */
38+
private boolean shallow;
39+
3740
private Map<String, List<JSFileChange>> parentHashes = new HashMap<>();
3841

3942
public String getCommitHash() {
@@ -107,4 +110,12 @@ public String getMessage() {
107110
public void setMessage(String message) {
108111
this.message = message;
109112
}
113+
114+
public boolean isShallow() {
115+
return shallow;
116+
}
117+
118+
public void setShallow(boolean shallow) {
119+
this.shallow = shallow;
120+
}
110121
}

0 commit comments

Comments
 (0)