-
Notifications
You must be signed in to change notification settings - Fork 46
/
GitFile.kt
123 lines (111 loc) · 3.98 KB
/
GitFile.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* This file is part of git-as-svn. It is subject to the license terms
* in the LICENSE file found in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/gpl-2.0.html. No part of git-as-svn,
* including this file, may be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file.
*/
package svnserver.repository.git
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.FileMode
import org.eclipse.jgit.lib.ObjectId
import org.tmatesoft.svn.core.SVNNodeKind
import org.tmatesoft.svn.core.SVNProperty
import svnserver.repository.VcsCopyFrom
import svnserver.repository.git.filter.GitFilter
import svnserver.repository.git.prop.GitProperty
import java.io.IOException
import java.io.InputStream
import java.util.*
/**
* Git file.
*
* @author Artem V. Navrotskiy <bozaro@users.noreply.github.com>
*/
interface GitFile : GitEntry {
override fun createChild(name: String, isDir: Boolean, stringInterner: (String) -> String): GitEntry {
return GitEntryImpl(rawProperties, fullPath, GitProperty.emptyArray, name, if (isDir) FileMode.TREE else FileMode.REGULAR_FILE, stringInterner)
}
@Throws(IOException::class)
override fun getEntry(name: String): GitFile?
/**
* Get native repository content hash for cheap content modification check.
*/
@get:Throws(IOException::class)
val contentHash: String
get() {
return md5
}
@get:Throws(IOException::class)
val md5: String
@get:Throws(IOException::class)
val size: Long
@Throws(IOException::class)
fun openStream(): InputStream
@get:Throws(IOException::class)
val copyFrom: VcsCopyFrom?
val filter: GitFilter?
val treeEntry: GitTreeEntry?
val objectId: GitObject<ObjectId>?
@get:Throws(IOException::class)
val allProperties: Map<String, String>
get() {
val props = HashMap<String, String>()
props.putAll(revProperties)
props.putAll(properties)
return props
}
val revProperties: Map<String, String>
get() {
val props = HashMap<String, String>()
val last = lastChange
props[SVNProperty.UUID] = branch.uuid
props[SVNProperty.COMMITTED_REVISION] = last.id.toString()
putProperty(props, SVNProperty.COMMITTED_DATE, last.dateString)
putProperty(props, SVNProperty.LAST_AUTHOR, last.author)
return props
}
@get:Throws(IOException::class)
val properties: Map<String, String>
get() {
return upstreamProperties
}
val lastChange: GitRevision
get() {
val branch: GitBranch = branch
val lastChange: Int = branch.getLastChange(fullPath, revision) ?: throw IllegalStateException("Internal error: can't find lastChange revision for file: $fileName@$revision")
return branch.sureRevisionInfo(lastChange)
}
val branch: GitBranch
val upstreamProperties: Map<String, String>
get() {
val result = HashMap<String, String>()
for (prop in rawProperties) {
prop.apply(result)
}
return result
}
val revision: Int
val isDirectory: Boolean
get() {
return (kind == SVNNodeKind.DIR)
}
val kind: SVNNodeKind
get() {
return when (val objType: Int = fileMode.objectType) {
Constants.OBJ_TREE, Constants.OBJ_COMMIT -> SVNNodeKind.DIR
Constants.OBJ_BLOB -> SVNNodeKind.FILE
else -> throw IllegalStateException("Unknown obj type: $objType")
}
}
val fileMode: FileMode
@get:Throws(IOException::class)
val entries: Map<String, GitFile>
companion object {
fun putProperty(props: MutableMap<String, String>, name: String, value: String?) {
if (value != null) {
props[name] = value
}
}
}
}