Skip to content

Commit

Permalink
Add mch commit --verbose and move "empty region file" behind that flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvinn8 committed May 26, 2024
1 parent 2c15d09 commit 1a40d6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion mch-cli/src/main/java/ca/bkaw/mch/cli/CommitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ public class CommitCommand implements Runnable {
@Option(names = "--no-cache", negatable = true, defaultValue = "true", description = "Skip caching by looking at the current commit.")
boolean cache;

@Option(names = "--verbose", defaultValue = "false", description = "Print more information while processing the commit.")
boolean verbose;

@Override
public void run() {
try {
CommitOperation.run(this.repository, this.commitMessage, this.cache);
CommitOperation.run(this.repository, this.commitMessage, this.cache, this.verbose);
} catch (IOException e) {
System.err.println("Failed to commit.");
e.printStackTrace();
Expand Down
15 changes: 13 additions & 2 deletions mch/src/main/java/ca/bkaw/mch/operation/CommitOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Utility class for performing a commit.
*/
public class CommitOperation {
public static void run(MchRepository repository, String commitMessage, boolean cache) throws IOException {
public static void run(MchRepository repository, String commitMessage, boolean cache, boolean verbose) throws IOException {
long start = System.currentTimeMillis();

// Read configuration and current commit from repository
Expand Down Expand Up @@ -86,12 +86,16 @@ public static void run(MchRepository repository, String commitMessage, boolean c

// Store region files
int unmodifiedRegionFiles = 0;
int emptyRegionFiles = 0;

for (RegionFileInfo regionFileInfo : worldProvider.getRegionFiles(dimensionKey)) {
if (regionFileInfo.fileSize() == 0) {
// I am not sure how or why these empty region files are created, but since they
// are 0 bytes they do not contain valid data. Skip them to avoid crashing.
System.out.println(" Skipping empty file (0 bytes): " + regionFileInfo.fileName());
if (verbose) {
System.out.println(" Skipping empty file (0 bytes): " + regionFileInfo.fileName());
}
emptyRegionFiles++;
continue;
}

Expand All @@ -105,6 +109,9 @@ public static void run(MchRepository repository, String commitMessage, boolean c
// changed.
// We can simply reference the same version number that the previous commit has.
dimension.addRegionFile(currentRegionFileInfo);
if (verbose) {
System.out.println(" Not modified: " + regionFileInfo.fileName());
}
unmodifiedRegionFiles++;
continue;
}
Expand Down Expand Up @@ -194,6 +201,10 @@ public static void run(MchRepository repository, String commitMessage, boolean c
dimension.addRegionFile(regionFileReference);
}

System.out.println(" " + emptyRegionFiles
+ (emptyRegionFiles == 1 ? " region file" : " region files")
+ " were empty (0 bytes)");

System.out.println(" " + unmodifiedRegionFiles
+ (unmodifiedRegionFiles == 1 ? " region file" : " region files")
+ " were not modified");
Expand Down

0 comments on commit 1a40d6e

Please sign in to comment.