Skip to content

Commit af0cd2b

Browse files
author
Gabriel Roldan
committed
Improved ProgressListener.setDescription() and added some more calls in remoting commands
Signed-off-by: Gabriel Roldan <[email protected]>
1 parent 2b615b0 commit af0cd2b

File tree

15 files changed

+54
-36
lines changed

15 files changed

+54
-36
lines changed

src/api/src/main/java/org/locationtech/geogig/model/Ref.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public int compareTo(Ref o) {
265265
*/
266266
@Override
267267
public String toString() {
268-
return String.format("Ref[%s -> %s]", name, objectId);
268+
return String.format("[%s -> %s]", name, objectId);
269269
}
270270

271271
public static String append(String namespace, String child) {

src/api/src/main/java/org/locationtech/geogig/model/SymRef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public String getTarget() {
5353

5454
@Override
5555
public String toString() {
56-
return String.format("SymRef[%s -> Ref[%s -> %s]]", getName(), target, getObjectId());
56+
return String.format("%s -> [%s -> %s]", getName(), target, getObjectId());
5757
}
5858

5959
/**

src/api/src/main/java/org/locationtech/geogig/repository/DefaultProgressListener.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,9 @@ public String getDescription() {
6262
return description;
6363
}
6464

65-
/**
66-
* Sets the description of the task.
67-
*
68-
* @param description the text to use for the description
69-
*/
7065
@Override
71-
public void setDescription(String description) {
72-
this.description = description;
66+
public void setDescription(String format, Object... args) {
67+
this.description = String.format(format, args);
7368
}
7469

7570
/**

src/api/src/main/java/org/locationtech/geogig/repository/ProgressListener.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ public default String getProgressDescription() {
4444
/**
4545
* Sets the description of the current task being run
4646
*
47-
* @param description
47+
* @param format description format like in {@link String#format}
48+
* @param args format arguments like in {@link String#format}
4849
*/
49-
void setDescription(String description);
50+
void setDescription(String format, Object... args);
5051

5152
/**
5253
* Notifies this listener that the operation begins.
@@ -60,7 +61,7 @@ public default String getProgressDescription() {
6061
*
6162
*/
6263
void setProgress(float progress);
63-
64+
6465
void incrementBy(float amount);
6566

6667
/**

src/api/src/main/java/org/locationtech/geogig/repository/Remote.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public String getPassword() {
229229
}
230230

231231
public @Override String toString() {
232-
return String.format("%s", getName());
232+
return String.format("%s [%s]", getName(), fetch);
233233
}
234234

235235
/**

src/api/src/main/java/org/locationtech/geogig/repository/SubProgressListener.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,9 @@ public void setProgress(float progress) {
7777
parentProgressListener.setProgress(start + (amount * percent));
7878
}
7979

80-
/**
81-
* Sets the description of the task.
82-
*
83-
* @param description the text to use for the description
84-
*/
8580
@Override
86-
public void setDescription(String description) {
87-
parentProgressListener.setDescription(description);
81+
public void setDescription(String format, Object... args) {
82+
parentProgressListener.setDescription(format, args);
8883
}
8984

9085
/**

src/api/src/test/java/org/locationtech/geogig/model/RefTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void testConstructor() throws Exception {
4343
public void testToString() throws Exception {
4444
Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);
4545

46-
assertEquals("Ref[" + testRef.getName() + " -> " + testRef.getObjectId().toString() + "]",
46+
assertEquals("[" + testRef.getName() + " -> " + testRef.getObjectId().toString() + "]",
4747
testRef.toString());
4848
}
4949

src/cli/core/src/main/java/org/locationtech/geogig/cli/GeogigCLI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,11 @@ public void started() {
798798
}
799799

800800
@Override
801-
public void setDescription(String s) {
801+
public void setDescription(String s, Object... args) {
802802
lastRun = platform.nanoTime();
803803
try {
804804
console.println();
805-
console.println(s);
805+
console.println(String.format(s, args));
806806
console.flush();
807807
} catch (IOException e) {
808808
throw new RuntimeException(e);

src/core/src/main/java/org/locationtech/geogig/porcelain/MergeOp.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ protected MergeReport _call() throws RuntimeException {
203203

204204
// capture original values in case the operation is cancelled
205205
origHead = currHead.get();
206+
getProgressListener().setDescription(String.format("Merge: merging %s onto %s", commits, origHead));
206207
if (origHead instanceof SymRef) {
207208
final String currentBranch = ((SymRef) origHead).getTarget();
208209
origCurrentBranch = command(RefParse.class).setName(currentBranch).call().get();
@@ -290,17 +291,18 @@ protected MergeReport _call() throws RuntimeException {
290291
"Conflicted merge.\nCannot merge more than two commits when conflicts exist"
291292
+ " or features have been modified in several histories");
292293
for (ObjectId commitId : commits) {
293-
progress.setDescription("Merging commit " + commitId);
294-
295294
if (headRef.getObjectId().isNull()) {
296295
// Fast-forward
297296
headRef = doFastForwardMerge(headRef, commitId, mergeStatusBuilder);
298297
continue;
299298
}
300-
301-
RevCommit headCommit = repository().getCommit(headRef.getObjectId());
299+
final RevCommit headCommit = repository().getCommit(headRef.getObjectId());
302300
final RevCommit targetCommit = repository().getCommit(commitId);
303301

302+
progress.setDescription(String.format("Merging commit %s onto %s",
303+
fmt(targetCommit), fmt(headCommit)));
304+
305+
304306
Optional<ObjectId> ancestorCommit = command(FindCommonAncestor.class)
305307
.setLeft(headCommit).setRight(targetCommit).call();
306308

@@ -346,22 +348,32 @@ protected MergeReport _call() throws RuntimeException {
346348

347349
progress.complete();
348350
}
349-
350351
if (!mergeStatusBuilder.isChanged()) {
352+
progress.setDescription("Merge: complete, nothing to merge.");
351353
throw new NothingToCommitException("The branch has already been merged.");
352354
}
353355
if (noFastForward) {
354356
mergeStatusBuilder.setFastFoward(false);
355357
}
358+
progress.setDescription("Creating merge commit");
356359
RevCommit mergeCommit = commit(mergeStatusBuilder.isFastForward());
357360

361+
progress.setDescription("Merge: created merge commit " + mergeCommit);
358362
MergeReport result = new MergeReport(mergeCommit, Optional.fromNullable(mergeScenario),
359363
oursId, pairs);
360364

361365
return result;
362366

363367
}
364368

369+
private String fmt(RevCommit c) {
370+
String msg = c.getMessage();
371+
if (msg.length() > 30) {
372+
msg = msg.substring(0, 30) + "...";
373+
}
374+
return String.format("%s (%s)", c.getId().toString().substring(0, 8), msg);
375+
}
376+
365377
private MergeReport abort() {
366378
command(CleanRefsOp.class).call();
367379
conflictsDatabase().removeConflicts(null);
@@ -370,6 +382,9 @@ private MergeReport abort() {
370382

371383
private Ref doFastForwardMerge(Ref headRef, ObjectId commitId,
372384
MergeStatusBuilder mergeStatusBuilder) {
385+
getProgressListener().setDescription(String.format("Fast forward merging %s onto %s",
386+
commitId.toString().substring(0, 8),
387+
headRef.getObjectId().toString().substring(0, 8)));
373388
if (headRef instanceof SymRef) {
374389
final String currentBranch = ((SymRef) headRef).getTarget();
375390
command(UpdateRef.class).setName(currentBranch).setNewValue(commitId).call();

src/core/src/main/java/org/locationtech/geogig/repository/impl/GeogigTransaction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@ public void commit(ProgressListener listener) throws ConflictsException {
167167
}
168168

169169
public void commitSyncTransaction() throws ConflictsException {
170+
commitSyncTransaction(DefaultProgressListener.NULL);
171+
}
172+
173+
public void commitSyncTransaction(ProgressListener listener) throws ConflictsException {
170174
context.command(TransactionEnd.class).setAuthor(authorName.orNull(), authorEmail.orNull())
171-
.setTransaction(this).setCancel(false).call();
175+
.setTransaction(this).setCancel(false).setProgressListener(listener).call();
172176
}
173177

174178
public void abort() {

0 commit comments

Comments
 (0)