Skip to content

Commit

Permalink
Improved ProgressListener.setDescription() and added some more calls …
Browse files Browse the repository at this point in the history
…in remoting commands

Signed-off-by: Gabriel Roldan <[email protected]>
  • Loading branch information
Gabriel Roldan committed Sep 12, 2018
1 parent 2b615b0 commit 2e0a92f
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public int compareTo(Ref o) {
*/
@Override
public String toString() {
return String.format("Ref[%s -> %s]", name, objectId);
return String.format("[%s -> %s]", name, objectId);
}

public static String append(String namespace, String child) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String getTarget() {

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,9 @@ public String getDescription() {
return description;
}

/**
* Sets the description of the task.
*
* @param description the text to use for the description
*/
@Override
public void setDescription(String description) {
this.description = description;
public void setDescription(String format, Object... args) {
this.description = String.format(format, args);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ public default String getProgressDescription() {
/**
* Sets the description of the current task being run
*
* @param description
* @param format description format like in {@link String#format}
* @param args format arguments like in {@link String#format}
*/
void setDescription(String description);
void setDescription(String format, Object... args);

/**
* Notifies this listener that the operation begins.
Expand All @@ -60,7 +61,7 @@ public default String getProgressDescription() {
*
*/
void setProgress(float progress);

void incrementBy(float amount);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public String getPassword() {
}

public @Override String toString() {
return String.format("%s", getName());
return String.format("%s [%s]", getName(), fetch);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,9 @@ public void setProgress(float progress) {
parentProgressListener.setProgress(start + (amount * percent));
}

/**
* Sets the description of the task.
*
* @param description the text to use for the description
*/
@Override
public void setDescription(String description) {
parentProgressListener.setDescription(description);
public void setDescription(String format, Object... args) {
parentProgressListener.setDescription(format, args);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testConstructor() throws Exception {
public void testToString() throws Exception {
Ref testRef = new Ref(Ref.REFS_PREFIX + "commit1", oid);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void testSymRef() {

String symRefString = symRef.toString();

assertEquals("SymRef[TestRef -> " + "Ref[" + testRef.getName() + " -> "
+ testRef.getObjectId().toString() + "]]", symRefString);
assertEquals("TestRef -> " + "[" + testRef.getName() + " -> "
+ testRef.getObjectId().toString() + "]", symRefString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,11 @@ public void started() {
}

@Override
public void setDescription(String s) {
public void setDescription(String s, Object... args) {
lastRun = platform.nanoTime();
try {
console.println();
console.println(s);
console.println(String.format(s, args));
console.flush();
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ protected MergeReport _call() throws RuntimeException {

// capture original values in case the operation is cancelled
origHead = currHead.get();
getProgressListener().setDescription(String.format("Merge: merging %s onto %s", commits, origHead));
if (origHead instanceof SymRef) {
final String currentBranch = ((SymRef) origHead).getTarget();
origCurrentBranch = command(RefParse.class).setName(currentBranch).call().get();
Expand Down Expand Up @@ -290,17 +291,18 @@ protected MergeReport _call() throws RuntimeException {
"Conflicted merge.\nCannot merge more than two commits when conflicts exist"
+ " or features have been modified in several histories");
for (ObjectId commitId : commits) {
progress.setDescription("Merging commit " + commitId);

if (headRef.getObjectId().isNull()) {
// Fast-forward
headRef = doFastForwardMerge(headRef, commitId, mergeStatusBuilder);
continue;
}

RevCommit headCommit = repository().getCommit(headRef.getObjectId());
final RevCommit headCommit = repository().getCommit(headRef.getObjectId());
final RevCommit targetCommit = repository().getCommit(commitId);

progress.setDescription(String.format("Merging commit %s onto %s",
fmt(targetCommit), fmt(headCommit)));


Optional<ObjectId> ancestorCommit = command(FindCommonAncestor.class)
.setLeft(headCommit).setRight(targetCommit).call();

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

progress.complete();
}

if (!mergeStatusBuilder.isChanged()) {
progress.setDescription("Merge: complete, nothing to merge.");
throw new NothingToCommitException("The branch has already been merged.");
}
if (noFastForward) {
mergeStatusBuilder.setFastFoward(false);
}
progress.setDescription("Creating merge commit");
RevCommit mergeCommit = commit(mergeStatusBuilder.isFastForward());

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

return result;

}

private String fmt(RevCommit c) {
String msg = c.getMessage();
if (msg.length() > 30) {
msg = msg.substring(0, 30) + "...";
}
return String.format("%s (%s)", c.getId().toString().substring(0, 8), msg);
}

private MergeReport abort() {
command(CleanRefsOp.class).call();
conflictsDatabase().removeConflicts(null);
Expand All @@ -370,6 +382,9 @@ private MergeReport abort() {

private Ref doFastForwardMerge(Ref headRef, ObjectId commitId,
MergeStatusBuilder mergeStatusBuilder) {
getProgressListener().setDescription(String.format("Fast forward merging %s onto %s",
commitId.toString().substring(0, 8),
headRef.getObjectId().toString().substring(0, 8)));
if (headRef instanceof SymRef) {
final String currentBranch = ((SymRef) headRef).getTarget();
command(UpdateRef.class).setName(currentBranch).setNewValue(commitId).call();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ public void commit(ProgressListener listener) throws ConflictsException {
}

public void commitSyncTransaction() throws ConflictsException {
commitSyncTransaction(DefaultProgressListener.NULL);
}

public void commitSyncTransaction(ProgressListener listener) throws ConflictsException {
context.command(TransactionEnd.class).setAuthor(authorName.orNull(), authorEmail.orNull())
.setTransaction(this).setCancel(false).call();
.setTransaction(this).setCancel(false).setProgressListener(listener).call();
}

public void abort() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ public void testComplex() throws Exception {

protected static final ProgressListener SIMPLE_PROGRESS = new DefaultProgressListener() {
public @Override
void setDescription(String msg) {
System.err.println(msg);
void setDescription(String msg, Object... args) {
System.err.printf(msg+"\n", args);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ protected PullResult _call() {
}

getProgressListener().started();
getProgressListener().setDescription("Pull: pulling " + remote);

PullResult result = new PullResult();
TransferSummary fetchResult = command(FetchOp.class)//
.addRemote(remote)//
.setDepth(depth.or(0))//
.setFullDepth(fullDepth)//
.setAllRemotes(all)//
.setProgressListener(subProgress(80.f))//
.setProgressListener(getProgressListener())//
.call();

result.setFetchResult(fetchResult);
Expand All @@ -242,8 +243,10 @@ protected PullResult _call() {
}
final Ref localRemoteRef = localRemoteRefOpt.get();
if (rebase) {
getProgressListener().setDescription("Pull: rebasing...");
command(RebaseOp.class).setUpstream(() -> localRemoteRef.getObjectId()).call();
} else {
getProgressListener().setDescription("Pull: merging...");
String message = this.message;
if (noFastForward && Strings.isNullOrEmpty(message)) {
message = String.format("Pull changes from %s:%s onto %s", remote.getName(),
Expand All @@ -267,6 +270,7 @@ protected PullResult _call() {
result.setNewRef(currentBranchFinalState);
}

getProgressListener().setDescription("Pull: finished pulling " + remote);
getProgressListener().complete();

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import lombok.extern.slf4j.Slf4j;

/**
* Fetches named heads or tags from one or more other repositories, along with the objects necessary
* to complete them.
Expand Down Expand Up @@ -74,6 +76,7 @@
* repository under its {@code refs/heads/ or {@code refs/tags} namespaces that were created,
* deleted, or updated.
*/
@Slf4j
public class FetchOp extends AbstractGeoGigOp<TransferSummary> {

private FetchArgs.Builder argsBuilder = new FetchArgs.Builder();
Expand All @@ -95,7 +98,7 @@ public class FetchOp extends AbstractGeoGigOp<TransferSummary> {
}
try (IRemoteRepo remoteRepo = openRemote(remote)) {
Preconditions.checkState(remote.equals(remoteRepo.getInfo()));

progress.setDescription("Fetching " + remoteRepo.getInfo());
final List<LocalRemoteRef> localToRemoteRemoteRefs = resolveRemoteRefs(remoteRepo);

final PackRequest request = prepareRequest(localRepo, localToRemoteRemoteRefs);
Expand All @@ -119,6 +122,7 @@ public class FetchOp extends AbstractGeoGigOp<TransferSummary> {
remoteRemoteRefs = updateLocalRemoteRefs(remote, localToRemoteRemoteRefs,
args.prune);
result.addAll(remote.getFetchURL(), Lists.newArrayList(remoteRemoteRefs));
progress.setDescription("Fetched " + remoteRepo.getInfo());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private RefDiff applyToPreOrder(PackProcessor target, RefRequest req, Deduplicat

progress.started();

progress.setDescription("Applying changes of " + req.name);
progress.setDescription("Saving missing revision objects changes for " + req.name);
ObjectReporter objectReport = new ObjectReporter(progress);

// back up current progress indicator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
public abstract class RemoteRepositoryTestCase {

protected static final ProgressListener SIMPLE_PROGRESS = new DefaultProgressListener() {
public @Override void setDescription(String msg) {
System.err.println(msg);
public @Override void setDescription(String msg, Object... args) {
System.err.printf(msg + "\n", args);
}
};

Expand Down

0 comments on commit 2e0a92f

Please sign in to comment.