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
;
33 protected TopologicalSorter
<ObjectId
>.Lane
getLane(ObjectId id
) {
34 return topoSorter
.lane
.get(id
);
37 protected TopologicalWalker(final Repository repostory
, Commit
[] starts
,
38 String
[] relativeResourceName
, boolean leafIsBlob
,
39 boolean followMainOnly
, Boolean merges
, ObjectId activeDiffLeafId
) {
40 super(repostory
, starts
, relativeResourceName
, leafIsBlob
,
41 followMainOnly
, merges
, activeDiffLeafId
);
42 topoSorter
= new TopologicalSorter
<ObjectId
>() {;
44 protected boolean filter(ObjectId element
) {
45 return collected
.containsKey(element
);
50 return collected
.size();
53 topoSorter
.setComparator(new Comparator
<ObjectId
>() {
54 public int compare(ObjectId i1
, ObjectId i2
) {
65 Date when1
= commitTime
.get(i1
);
67 return i1
.compareTo(i2
);
69 Date when2
= commitTime
.get(i2
);
71 return i1
.compareTo(i2
);
73 int c
= when2
.compareTo(when1
);
82 protected void record(ObjectId pred
, ObjectId succ
) {
85 topoSorter
.put(new TopologicalSorter
.Edge
<ObjectId
>(pred
, succ
));
86 // else topoSorter.put(pred);
91 protected void collect(Commit commit
, int count
, int breadth
) {
92 // System.out.println("Got: "+count+" "+commit.getCommitId());
93 ObjectId commitId
= commit
.getCommitId();
95 commitId
= ObjectId
.zeroId();
96 collected
.put(commitId
, commitId
);
97 if (commitId
.equals(ObjectId
.zeroId()))
98 commitTime
.put(commitId
, new Date(Long
.MAX_VALUE
));
100 commitTime
.put(commitId
, commit
.getAuthor().getWhen());
103 protected boolean isCancelled() {
107 public Collection
collectHistory() {
108 super.collectHistory();
109 return topoSorter
.getEntries();