mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-23 16:59:48 +01:00
merge with branch issue-36
This commit is contained in:
@@ -101,12 +101,13 @@ public class GitChangesetViewer implements ChangesetViewer
|
|||||||
{
|
{
|
||||||
gr = GitUtil.open(directory);
|
gr = GitUtil.open(directory);
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
List<Changeset> changesetList = new ArrayList<Changeset>();
|
||||||
|
|
||||||
if (!gr.getAllRefs().isEmpty())
|
if (!gr.getAllRefs().isEmpty())
|
||||||
{
|
{
|
||||||
converter = new GitChangesetConverter(gr, GitUtil.ID_LENGTH);
|
converter = new GitChangesetConverter(gr, GitUtil.ID_LENGTH);
|
||||||
Git git = new Git(gr);
|
Git git = new Git(gr);
|
||||||
List<Changeset> changesetList = new ArrayList<Changeset>();
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
for (RevCommit commit : git.log().call())
|
for (RevCommit commit : git.log().call())
|
||||||
{
|
{
|
||||||
@@ -117,9 +118,9 @@ public class GitChangesetViewer implements ChangesetViewer
|
|||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
changesets = new ChangesetPagingResult(counter, changesetList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changesets = new ChangesetPagingResult(counter, changesetList);
|
||||||
}
|
}
|
||||||
catch (NoHeadException ex)
|
catch (NoHeadException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -117,12 +117,25 @@ public class GitRepositoryBrowser implements RepositoryBrowser
|
|||||||
|
|
||||||
ObjectId revId = GitUtil.getRevisionId(repo, revision);
|
ObjectId revId = GitUtil.getRevisionId(repo, revision);
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("load content for {} at {}", path, revId.name());
|
||||||
|
}
|
||||||
|
|
||||||
revWalk = new RevWalk(repo);
|
revWalk = new RevWalk(repo);
|
||||||
|
|
||||||
RevCommit entry = revWalk.parseCommit(revId);
|
RevCommit entry = revWalk.parseCommit(revId);
|
||||||
RevTree revTree = entry.getTree();
|
RevTree revTree = entry.getTree();
|
||||||
|
|
||||||
treeWalk.addTree(revTree);
|
if (revTree != null)
|
||||||
|
{
|
||||||
|
treeWalk.addTree(revTree);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.error("could not find tree for {}", revId.name());
|
||||||
|
}
|
||||||
|
|
||||||
treeWalk.setFilter(PathFilter.create(path));
|
treeWalk.setFilter(PathFilter.create(path));
|
||||||
|
|
||||||
if (treeWalk.next())
|
if (treeWalk.next())
|
||||||
@@ -175,62 +188,33 @@ public class GitRepositoryBrowser implements RepositoryBrowser
|
|||||||
BrowserResult result = null;
|
BrowserResult result = null;
|
||||||
File directory = handler.getDirectory(repository);
|
File directory = handler.getDirectory(repository);
|
||||||
org.eclipse.jgit.lib.Repository repo = GitUtil.open(directory);
|
org.eclipse.jgit.lib.Repository repo = GitUtil.open(directory);
|
||||||
RevWalk revWalk = null;
|
|
||||||
TreeWalk treeWalk = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ObjectId revId = GitUtil.getRevisionId(repo, revision);
|
ObjectId revId = GitUtil.getRevisionId(repo, revision);
|
||||||
|
|
||||||
treeWalk = new TreeWalk(repo);
|
if (revId != null)
|
||||||
revWalk = new RevWalk(repo);
|
|
||||||
treeWalk.addTree(revWalk.parseTree(revId));
|
|
||||||
result = new BrowserResult();
|
|
||||||
|
|
||||||
List<FileObject> files = new ArrayList<FileObject>();
|
|
||||||
|
|
||||||
if (Util.isEmpty(path))
|
|
||||||
{
|
{
|
||||||
while (treeWalk.next())
|
result = getResult(repo, revId, path);
|
||||||
{
|
|
||||||
files.add(createFileObject(repo, revId, treeWalk));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String[] parts = path.split("/");
|
if (Util.isNotEmpty(revision))
|
||||||
int current = 0;
|
|
||||||
int limit = parts.length;
|
|
||||||
|
|
||||||
while (treeWalk.next())
|
|
||||||
{
|
{
|
||||||
String name = treeWalk.getNameString();
|
logger.error("could not find revision {}", revision);
|
||||||
|
}
|
||||||
if (current >= limit)
|
else if (logger.isWarnEnabled())
|
||||||
{
|
{
|
||||||
String p = treeWalk.getPathString();
|
logger.warn("coul not find head of repository, empty?");
|
||||||
|
|
||||||
if (p.split("/").length > limit)
|
|
||||||
{
|
|
||||||
files.add(createFileObject(repo, revId, treeWalk));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (name.equalsIgnoreCase(parts[current]))
|
|
||||||
{
|
|
||||||
current++;
|
|
||||||
treeWalk.enterSubtree();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
result.setFiles(files);
|
result = new BrowserResult(Constants.HEAD, null, null,
|
||||||
result.setRevision(revId.getName());
|
new ArrayList<FileObject>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GitUtil.close(repo);
|
GitUtil.close(repo);
|
||||||
GitUtil.release(revWalk);
|
|
||||||
GitUtil.release(treeWalk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -328,6 +312,97 @@ public class GitRepositoryBrowser implements RepositoryBrowser
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param repo
|
||||||
|
* @param revId
|
||||||
|
* @param path
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private BrowserResult getResult(org.eclipse.jgit.lib.Repository repo,
|
||||||
|
ObjectId revId, String path)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
BrowserResult result = null;
|
||||||
|
RevWalk revWalk = null;
|
||||||
|
TreeWalk treeWalk = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("load repository browser for revision {}", revId.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
treeWalk = new TreeWalk(repo);
|
||||||
|
revWalk = new RevWalk(repo);
|
||||||
|
|
||||||
|
RevTree tree = revWalk.parseTree(revId);
|
||||||
|
|
||||||
|
if (tree != null)
|
||||||
|
{
|
||||||
|
treeWalk.addTree(tree);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.error("could not find tree for {}", revId.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
result = new BrowserResult();
|
||||||
|
|
||||||
|
List<FileObject> files = new ArrayList<FileObject>();
|
||||||
|
|
||||||
|
if (Util.isEmpty(path))
|
||||||
|
{
|
||||||
|
while (treeWalk.next())
|
||||||
|
{
|
||||||
|
files.add(createFileObject(repo, revId, treeWalk));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String[] parts = path.split("/");
|
||||||
|
int current = 0;
|
||||||
|
int limit = parts.length;
|
||||||
|
|
||||||
|
while (treeWalk.next())
|
||||||
|
{
|
||||||
|
String name = treeWalk.getNameString();
|
||||||
|
|
||||||
|
if (current >= limit)
|
||||||
|
{
|
||||||
|
String p = treeWalk.getPathString();
|
||||||
|
|
||||||
|
if (p.split("/").length > limit)
|
||||||
|
{
|
||||||
|
files.add(createFileObject(repo, revId, treeWalk));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (name.equalsIgnoreCase(parts[current]))
|
||||||
|
{
|
||||||
|
current++;
|
||||||
|
treeWalk.enterSubtree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setFiles(files);
|
||||||
|
result.setRevision(revId.getName());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
GitUtil.release(revWalk);
|
||||||
|
GitUtil.release(treeWalk);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -35,20 +35,20 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
import org.eclipse.jgit.lib.RepositoryCache;
|
||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||||
|
import org.eclipse.jgit.util.FS;
|
||||||
|
|
||||||
import sonia.scm.util.Util;
|
import sonia.scm.util.Util;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.eclipse.jgit.lib.RepositoryCache;
|
|
||||||
import org.eclipse.jgit.util.FS;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -74,6 +74,23 @@ public class GitUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param directory
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static org.eclipse.jgit.lib.Repository open(File directory)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
return RepositoryCache.open(RepositoryCache.FileKey.lenient(directory,
|
||||||
|
FS.DETECTED), true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -121,24 +138,6 @@ public class GitUtil
|
|||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param directory
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static org.eclipse.jgit.lib.Repository open(File directory)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
return RepositoryCache.open(RepositoryCache.FileKey.lenient(directory,
|
|
||||||
FS.DETECTED), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -224,10 +224,21 @@ if (Sonia.repository.ExtendedInfoPanel){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Sonia.repository.RepositoryBrowser){
|
if (Sonia.repository.RepositoryBrowser){
|
||||||
|
|
||||||
Ext.override(Sonia.repository.RepositoryBrowser, {
|
Ext.override(Sonia.repository.RepositoryBrowser, {
|
||||||
// german ??
|
// german ??
|
||||||
repositoryBrowserTitleText: 'Source: {0}'
|
repositoryBrowserTitleText: 'Source: {0}',
|
||||||
|
emptyText: 'In diesem Verzeichnis befinden sich keine Dateien'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Sonia.repository.ChangesetViewerGrid){
|
||||||
|
|
||||||
|
Ext.override(Sonia.repository.ChangesetViewerGrid, {
|
||||||
|
emptyText: 'Es konnten keine Commits gefunden werden'
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sonia.config.js
|
// sonia.config.js
|
||||||
|
|||||||
@@ -48,7 +48,8 @@ Sonia.repository.ChangesetViewerGrid = Ext.extend(Ext.grid.GridPanel, {
|
|||||||
<div class="cs-tree">Tree: <a class="cs-tree-link" rel="{0}" href="#">{0}</a></div>',
|
<div class="cs-tree">Tree: <a class="cs-tree-link" rel="{0}" href="#">{0}</a></div>',
|
||||||
tagsAndBranchesTemplate: '<div class="changeset-tags">{0}</div>\
|
tagsAndBranchesTemplate: '<div class="changeset-tags">{0}</div>\
|
||||||
<div class="changeset-branches">{1}</div>',
|
<div class="changeset-branches">{1}</div>',
|
||||||
|
|
||||||
|
emptyText: 'No commits available',
|
||||||
|
|
||||||
initComponent: function(){
|
initComponent: function(){
|
||||||
|
|
||||||
@@ -88,6 +89,10 @@ Sonia.repository.ChangesetViewerGrid = Ext.extend(Ext.grid.GridPanel, {
|
|||||||
hideHeaders: true,
|
hideHeaders: true,
|
||||||
colModel: changesetColModel,
|
colModel: changesetColModel,
|
||||||
loadMask: true,
|
loadMask: true,
|
||||||
|
viewConfig: {
|
||||||
|
deferEmptyText: false,
|
||||||
|
emptyText: this.emptyText
|
||||||
|
},
|
||||||
listeners: {
|
listeners: {
|
||||||
click: {
|
click: {
|
||||||
fn: this.onClick,
|
fn: this.onClick,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, {
|
|||||||
iconDocument: 'resources/images/document.gif',
|
iconDocument: 'resources/images/document.gif',
|
||||||
templateIcon: '<img src="{0}" alt="{1}" title="{2}" />',
|
templateIcon: '<img src="{0}" alt="{1}" title="{2}" />',
|
||||||
templateLink: '<a class="scm-browser" rel="{1}" href="#">{0}</a>',
|
templateLink: '<a class="scm-browser" rel="{1}" href="#">{0}</a>',
|
||||||
|
|
||||||
|
emptyText: 'This directory is empty',
|
||||||
|
|
||||||
initComponent: function(){
|
initComponent: function(){
|
||||||
|
|
||||||
@@ -113,6 +115,10 @@ Sonia.repository.RepositoryBrowser = Ext.extend(Ext.grid.GridPanel, {
|
|||||||
store: browserStore,
|
store: browserStore,
|
||||||
colModel: browserColModel,
|
colModel: browserColModel,
|
||||||
loadMask: true,
|
loadMask: true,
|
||||||
|
viewConfig: {
|
||||||
|
deferEmptyText: false,
|
||||||
|
emptyText: this.emptyText
|
||||||
|
},
|
||||||
listeners: {
|
listeners: {
|
||||||
click: {
|
click: {
|
||||||
fn: this.onClick,
|
fn: this.onClick,
|
||||||
|
|||||||
Reference in New Issue
Block a user