1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.lfs;
11
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.io.PrintStream;
15
16 import org.eclipse.jgit.annotations.Nullable;
17 import org.eclipse.jgit.attributes.Attribute;
18 import org.eclipse.jgit.hooks.PrePushHook;
19 import org.eclipse.jgit.lib.ConfigConstants;
20 import org.eclipse.jgit.lib.ObjectLoader;
21 import org.eclipse.jgit.lib.Repository;
22 import org.eclipse.jgit.util.LfsFactory;
23
24
25
26
27
28
29 public class BuiltinLFS extends LfsFactory {
30
31 private BuiltinLFS() {
32 SmudgeFilter.register();
33 CleanFilter.register();
34 }
35
36
37
38
39 public static void register() {
40 setInstance(new BuiltinLFS());
41 }
42
43 @Override
44 public boolean isAvailable() {
45 return true;
46 }
47
48 @Override
49 public ObjectLoaderlib/ObjectLoader.html#ObjectLoader">ObjectLoader applySmudgeFilter(Repository db, ObjectLoader loader,
50 Attribute attribute) throws IOException {
51 if (isEnabled(db) && (attribute == null || isEnabled(db, attribute))) {
52 return LfsBlobFilter.smudgeLfsBlob(db, loader);
53 }
54 return loader;
55 }
56
57 @Override
58 public LfsInputStream applyCleanFilter(Repository db, InputStream input,
59 long length, Attribute attribute) throws IOException {
60 if (isEnabled(db, attribute)) {
61 return new LfsInputStream(LfsBlobFilter.cleanLfsBlob(db, input));
62 }
63 return new LfsInputStream(input, length);
64 }
65
66 @Override
67 @Nullable
68 public PrePushHook getPrePushHook(Repository repo,
69 PrintStream outputStream) {
70 if (isEnabled(repo)) {
71 return new LfsPrePushHook(repo, outputStream);
72 }
73 return null;
74 }
75
76 @Override
77 @Nullable
78 public PrePushHook getPrePushHook(Repository repo, PrintStream outputStream,
79 PrintStream errorStream) {
80 if (isEnabled(repo)) {
81 return new LfsPrePushHook(repo, outputStream, errorStream);
82 }
83 return null;
84 }
85
86
87
88
89
90
91 @Override
92 public boolean isEnabled(Repository db) {
93 if (db == null) {
94 return false;
95 }
96 return db.getConfig().getBoolean(ConfigConstants.CONFIG_FILTER_SECTION,
97 ConfigConstants.CONFIG_SECTION_LFS,
98 ConfigConstants.CONFIG_KEY_USEJGITBUILTIN,
99 false);
100 }
101
102
103
104
105
106
107
108
109
110 private boolean isEnabled(Repository db, Attribute attribute) {
111 if (attribute == null) {
112 return false;
113 }
114 return isEnabled(db) && ConfigConstants.CONFIG_SECTION_LFS
115 .equals(attribute.getValue());
116 }
117
118 @Override
119 public LfsInstallCommand getInstallCommand() {
120 return new InstallBuiltinLfsCommand();
121 }
122
123 }