1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.dfs;
12
13 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_CORE_SECTION;
14 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_DFS_SECTION;
15 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_DELTA_BASE_CACHE_LIMIT;
16 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_STREAM_BUFFER;
17 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_STREAM_FILE_TRESHOLD;
18
19 import org.eclipse.jgit.lib.Config;
20 import org.eclipse.jgit.storage.pack.PackConfig;
21
22
23
24
25 public class DfsReaderOptions {
26
27 public static final int KiB = 1024;
28
29
30 public static final int MiB = 1024 * KiB;
31
32 private int deltaBaseCacheLimit;
33 private int streamFileThreshold;
34
35 private int streamPackBufferSize;
36
37
38
39
40 public DfsReaderOptions() {
41 setDeltaBaseCacheLimit(10 * MiB);
42 setStreamFileThreshold(PackConfig.DEFAULT_BIG_FILE_THRESHOLD);
43 }
44
45
46
47
48
49
50 public int getDeltaBaseCacheLimit() {
51 return deltaBaseCacheLimit;
52 }
53
54
55
56
57
58
59
60
61 public DfsReaderOptions setDeltaBaseCacheLimit(int maxBytes) {
62 deltaBaseCacheLimit = Math.max(0, maxBytes);
63 return this;
64 }
65
66
67
68
69
70
71 public int getStreamFileThreshold() {
72 return streamFileThreshold;
73 }
74
75
76
77
78
79
80
81
82
83
84
85 public DfsReaderOptions setStreamFileThreshold(int newLimit) {
86 streamFileThreshold = Math.max(0, newLimit);
87 return this;
88 }
89
90
91
92
93
94
95
96
97 public int getStreamPackBufferSize() {
98 return streamPackBufferSize;
99 }
100
101
102
103
104
105
106
107
108
109
110 public DfsReaderOptions setStreamPackBufferSize(int bufsz) {
111 streamPackBufferSize = Math.max(0, bufsz);
112 return this;
113 }
114
115
116
117
118
119
120
121
122
123
124
125 public DfsReaderOptions fromConfig(Config rc) {
126 setDeltaBaseCacheLimit(rc.getInt(
127 CONFIG_CORE_SECTION,
128 CONFIG_DFS_SECTION,
129 CONFIG_KEY_DELTA_BASE_CACHE_LIMIT,
130 getDeltaBaseCacheLimit()));
131
132 long maxMem = Runtime.getRuntime().maxMemory();
133 long sft = rc.getLong(
134 CONFIG_CORE_SECTION,
135 CONFIG_DFS_SECTION,
136 CONFIG_KEY_STREAM_FILE_TRESHOLD,
137 getStreamFileThreshold());
138 sft = Math.min(sft, maxMem / 4);
139 sft = Math.min(sft, Integer.MAX_VALUE);
140 setStreamFileThreshold((int) sft);
141
142 setStreamPackBufferSize(rc.getInt(
143 CONFIG_CORE_SECTION,
144 CONFIG_DFS_SECTION,
145 CONFIG_KEY_STREAM_BUFFER,
146 getStreamPackBufferSize()));
147 return this;
148 }
149 }