commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
1f9dae
|
16 |
package com.gitblit.models;
|
5fe7df
|
17 |
|
JM |
18 |
import java.io.Serializable;
|
|
19 |
|
9bc17d
|
20 |
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
1f9dae
|
21 |
import org.eclipse.jgit.lib.FileMode;
|
5fe7df
|
22 |
|
d9f687
|
23 |
/**
|
JM |
24 |
* PathModel is a serializable model class that represents a file or a folder,
|
|
25 |
* including all its metadata and associated commit id.
|
|
26 |
*
|
|
27 |
* @author James Moger
|
|
28 |
*
|
|
29 |
*/
|
5fe7df
|
30 |
public class PathModel implements Serializable, Comparable<PathModel> {
|
JM |
31 |
|
|
32 |
private static final long serialVersionUID = 1L;
|
155bf7
|
33 |
|
5fe7df
|
34 |
public final String name;
|
JM |
35 |
public final String path;
|
|
36 |
public final long size;
|
155bf7
|
37 |
public final int mode;
|
5fe7df
|
38 |
public final String commitId;
|
JM |
39 |
public boolean isParentPath;
|
155bf7
|
40 |
|
5fe7df
|
41 |
public PathModel(String name, String path, long size, int mode, String commitId) {
|
JM |
42 |
this.name = name;
|
|
43 |
this.path = path;
|
|
44 |
this.size = size;
|
|
45 |
this.mode = mode;
|
|
46 |
this.commitId = commitId;
|
|
47 |
}
|
155bf7
|
48 |
|
5fe7df
|
49 |
public boolean isTree() {
|
1f9dae
|
50 |
return FileMode.TREE.equals(mode);
|
5fe7df
|
51 |
}
|
155bf7
|
52 |
|
2a7306
|
53 |
@Override
|
JM |
54 |
public int hashCode() {
|
|
55 |
return commitId.hashCode() + path.hashCode();
|
|
56 |
}
|
|
57 |
|
|
58 |
@Override
|
|
59 |
public boolean equals(Object o) {
|
|
60 |
if (o instanceof PathModel) {
|
|
61 |
PathModel other = (PathModel) o;
|
|
62 |
return this.path.equals(other.path);
|
|
63 |
}
|
|
64 |
return super.equals(o);
|
5fe7df
|
65 |
}
|
JM |
66 |
|
|
67 |
@Override
|
|
68 |
public int compareTo(PathModel o) {
|
fc8426
|
69 |
boolean isTree = isTree();
|
JM |
70 |
boolean otherTree = o.isTree();
|
|
71 |
if (isTree && otherTree) {
|
|
72 |
return path.compareTo(o.path);
|
|
73 |
} else if (!isTree && !otherTree) {
|
|
74 |
return path.compareTo(o.path);
|
|
75 |
} else if (isTree && !otherTree) {
|
|
76 |
return -1;
|
|
77 |
}
|
|
78 |
return 1;
|
5fe7df
|
79 |
}
|
9bc17d
|
80 |
|
d9f687
|
81 |
/**
|
JM |
82 |
* PathChangeModel is a serializable class that represents a file changed in
|
|
83 |
* a commit.
|
|
84 |
*
|
|
85 |
* @author James Moger
|
|
86 |
*
|
|
87 |
*/
|
9bc17d
|
88 |
public static class PathChangeModel extends PathModel {
|
2a7306
|
89 |
|
9bc17d
|
90 |
private static final long serialVersionUID = 1L;
|
2a7306
|
91 |
|
9bc17d
|
92 |
public final ChangeType changeType;
|
JM |
93 |
|
2a7306
|
94 |
public PathChangeModel(String name, String path, long size, int mode, String commitId,
|
JM |
95 |
ChangeType type) {
|
9bc17d
|
96 |
super(name, path, size, mode, commitId);
|
JM |
97 |
this.changeType = type;
|
|
98 |
}
|
2a7306
|
99 |
|
JM |
100 |
@Override
|
|
101 |
public int hashCode() {
|
|
102 |
return super.hashCode();
|
|
103 |
}
|
|
104 |
|
|
105 |
@Override
|
|
106 |
public boolean equals(Object o) {
|
|
107 |
return super.equals(o);
|
|
108 |
}
|
9bc17d
|
109 |
}
|
5fe7df
|
110 |
}
|