1 package org
.nbgit
.ui
.log
;
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
8 * The contents of this file are subject to the terms of either the GNU
9 * General Public License Version 2 only ("GPL") or the Common
10 * Development and Distribution License("CDDL") (collectively, the
11 * "License"). You may not use this file except in compliance with the
12 * License. You can obtain a copy of the License at
13 * http://www.netbeans.org/cddl-gplv2.html
14 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
15 * specific language governing permissions and limitations under the
16 * License. When distributing the software, include this License Header
17 * Notice in each file and include the License file at
18 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
19 * particular file as subject to the "Classpath" exception as provided
20 * by Sun in the GPL Version 2 section of the License file that
21 * accompanied this code. If applicable, add the following below the
22 * License Header, with the fields enclosed by brackets [] replaced by
23 * your own identifying information:
24 * "Portions Copyrighted [year] [name of copyright owner]"
28 * The Original Software is NetBeans. The Initial Developer of the Original
29 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
30 * Microsystems, Inc. All Rights Reserved.
31 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
33 * If you wish your version of this file to be governed by only the CDDL
34 * or only the GPL Version 2, indicate your decision by adding
35 * "[Contributor] elects to include this software in this distribution
36 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37 * single choice of license, a recipient has the option to distribute
38 * your version of this file under either the CDDL, the GPL Version 2 or
39 * to extend the choice of license to its licensees as provided above.
40 * However, if you add GPL Version 2 code and therefore, elected the GPL
41 * Version 2 license, then the option applies only if the new code is
42 * made subject to such option by the copyright holder.
45 import java
.io
.IOException
;
46 import java
.util
.ArrayList
;
47 import java
.util
.Date
;
48 import java
.util
.List
;
49 import org
.openide
.util
.Exceptions
;
50 import org
.spearce
.jgit
.errors
.CorruptObjectException
;
51 import org
.spearce
.jgit
.errors
.IncorrectObjectTypeException
;
52 import org
.spearce
.jgit
.errors
.MissingObjectException
;
53 import org
.spearce
.jgit
.lib
.AnyObjectId
;
54 import org
.spearce
.jgit
.lib
.ObjectId
;
55 import org
.spearce
.jgit
.lib
.Repository
;
56 import org
.spearce
.jgit
.revwalk
.RevCommit
;
57 import org
.spearce
.jgit
.revwalk
.RevWalk
;
58 import org
.spearce
.jgit
.treewalk
.TreeWalk
;
61 * Describes log information for a file. This is the result of doing a
62 * cvs log command. The fields in instances of this object are populated
63 * by response handlers.
65 * @author Maros Sandor
67 public class RepositoryRevision
extends RevCommit
{
69 private final Repository repo
;
71 * List of events associated with the revision.
73 private final List
<Event
> events
= new ArrayList
<Event
>(1);
75 private RepositoryRevision(AnyObjectId id
, Repository repo
) {
80 public String
getRepositoryRootUrl() {
81 return repo
.getDirectory().getAbsolutePath();
84 Iterable
<Event
> createEvents(Walk walk
) {
86 initEvents(walk
.getTreeWalk());
87 } catch (MissingObjectException ex
) {
88 Exceptions
.printStackTrace(ex
);
89 } catch (IncorrectObjectTypeException ex
) {
90 Exceptions
.printStackTrace(ex
);
91 } catch (CorruptObjectException ex
) {
92 Exceptions
.printStackTrace(ex
);
93 } catch (IOException ex
) {
94 Exceptions
.printStackTrace(ex
);
100 private ObjectId
[] getTrees() {
101 final ObjectId
[] r
= new ObjectId
[getParentCount() + 1];
102 for (int i
= 0; i
< r
.length
- 1; i
++) {
103 r
[i
] = getParent(i
).getTree().getId();
105 r
[r
.length
- 1] = getTree().getId();
109 private char getStatus(TreeWalk walk
, int mode0
, int mode1
) {
110 if (mode0
== 0 && mode1
!= 0) {
112 } else if (mode0
!= 0 && mode1
== 0) {
114 } else if (!walk
.idEqual(0, 1)) {
116 } else if (mode0
!= mode1
) {
122 private void initEvents(final TreeWalk walk
)
123 throws MissingObjectException
, IncorrectObjectTypeException
,
124 CorruptObjectException
, IOException
{
125 ObjectId
[] trees
= getTrees();
126 final int revTree
= trees
.length
- 1;
130 switch (trees
.length
) {
133 while (walk
.next()) {
134 events
.add(new Event(walk
.getPathString(), 'A'));
138 while (walk
.next()) {
139 int mode0
= walk
.getRawMode(0);
140 int mode1
= walk
.getRawMode(1);
141 char status
= getStatus(walk
, mode0
, mode1
);
145 events
.add(new Event(walk
.getPathString(), status
));
150 while (walk
.next()) {
152 int mode1
= walk
.getRawMode(revTree
);
155 for (i
= 0; i
< revTree
; i
++) {
156 int mode
= walk
.getRawMode(i
);
157 if (mode
== mode1
&& walk
.idEqual(i
, revTree
)) {
166 char status
= getStatus(walk
, mode0
, mode1
);
170 events
.add(new Event(walk
.getPathString(), status
));
177 public List
<Event
> getEvents() {
181 public String
getAuthor() {
182 return getAuthorIdent().getName();
185 String
getMessage() {
186 return getFullMessage();
189 public String
getRevision() {
190 return getId().name();
193 public Date
getDate() {
194 return getCommitterIdent().getWhen();
200 * The file or folder that this event is about. It may be null if the File cannot be computed.
203 private GitLogMessageChangedPath changedPath
;
207 private Event(GitLogMessageChangedPath changedPath
) {
208 this.changedPath
= changedPath
;
209 name
= changedPath
.getPath().substring(changedPath
.getPath().lastIndexOf('/') + 1);
211 int indexPath
= changedPath
.getPath().lastIndexOf('/');
212 if (indexPath
> -1) {
213 path
= changedPath
.getPath().substring(0, indexPath
);
219 private Event(String pathString
, char c
) {
220 this(new GitLogMessageChangedPath(pathString
, c
));
223 public RepositoryRevision
getLogInfoHeader() {
224 return RepositoryRevision
.this;
227 public GitLogMessageChangedPath
getChangedPath() {
231 /** Getter for property file.
232 * @return Value of property file.
234 public File
getFile() {
238 /** Setter for property file.
239 * @param file New value of property file.
241 public void setFile(File file
) {
245 public String
getName() {
249 public String
getPath() {
254 public String
toString() {
255 StringBuffer text
= new StringBuffer();
257 text
.append(getPath());
258 return text
.toString();
262 public static class Walk
extends RevWalk
{
264 private final TreeWalk walk
;
266 public Walk(Repository repo
) {
268 walk
= new TreeWalk(repo
);
269 walk
.setRecursive(true);
273 protected RevCommit
createCommit(final AnyObjectId id
) {
274 return new RepositoryRevision(id
, getRepository());
277 private TreeWalk
getTreeWalk() {