Skip to content
Permalink
Browse files
git-webrev: add --similarity flag
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Aug 15, 2020
1 parent 49868fe commit 1aa66a53413ccd4d949cbb816593d2b753b81dc5
@@ -127,6 +127,11 @@ private static void generate(String[] args) throws IOException {
.describe("NAME")
.helptext("Use remote to calculate outgoing changes")
.optional(),
Option.shortcut("s")
.fullname("similarity")
.describe("SIMILARITY")
.helptext("Guess renamed files by similarity (0 - 100)")
.optional(),
Switch.shortcut("b")
.fullname("")
.helptext("Do not ignore changes in whitespace (always true)")
@@ -352,6 +357,22 @@ private static void generate(String[] args) throws IOException {
}
}

var similarity = 90;
try {
var similarityArg = arg("similarity", arguments, repo);
if (similarityArg != null) {
var value = Integer.parseInt(similarityArg);
if (value < 0 || value > 100) {
System.err.println("error: --similarity must be a number between 0 and 100");
System.exit(1);
}
similarity = value;
}
} catch (NumberFormatException e) {
System.err.println("error: --similarity must be a number between 0 and 100");
System.exit(1);
}

var jbs = "https://bugs.openjdk.java.net/browse/";
var issueParts = issue != null ? issue.split("-") : new String[0];
var jbsProject = issueParts.length == 2 && KNOWN_JBS_PROJECTS.contains(issueParts[0])?
@@ -366,6 +387,7 @@ private static void generate(String[] args) throws IOException {
.issue(issue)
.version(version)
.files(files)
.similarity(similarity)
.generate(rev);
}

@@ -234,19 +234,19 @@ public List<FileEntry> files(Hash h, List<Path> paths) throws IOException {
public void dump(FileEntry entry, Path to) throws IOException {
}

public Diff diff(Hash base, Hash head) throws IOException {
public Diff diff(Hash base, Hash head, int similarity) throws IOException {
return null;
}

public Diff diff(Hash base, Hash head, List<Path> files) throws IOException {
public Diff diff(Hash base, Hash head, List<Path> files, int similarity) throws IOException {
return null;
}

public Diff diff(Hash head) throws IOException {
public Diff diff(Hash head, int similarity) throws IOException {
return null;
}

public Diff diff(Hash head, List<Path> files) throws IOException {
public Diff diff(Hash head, List<Path> files, int similarity) throws IOException {
return null;
}

@@ -102,10 +102,25 @@ default List<FileEntry> files(Hash h, Path... paths) throws IOException {
void dump(FileEntry entry, Path to) throws IOException;
List<StatusEntry> status(Hash from, Hash to) throws IOException;
List<StatusEntry> status() throws IOException;
Diff diff(Hash base, Hash head) throws IOException;
Diff diff(Hash base, Hash head, List<Path> files) throws IOException;
Diff diff(Hash head) throws IOException;
Diff diff(Hash head, List<Path> files) throws IOException;

static final int DEFAULT_SIMILARITY = 90;
default Diff diff(Hash base, Hash head) throws IOException {
return diff(base, head, DEFAULT_SIMILARITY);
}
Diff diff(Hash base, Hash head, int similarity) throws IOException;
default Diff diff(Hash base, Hash head, List<Path> files) throws IOException {
return diff(base, head, files, DEFAULT_SIMILARITY);
}
Diff diff(Hash base, Hash head, List<Path> files, int similarity) throws IOException;
default Diff diff(Hash head) throws IOException {
return diff(head, DEFAULT_SIMILARITY);
}
Diff diff(Hash head, int similarity) throws IOException;
default Diff diff(Hash head, List<Path> files) throws IOException {
return diff(head, files, DEFAULT_SIMILARITY);
}

Diff diff(Hash head, List<Path> files, int similarity) throws IOException;
List<String> config(String key) throws IOException;
Repository copyTo(Path destination) throws IOException;
String pullPath(String remote) throws IOException;
@@ -998,25 +998,28 @@ public List<StatusEntry> status() throws IOException {
}

@Override
public Diff diff(Hash from) throws IOException {
return diff(from, List.of());
public Diff diff(Hash from, int similarity) throws IOException {
return diff(from, List.of(), similarity);
}

@Override
public Diff diff(Hash from, List<Path> files) throws IOException {
return diff(from, null, files);
public Diff diff(Hash from, List<Path> files, int similarity) throws IOException {
return diff(from, null, files, similarity);
}

@Override
public Diff diff(Hash from, Hash to) throws IOException {
return diff(from, to, List.of());
public Diff diff(Hash from, Hash to, int similarity) throws IOException {
return diff(from, to, List.of(), similarity);
}

@Override
public Diff diff(Hash from, Hash to, List<Path> files) throws IOException {
public Diff diff(Hash from, Hash to, List<Path> files, int similarity) throws IOException {
if (similarity < 0 || similarity > 100) {
throw new IllegalArgumentException("similarity must be between 0 and 100, is: " + similarity);
}
var cmd = new ArrayList<>(List.of("git", "diff", "--patch",
"--find-renames=90%",
"--find-copies=90%",
"--find-renames=" + similarity + "%",
"--find-copies=" + similarity + "%",
"--find-copies-harder",
"--binary",
"--raw",
@@ -846,22 +846,22 @@ public void revert(Hash parent) throws IOException {
}

@Override
public Diff diff(Hash from) throws IOException {
public Diff diff(Hash from, int similarity) throws IOException {
return diff(from, List.of());
}

@Override
public Diff diff(Hash from, List<Path> files) throws IOException {
public Diff diff(Hash from, List<Path> files, int similarity) throws IOException {
return diff(from, null, files);
}

@Override
public Diff diff(Hash from, Hash to) throws IOException {
public Diff diff(Hash from, Hash to, int similarity) throws IOException {
return diff(from, to, List.of());
}

@Override
public Diff diff(Hash from, Hash to, List<Path> files) throws IOException {
public Diff diff(Hash from, Hash to, List<Path> files, int similarity) throws IOException {
var ext = Files.createTempFile("ext", ".py");
copyResource(EXT_PY, ext);

@@ -74,6 +74,7 @@ public static class Builder {
private Function<String, String> commitLinker;
private String version;
private List<Path> files = List.of();
private int similarity = 90;

Builder(ReadOnlyRepository repository, Path output) {
this.repository = repository;
@@ -130,14 +131,19 @@ public Builder files(List<Path> files) {
return this;
}

public Builder similarity(int similarity) {
this.similarity = similarity;
return this;
}

public void generate(Hash tailEnd) throws IOException {
generate(tailEnd, null);
}

public void generate(Hash tailEnd, Hash head) throws IOException {
var diff = head == null ?
repository.diff(tailEnd, files) :
repository.diff(tailEnd, head, files);
repository.diff(tailEnd, files, similarity) :
repository.diff(tailEnd, head, files, similarity);
generate(diff, tailEnd, head);
}

1 comment on commit 1aa66a5

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 1aa66a5 Aug 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.