|
5 | 5 | */ |
6 | 6 | package org.archicontribs.modelrepository.views.history; |
7 | 7 |
|
| 8 | +import java.io.File; |
8 | 9 | import java.io.IOException; |
| 10 | +import java.nio.file.Path; |
9 | 11 | import java.text.DateFormat; |
10 | 12 | import java.util.ArrayList; |
11 | 13 | import java.util.Date; |
|
14 | 16 | import org.archicontribs.modelrepository.IModelRepositoryImages; |
15 | 17 | import org.archicontribs.modelrepository.grafico.BranchInfo; |
16 | 18 | import org.archicontribs.modelrepository.grafico.BranchStatus; |
| 19 | +import org.archicontribs.modelrepository.grafico.GraficoFileConventions; |
17 | 20 | import org.archicontribs.modelrepository.grafico.IArchiRepository; |
18 | 21 | import org.eclipse.jface.layout.TableColumnLayout; |
19 | 22 | import org.eclipse.jface.viewers.CellLabelProvider; |
|
30 | 33 | import org.eclipse.jgit.lib.Repository; |
31 | 34 | import org.eclipse.jgit.revwalk.RevCommit; |
32 | 35 | import org.eclipse.jgit.revwalk.RevWalk; |
| 36 | +import org.eclipse.jgit.treewalk.filter.PathFilter; |
33 | 37 | import org.eclipse.swt.SWT; |
34 | 38 | import org.eclipse.swt.graphics.Image; |
35 | 39 | import org.eclipse.swt.widgets.Composite; |
36 | 40 | import org.eclipse.swt.widgets.Display; |
37 | 41 |
|
38 | 42 | import com.archimatetool.editor.ui.UIUtils; |
| 43 | +import com.archimatetool.model.IArchimateModelObject; |
| 44 | +import com.archimatetool.model.IFolder; |
39 | 45 |
|
40 | 46 |
|
41 | 47 | /** |
@@ -119,6 +125,15 @@ public void doSetInput(IArchiRepository archiRepo) { |
119 | 125 | // setSelection(new StructuredSelection(element), true); |
120 | 126 | //} |
121 | 127 | } |
| 128 | + |
| 129 | + private static record HistoryInput(IArchiRepository repo, IArchimateModelObject obj) {} |
| 130 | + |
| 131 | + public void doSetInput(IArchiRepository selectedRepository, Object selected) { |
| 132 | + if (selected instanceof IArchimateModelObject) |
| 133 | + setInput(new HistoryInput(selectedRepository, (IArchimateModelObject)selected)); |
| 134 | + else |
| 135 | + doSetInput(selectedRepository); |
| 136 | + } |
122 | 137 |
|
123 | 138 | public void setSelectedBranch(BranchInfo branchInfo) { |
124 | 139 | if(branchInfo != null && branchInfo.equals(fSelectedBranch)) { |
@@ -155,27 +170,47 @@ List<RevCommit> getCommits(Object parent) { |
155 | 170 | fLocalCommit = null; |
156 | 171 | fOriginCommit = null; |
157 | 172 |
|
158 | | - if(!(parent instanceof IArchiRepository) || fSelectedBranch == null) { |
| 173 | + IArchiRepository repo = null; |
| 174 | + File elemFile = null; |
| 175 | + |
| 176 | + if (parent instanceof HistoryInput && ((HistoryInput) parent).obj().eContainer() instanceof IFolder) { |
| 177 | + HistoryInput input = (HistoryInput) parent; |
| 178 | + repo = input.repo(); |
| 179 | + IFolder folder = (IFolder) input.obj().eContainer(); |
| 180 | + elemFile = GraficoFileConventions.forElement( |
| 181 | + new File(repo.getLocalRepositoryFolder(), "model"), |
| 182 | + folder, |
| 183 | + input.obj()); |
| 184 | + } else if (parent instanceof IArchiRepository) |
| 185 | + repo = (IArchiRepository) parent; |
| 186 | + |
| 187 | + if(fSelectedBranch == null) { |
159 | 188 | return commits; |
160 | 189 | } |
161 | 190 |
|
162 | | - IArchiRepository repo = (IArchiRepository)parent; |
163 | | - |
164 | 191 | // Local Repo was deleted |
165 | | - if(!repo.getLocalRepositoryFolder().exists()) { |
| 192 | + if(repo == null || !repo.getLocalRepositoryFolder().exists()) { |
166 | 193 | return commits; |
167 | 194 | } |
168 | 195 |
|
169 | 196 | try(Repository repository = Git.open(repo.getLocalRepositoryFolder()).getRepository()) { |
170 | 197 | // a RevWalk allows to walk over commits based on some filtering that is defined |
171 | 198 | try(RevWalk revWalk = new RevWalk(repository)) { |
| 199 | + if (elemFile != null) { |
| 200 | + String elemPath = Path.of(repo.getLocalRepositoryFolder().getAbsolutePath()) |
| 201 | + .relativize( |
| 202 | + Path.of(elemFile.getAbsolutePath()) |
| 203 | + ).toString(); |
| 204 | + revWalk.setTreeFilter(PathFilter.create(elemPath)); |
| 205 | + } |
| 206 | + |
172 | 207 | // Find the local branch |
173 | 208 | ObjectId objectID = repository.resolve(fSelectedBranch.getLocalBranchNameFor()); |
174 | 209 | if(objectID != null) { |
175 | 210 | fLocalCommit = revWalk.parseCommit(objectID); |
176 | 211 | revWalk.markStart(fLocalCommit); |
177 | 212 | } |
178 | | - |
| 213 | + |
179 | 214 | // Find the remote branch |
180 | 215 | objectID = repository.resolve(fSelectedBranch.getRemoteBranchNameFor()); |
181 | 216 | if(objectID != null) { |
|
0 commit comments