2 * Copyright (C) 2007 Robin Rosenberg
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.jgit
.lib
;
19 import java
.util
.Collection
;
20 import java
.util
.Comparator
;
21 import java
.util
.Date
;
22 import java
.util
.HashMap
;
25 public class TopologicalWalker
extends Walker
{
27 @SuppressWarnings("unchecked")
28 Map
<ObjectId
, ObjectId
> collected
= new ObjectIdMap(new HashMap
<ObjectId
,ObjectId
>());
29 Map
<ObjectId
, Date
> commitTime
= new ObjectIdMap(new HashMap
<ObjectId
,ObjectId
>());
31 TopologicalSorter
<ObjectId
> topoSorter
;
32 final boolean returnAll
;
34 public boolean isReturnAll() {
38 protected TopologicalSorter
<ObjectId
>.Lane
getLane(ObjectId id
) {
39 return topoSorter
.lane
.get(id
);
42 protected TopologicalWalker(final Repository repostory
, Commit
[] starts
,
43 String
[] relativeResourceName
, boolean leafIsBlob
,
44 boolean followMainOnly
, Boolean merges
, ObjectId activeDiffLeafId
, final boolean returnAll
) {
45 super(repostory
, starts
, relativeResourceName
, leafIsBlob
,
46 followMainOnly
, merges
, activeDiffLeafId
);
47 this.returnAll
= returnAll
;
48 topoSorter
= new TopologicalSorter
<ObjectId
>() {;
50 protected boolean filter(ObjectId element
) {
51 return returnAll ?
true : collected
.containsKey(element
);
56 return returnAll ?
super.size() : collected
.size();
59 topoSorter
.setComparator(new Comparator
<ObjectId
>() {
60 public int compare(ObjectId i1
, ObjectId i2
) {
71 Date when1
= commitTime
.get(i1
);
73 return i1
.compareTo(i2
);
75 Date when2
= commitTime
.get(i2
);
77 return i1
.compareTo(i2
);
79 int c
= when2
.compareTo(when1
);
88 protected void record(ObjectId pred
, ObjectId succ
) {
91 topoSorter
.put(new TopologicalSorter
.Edge
<ObjectId
>(pred
, succ
));
92 // else topoSorter.put(pred);
97 protected void collect(Commit commit
, int count
, int breadth
) {
98 // System.out.println("Got: "+count+" "+commit.getCommitId());
99 ObjectId commitId
= commit
.getCommitId();
100 if (commitId
== null)
101 commitId
= ObjectId
.zeroId();
102 collected
.put(commitId
, commitId
);
103 if (commitId
.equals(ObjectId
.zeroId()) || commitId
.equals(starts
[0].getCommitId()))
104 commitTime
.put(commitId
, new Date(Long
.MAX_VALUE
));
106 commitTime
.put(commitId
, commit
.getAuthor().getWhen());
109 protected boolean isCancelled() {
113 public Collection
collectHistory() {
114 super.collectHistory();
115 return topoSorter
.getEntries();