Skip to content

Commit 699b7bd

Browse files
committed
fixup commit-navigation when going from a 'latest' commit
This got broken with the introduction of the fragment stuff- there's also a small improvement in that the branch name is now passed through to the commit viewer activity.
1 parent 1d0b7c4 commit 699b7bd

File tree

5 files changed

+57
-13
lines changed

5 files changed

+57
-13
lines changed

agit/src/main/java/com/madgag/agit/CommitViewerActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.util.Map;
6060

6161
import org.eclipse.jgit.lib.ObjectId;
62+
import org.eclipse.jgit.lib.Ref;
6263
import org.eclipse.jgit.lib.Repository;
6364
import org.eclipse.jgit.revplot.PlotCommit;
6465
import org.eclipse.jgit.revplot.PlotCommitList;
@@ -73,6 +74,11 @@ public static GitIntentBuilder commitViewIntentFor(Bundle sourceArgs) {
7374
return new GitIntentBuilder("commit.VIEW", sourceArgs, GITDIR, UNTIL_REVS, COMMIT);
7475
}
7576

77+
public static Intent commitViewIntentFor(Repository repository, Ref ref) {
78+
return new GitIntentBuilder("commit.VIEW").repository(repository).untilRevs(ref).commit(ref.getObjectId()).toIntent();
79+
}
80+
81+
7682
public static Intent commitViewIntentFor(Repository repository, RevCommit commit) {
7783
return new GitIntentBuilder("commit.VIEW").repository(repository).commit(commit).toIntent();
7884
}
@@ -175,6 +181,7 @@ private void swapCommitViewVars() {
175181

176182
private void setCurrentCommit(PlotCommit<PlotLane> commit) {
177183
this.commit = commit;
184+
Log.d(TAG, "setCurrentCommit : commit=" + commit);
178185
setActionBarTitles();
179186
}
180187

agit/src/main/java/com/madgag/agit/GitIntentBuilder.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.madgag.agit;
2121

22+
import static com.google.common.collect.Lists.newArrayList;
2223
import static com.madgag.agit.GitIntents.EXTRA_SOURCE_URI;
2324
import static com.madgag.agit.GitIntents.EXTRA_TARGET_DIR;
2425
import static com.madgag.agit.GitIntents.GITDIR;
@@ -27,10 +28,11 @@
2728
import android.os.Bundle;
2829

2930
import java.io.File;
31+
import java.util.ArrayList;
3032

33+
import org.eclipse.jgit.lib.ObjectId;
3134
import org.eclipse.jgit.lib.Ref;
3235
import org.eclipse.jgit.lib.Repository;
33-
import org.eclipse.jgit.revwalk.RevCommit;
3436
import org.eclipse.jgit.transport.RemoteConfig;
3537

3638
public class GitIntentBuilder {
@@ -79,6 +81,11 @@ public GitIntentBuilder targetDir(String targetDir) {
7981
return add(EXTRA_TARGET_DIR, targetDir);
8082
}
8183

84+
public GitIntentBuilder add(String fieldName, ArrayList<String> list) {
85+
intent.putStringArrayListExtra(fieldName, list);
86+
return this;
87+
}
88+
8289
public GitIntentBuilder add(String fieldName, String value) {
8390
intent.putExtra(fieldName, value);
8491
return this;
@@ -88,14 +95,18 @@ public GitIntentBuilder repository(Repository repository) {
8895
return gitdir(repository.getDirectory());
8996
}
9097

91-
public GitIntentBuilder commit(RevCommit revCommit) {
98+
public GitIntentBuilder commit(ObjectId revCommit) {
9299
return commit(revCommit.name());
93100
}
94101

95102
public GitIntentBuilder commit(String commitId) {
96103
return add("commit", commitId);
97104
}
98105

106+
public GitIntentBuilder untilRevs(Ref ref) {
107+
return add(GitIntents.UNTIL_REVS, newArrayList(ref.getName())); //To change body of created methods use File | Settings | File Templates.
108+
}
109+
99110
public GitIntentBuilder revision(String revision) {
100111
return add(GitIntents.REVISION, revision);
101112
}
@@ -107,4 +118,5 @@ public GitIntentBuilder path(String path) {
107118
public Intent toIntent() {
108119
return intent;
109120
}
121+
110122
}

agit/src/main/java/com/madgag/agit/LogStartProvider.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@
1919

2020
package com.madgag.agit;
2121

22+
import static com.google.common.collect.Lists.newArrayList;
23+
import static com.madgag.agit.GitIntents.COMMIT;
2224
import static com.madgag.agit.GitIntents.UNTIL_REVS;
2325
import static org.eclipse.jgit.lib.Constants.R_REMOTES;
2426

27+
import android.util.Log;
28+
2529
import com.google.common.base.Function;
2630
import com.google.inject.Inject;
2731

2832
import javax.annotation.Nullable;
2933
import java.io.IOException;
3034
import java.util.ArrayList;
3135
import java.util.List;
36+
import java.util.Set;
3237

3338
import org.eclipse.jgit.lib.ObjectId;
3439
import org.eclipse.jgit.lib.Ref;
3540
import org.eclipse.jgit.lib.Repository;
41+
import org.eclipse.jgit.revwalk.RevCommit;
3642
import org.eclipse.jgit.revwalk.RevWalk;
3743

3844
import roboguice.inject.InjectExtra;
@@ -48,23 +54,41 @@ public ObjectId apply(Ref ref) {
4854
};
4955

5056
private @Inject Repository repository;
57+
58+
/**
59+
* The revs that specify the starts of the 'log'
60+
*/
5161
private @InjectExtra(value=UNTIL_REVS, optional = true) ArrayList<String> untilRevs;
5262

63+
/**
64+
* A specific commit that has been selected (possibly from a list of commits in a log)
65+
*/
66+
private @InjectExtra(value=COMMIT, optional = true) String commitId;
67+
5368
public String getCurrentRef() {
5469
return untilRevs == null ? null : untilRevs.get(0);
5570
}
5671

5772
public void markStartsOn(RevWalk revWalk) {
73+
List<RevCommit> commits = newArrayList();
74+
5875
try {
59-
for (String untilRev : impliedRevs()) {
60-
revWalk.markStart(revWalk.parseCommit(repository.resolve(untilRev)));
76+
if (commitId != null) {
77+
Log.d(TAG, "Including specific commit : " + commitId);
78+
commits.add(revWalk.parseCommit(ObjectId.fromString(commitId)));
6179
}
80+
if (untilRevs != null) {
81+
Log.d(TAG, "Including start revs : " + untilRevs);
82+
for (String untilRev : untilRevs) {
83+
RevCommit commit = revWalk.parseCommit(repository.resolve(untilRev));
84+
Log.d(TAG, "untilRev=" + untilRev + " commit=" + commit);
85+
commits.add(commit);
86+
}
87+
}
88+
89+
revWalk.markStart(commits);
6290
} catch (IOException e) {
6391
throw new RuntimeException(e);
6492
}
6593
}
66-
67-
private Iterable<String> impliedRevs() throws IOException {
68-
return (untilRevs == null) ? repository.getRefDatabase().getRefs(R_REMOTES).keySet() : untilRevs;
69-
}
7094
}

agit/src/main/java/com/madgag/agit/RepoSummary.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ public static List<RepoSummary> sortReposByLatestCommit(List<RepoSummary> repoSu
6565

6666
private final Repository repo;
6767

68-
private final RevCommit latestCommit;
68+
public final RDTBranch.BranchSummary mostlyRecentlyUpdatedBranch;
6969

7070
@Inject
7171
public RepoSummary(Repository repo) {
7272
this.repo = repo;
7373
List<RDTBranch.BranchSummary> branchSummaries = new RDTBranch(repo).getAll();
74-
latestCommit = branchSummaries.isEmpty() ? null : branchSummaries.get(0).getLatestCommit();
74+
mostlyRecentlyUpdatedBranch = branchSummaries.isEmpty() ? null : branchSummaries.get(0);
7575
}
7676

7777
public boolean hasCommits() {
78-
return latestCommit != null;
78+
return mostlyRecentlyUpdatedBranch != null;
7979
}
8080

8181
public RevCommit getLatestCommit() {
82-
return latestCommit;
82+
return hasCommits()?mostlyRecentlyUpdatedBranch.getLatestCommit():null;
8383
}
8484

8585
public Repository getRepo() {

agit/src/main/java/com/madgag/agit/views/LatestCommitView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public LatestCommitView(Context context, LayoutInflater layoutInflater, RepoSumm
4343

4444
PrettyCommitSummaryView objectSummaryView = (PrettyCommitSummaryView) findViewById(latest_commit);
4545
RevCommit latestCommit = repoSummary.getLatestCommit();
46+
4647
if (latestCommit == null) {
4748
objectSummaryView.setVisibility(GONE);
4849
} else {
@@ -54,7 +55,7 @@ public LatestCommitView(Context context, LayoutInflater layoutInflater, RepoSumm
5455

5556
public void onItemClick() {
5657
if (repoSummary.hasCommits()) {
57-
getContext().startActivity(commitViewIntentFor(repoSummary.getRepo(), repoSummary.getLatestCommit()));
58+
getContext().startActivity(commitViewIntentFor(repoSummary.getRepo(), repoSummary.mostlyRecentlyUpdatedBranch.getRef()));
5859
}
5960
}
6061

0 commit comments

Comments
 (0)