[Notice] Announcing the End of Demo Server [Read me]

code: Add branch filter to the Code History page.
@fdd1b74ceff36a31d43cdb6217a1c64a6e23a600
--- app/controllers/CodeHistoryApp.java
+++ app/controllers/CodeHistoryApp.java
... | ... | @@ -24,7 +24,13 @@ |
24 | 24 |
|
25 | 25 |
private static final int HISTORY_ITEM_LIMIT = 25; |
26 | 26 |
|
27 |
- public static Result history(String userName, String projectName) throws IOException, |
|
27 |
+ public static Result historyUntilHead(String userName, String projectName) throws IOException, |
|
28 |
+ UnsupportedOperationException, ServletException, GitAPIException, |
|
29 |
+ SVNException { |
|
30 |
+ return history(userName, projectName, null); |
|
31 |
+ } |
|
32 |
+ |
|
33 |
+ public static Result history(String userName, String projectName, String branch) throws IOException, |
|
28 | 34 |
UnsupportedOperationException, ServletException, GitAPIException, |
29 | 35 |
SVNException { |
30 | 36 |
Project project = Project.findByName(projectName); |
... | ... | @@ -37,8 +43,8 @@ |
37 | 43 |
|
38 | 44 |
try { |
39 | 45 |
List<Commit> commits = RepositoryService.getRepository(project).getHistory(page, |
40 |
- HISTORY_ITEM_LIMIT); |
|
41 |
- return ok(history.render(url, project, commits, page)); |
|
46 |
+ HISTORY_ITEM_LIMIT, branch); |
|
47 |
+ return ok(history.render(url, project, commits, page, branch)); |
|
42 | 48 |
} catch (NoHeadException e) { |
43 | 49 |
return ok(nohead.render(url, project)); |
44 | 50 |
} |
--- app/playRepository/GitRepository.java
+++ app/playRepository/GitRepository.java
... | ... | @@ -17,8 +17,6 @@ |
17 | 17 |
import org.eclipse.jgit.treewalk.TreeWalk; |
18 | 18 |
import org.eclipse.jgit.treewalk.filter.PathFilter; |
19 | 19 |
|
20 |
-import com.google.common.collect.Lists; |
|
21 |
- |
|
22 | 20 |
import play.Logger; |
23 | 21 |
import play.libs.Json; |
24 | 22 |
import utils.FileUtil; |
... | ... | @@ -178,13 +176,16 @@ |
178 | 176 |
} |
179 | 177 |
|
180 | 178 |
@Override |
181 |
- public List<Commit> getHistory(int page, int limit) throws AmbiguousObjectException, |
|
182 |
- IOException, NoHeadException, GitAPIException { |
|
179 |
+ public List<Commit> getHistory(int page, int limit, String until) |
|
180 |
+ throws AmbiguousObjectException, IOException, NoHeadException, GitAPIException { |
|
183 | 181 |
// Get the list of commits from HEAD to the given page. |
184 |
- Iterable<RevCommit> iter = new Git(repository).log() |
|
185 |
- .setMaxCount(page * limit + limit).call(); |
|
182 |
+ LogCommand logCommand = new Git(repository).log(); |
|
183 |
+ if (until != null) { |
|
184 |
+ logCommand.add(repository.resolve(until)); |
|
185 |
+ } |
|
186 |
+ Iterable<RevCommit> iter = logCommand.setMaxCount(page * limit + limit).call(); |
|
186 | 187 |
List<RevCommit> list = new LinkedList<RevCommit>(); |
187 |
- for(RevCommit commit : iter) { |
|
188 |
+ for (RevCommit commit : iter) { |
|
188 | 189 |
if (list.size() >= limit) { |
189 | 190 |
list.remove(0); |
190 | 191 |
} |
... | ... | @@ -192,11 +193,16 @@ |
192 | 193 |
} |
193 | 194 |
|
194 | 195 |
List<Commit> result = new ArrayList<Commit>(); |
195 |
- for(RevCommit commit : list) { |
|
196 |
+ for (RevCommit commit : list) { |
|
196 | 197 |
result.add(new GitCommit(commit)); |
197 | 198 |
} |
198 | 199 |
|
199 | 200 |
return result; |
200 | 201 |
} |
201 | 202 |
|
202 |
-} |
|
203 |
+ @Override |
|
204 |
+ public List<String> getBranches() { |
|
205 |
+ return new ArrayList<String>(repository.getAllRefs().keySet()); |
|
206 |
+ } |
|
207 |
+ |
|
208 |
+}(No newline at end of file) |
--- app/playRepository/PlayRepository.java
+++ app/playRepository/PlayRepository.java
... | ... | @@ -25,7 +25,9 @@ |
25 | 25 |
public String getPatch(String commitId) throws GitAPIException, MissingObjectException, |
26 | 26 |
IncorrectObjectTypeException, IOException, SVNException; |
27 | 27 |
|
28 |
- public List<Commit> getHistory(int page, int limit) throws AmbiguousObjectException, |
|
28 |
+ public List<Commit> getHistory(int page, int limit, String branch) throws AmbiguousObjectException, |
|
29 | 29 |
IOException, NoHeadException, GitAPIException, SVNException; |
30 | 30 |
|
31 |
+ public List<String> getBranches(); |
|
32 |
+ |
|
31 | 33 |
}(No newline at end of file) |
--- app/playRepository/SVNRepository.java
+++ app/playRepository/SVNRepository.java
... | ... | @@ -131,7 +131,7 @@ |
131 | 131 |
} |
132 | 132 |
|
133 | 133 |
@Override |
134 |
- public List<Commit> getHistory(int page, int limit) throws AmbiguousObjectException, |
|
134 |
+ public List<Commit> getHistory(int page, int limit, String until) throws AmbiguousObjectException, |
|
135 | 135 |
IOException, NoHeadException, GitAPIException, SVNException { |
136 | 136 |
// Get the repository |
137 | 137 |
SVNURL svnURL = SVNURL.fromFile(new File(repoPrefix + userName + "/" + projectName)); |
... | ... | @@ -144,7 +144,7 @@ |
144 | 144 |
long startRevision = repository.getLatestRevision(); |
145 | 145 |
long endRevision = startRevision - limit; |
146 | 146 |
if (endRevision < 1) { |
147 |
- endRevision = 1; |
|
147 |
+ return new ArrayList<Commit>(); |
|
148 | 148 |
} |
149 | 149 |
|
150 | 150 |
// Get the logs |
... | ... | @@ -156,4 +156,8 @@ |
156 | 156 |
return result; |
157 | 157 |
} |
158 | 158 |
|
159 |
-} |
|
159 |
+ @Override |
|
160 |
+ public List<String> getBranches() { |
|
161 |
+ return new ArrayList<String>(); |
|
162 |
+ } |
|
163 |
+}(No newline at end of file) |
--- app/views/code/diff.scala.html
+++ app/views/code/diff.scala.html
... | ... | @@ -11,7 +11,6 @@ |
11 | 11 |
<pre><code>@patch</code></pre> |
12 | 12 |
</div> |
13 | 13 |
<script type="text/javascript"> |
14 |
- var fn = nforge.require('code.diff'); |
|
15 | 14 |
$("code").highlight('diff'); |
16 | 15 |
</script> |
17 | 16 |
} |
--- app/views/code/gitView.scala.html
+++ app/views/code/gitView.scala.html
... | ... | @@ -1,7 +1,7 @@ |
1 | 1 |
@(url : String, project:Project) @main("코드", project){ |
2 | 2 |
<ul class="nav nav-tabs"> |
3 | 3 |
<a href="@routes.CodeApp.codeBrowser(project.owner, project.name)">@Messages("Files")</a></li> |
4 |
- <a href="@routes.CodeHistoryApp.history(project.owner, project.name)">@Messages("Commits")</a></li> |
|
4 |
+ <a href="@routes.CodeHistoryApp.historyUntilHead(project.owner, project.name)">@Messages("Commits")</a></li> |
|
5 | 5 |
</ul> |
6 | 6 |
|
7 | 7 |
<div class="well">Clone this repository : git clone @url</div> |
--- app/views/code/history.scala.html
+++ app/views/code/history.scala.html
... | ... | @@ -1,33 +1,54 @@ |
1 |
-@(url: String, project: Project, history: List[playRepository.Commit], page: Integer) |
|
1 |
+@(url: String, project: Project, history: List[playRepository.Commit], page: Integer, selectedBranch: String) |
|
2 |
+ |
|
3 |
+@import playRepository.RepositoryService |
|
4 |
+@import java.net.URLEncoder |
|
2 | 5 |
|
3 | 6 |
@main(Messages("Commit History"), project) { |
4 | 7 |
|
8 |
+@defining(RepositoryService.getRepository(project).getBranches()) { branches => |
|
9 |
+ @if(branches.length > 0) { |
|
10 |
+ <select id="branch" name="branch"> |
|
11 |
+ @branches.map { branch => |
|
12 |
+ @defining(routes.CodeHistoryApp.history(project.owner, project.name, URLEncoder.encode(branch, "UTF-8"))) { url => |
|
13 |
+ <option @(if(branch == selectedBranch) "selected" else "") value="@url" >@branch</option> |
|
14 |
+ } |
|
15 |
+ } |
|
16 |
+ </select> |
|
17 |
+ } |
|
18 |
+} |
|
19 |
+ |
|
5 | 20 |
<ul class="nav nav-tabs"> |
6 | 21 |
<a href="@routes.CodeApp.codeBrowser(project.owner, project.name)">@Messages("Files")</a></li> |
7 |
- <a href="@routes.CodeHistoryApp.history(project.owner, project.name)">@Messages("Commits")</a></li> |
|
22 |
+ <a href="@routes.CodeHistoryApp.history(project.owner, project.name, selectedBranch)">@Messages("Commits")</a></li> |
|
8 | 23 |
</ul> |
9 | 24 |
|
10 |
-<div class="row" id="history"> |
|
11 |
- <table class="table"> |
|
12 |
- <tbody> |
|
13 |
- @for(commit <- history.iterator()) { |
|
14 |
- <tr> |
|
15 |
- <td>@commit.getAuthorName()</td> |
|
16 |
- <td><pre>@commit.getMessage()</pre></td> |
|
17 |
- <td>@commit.getAuthorDate()</td> |
|
18 |
- <td><a href="@routes.CodeHistoryApp.show(project.owner, project.name, commit.getId())">@commit.getShortId()</a></td> |
|
19 |
- </tr> |
|
20 |
- } |
|
21 |
- </tbody> |
|
22 |
- </table> |
|
23 |
- <ul class="pager"> |
|
24 |
- @if(page > 0) { |
|
25 |
- <li><a href="@routes.CodeHistoryApp.history(project.owner, project.name)?page=@(page - 1)">@Messages("Newer")</a></li> |
|
26 |
- } |
|
25 |
+@if(history.size() > 0) { |
|
26 |
+ <div class="row" id="history"> |
|
27 |
+ <table class="table"> |
|
28 |
+ <tbody> |
|
29 |
+ @for(commit <- history.iterator()) { |
|
30 |
+ <tr> |
|
31 |
+ <td>@commit.getAuthorName()</td> |
|
32 |
+ <td><pre>@commit.getMessage()</pre></td> |
|
33 |
+ <td>@commit.getAuthorDate()</td> |
|
34 |
+ <td><a href="@routes.CodeHistoryApp.show(project.owner, project.name, commit.getId())">@commit.getShortId()</a></td> |
|
35 |
+ </tr> |
|
36 |
+ } |
|
37 |
+ </tbody> |
|
38 |
+ </table> |
|
39 |
+ <ul class="pager"> |
|
40 |
+ @if(page > 0) { |
|
41 |
+ <li><a href="@routes.CodeHistoryApp.history(project.owner, project.name, selectedBranch)?page=@(page - 1)">@Messages("Newer")</a></li> |
|
42 |
+ } |
|
27 | 43 |
|
28 |
- @if(history.get(history.size() - 1).getParentCount() > 0) { |
|
29 |
- <li><a href="@routes.CodeHistoryApp.history(project.owner, project.name)?page=@(page + 1)">@Messages("Older")</a></li> |
|
30 |
- } |
|
31 |
- </ul> |
|
32 |
-</div> |
|
44 |
+ @if(history.get(history.size() - 1).getParentCount() > 0) { |
|
45 |
+ <li><a href="@routes.CodeHistoryApp.history(project.owner, project.name, selectedBranch)?page=@(page + 1)">@Messages("Older")</a></li> |
|
46 |
+ } |
|
47 |
+ </ul> |
|
48 |
+ </div> |
|
49 |
+ <script type="text/javascript"> |
|
50 |
+ nforge.require('code.branch'); |
|
51 |
+ </script> |
|
52 |
+} |
|
53 |
+ |
|
33 | 54 |
} |
--- app/views/code/svnView.scala.html
+++ app/views/code/svnView.scala.html
... | ... | @@ -1,7 +1,7 @@ |
1 | 1 |
@(url : String, project:Project) @main("코드", project){ |
2 | 2 |
<ul class="nav nav-tabs"> |
3 | 3 |
<a href="@routes.CodeApp.codeBrowser(project.owner, project.name)">@Messages("Files")</a></li> |
4 |
- <a href="@routes.CodeHistoryApp.history(project.owner, project.name)">@Messages("Commits")</a></li> |
|
4 |
+ <a href="@routes.CodeHistoryApp.history(project.owner, project.name, null)">@Messages("Commits")</a></li> |
|
5 | 5 |
</ul> |
6 | 6 |
|
7 | 7 |
<div class="well">Checkout this repository : svn checkout @url</div> |
--- conf/routes
+++ conf/routes
... | ... | @@ -96,7 +96,8 @@ |
96 | 96 |
GET /:user/:projectName/code/*path controllers.CodeApp.showRawFile(user:String, projectName:String, path:String) |
97 | 97 |
|
98 | 98 |
# Commits |
99 |
-GET /:user/:projectName/commits controllers.CodeHistoryApp.history(user:String, projectName:String) |
|
99 |
+GET /:user/:projectName/commits controllers.CodeHistoryApp.historyUntilHead(user:String, projectName:String) |
|
100 |
+GET /:user/:projectName/commits/:branch controllers.CodeHistoryApp.history(user:String, projectName:String, branch:String) |
|
100 | 101 |
GET /:user/:projectName/commit/:id controllers.CodeHistoryApp.show(user:String, projectName:String, id:String) |
101 | 102 |
|
102 | 103 |
# Search |
--- public/javascripts/modules/code.js
+++ public/javascripts/modules/code.js
... | ... | @@ -1,3 +1,12 @@ |
1 | 1 |
nforge.namespace('code'); |
2 |
-nforge.code.diff = function () { |
|
2 |
+nforge.code.branch = function () { |
|
3 |
+ return { |
|
4 |
+ init: function() { |
|
5 |
+ $('#branch').click(this.update); |
|
6 |
+ }, |
|
7 |
+ |
|
8 |
+ update: function() { |
|
9 |
+ window.location.replace($('#branch').val()); |
|
10 |
+ } |
|
11 |
+ }; |
|
3 | 12 |
}; |
--- test/playRepository/GitRepositoryTest.java
+++ test/playRepository/GitRepositoryTest.java
... | ... | @@ -128,8 +128,8 @@ |
128 | 128 |
|
129 | 129 |
GitRepository gitRepo = new GitRepository(userName, projectName + "/"); |
130 | 130 |
|
131 |
- List<Commit> history2 = gitRepo.getHistory(0, 2); |
|
132 |
- List<Commit> history5 = gitRepo.getHistory(0, 5); |
|
131 |
+ List<Commit> history2 = gitRepo.getHistory(0, 2, "HEAD"); |
|
132 |
+ List<Commit> history5 = gitRepo.getHistory(0, 5, "HEAD"); |
|
133 | 133 |
|
134 | 134 |
// then |
135 | 135 |
assertThat(history2.size()).isEqualTo(2); |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?