Debian Codegraph @

lfs/attribute.go

raw symbols SCIP
1 package lfsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/"
5 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
6 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
7
8 "github.com/git-lfs/git-lfs/v3/gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/"
9 "github.com/git-lfs/git-lfs/v3/trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/"
10 )
11
12 // Attribute wraps the structure and some operations of Git's conception of an
13 // "attribute", as defined here: http://git-scm.com/docs/gitattributes.
14 type Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute# struct {
15 // The Section of an Attribute refers to the location at which all
16 // properties are relative to. For example, for a Section with the value
17 // "core", Git will produce something like:
18 //
19 // [core]
20 // autocrlf = true
21 // ...
22 Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section. string
23
24 // The Properties of an Attribute refer to all of the keys and values
25 // that define that Attribute.
26 Propertiesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Properties. map[string]string
27 // Previous values of these attributes that can be automatically upgraded
28 Upgradeablesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Upgradeables. map[string][]string
29 }
30
31 // FilterOptions serves as an argument to Install().
32 type FilterOptionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions# struct {
33 GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig. *gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.Configurationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#
34 Forcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Force. bool
35 Filescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#File. string
36 Localscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Local. bool
37 Worktreescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Worktree. bool
38 Systemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#System. bool
39 SkipSmudgescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#SkipSmudge. bool
40 }
41
42 func (o *FilterOptionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#) Installscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Install().() error {
43 if o.SkipSmudgescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#SkipSmudge. {
44 return skipSmudgeFilterAttributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/skipSmudgeFilterAttribute().().Installscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Install().(o)
45 }
46 return filterAttributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/filterAttribute().().Installscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Install().(o)
47 }
48
49 func (o *FilterOptionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#) Uninstallscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Uninstall().() error {
50 attrs := filterAttributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/filterAttribute().()
51 if err := attrs.Uninstallscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Uninstall().(o); err != nil {
52 return err
53 }
54 for k := range attrs.Propertiesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Properties. {
55 name := fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%s.%s", attrs.Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section., k)
56 if len(o.GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig..Findscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#Find().(name)) > 0 {
57 return errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("some filter configuration was not removed (found %s)", name))
58 }
59 }
60 return nil
61 }
62
63 func filterAttributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/filterAttribute().() *Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute# {
64 return &Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#{
65 Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section.: "filter.lfs",
66 Propertiesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Properties.: map[string]string{
67 "clean": "git-lfs clean -- %f",
68 "smudge": "git-lfs smudge -- %f",
69 "process": "git-lfs filter-process",
70 "required": "true",
71 },
72 Upgradeablesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Upgradeables.: map[string][]string{
73 "clean": []string{
74 "git-lfs clean %f",
75 },
76 "smudge": []string{
77 "git-lfs smudge %f",
78 "git-lfs smudge --skip %f",
79 "git-lfs smudge --skip -- %f",
80 },
81 "process": []string{
82 "git-lfs filter",
83 "git-lfs filter --skip",
84 "git-lfs filter-process --skip",
85 },
86 },
87 }
88 }
89
90 func skipSmudgeFilterAttributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/skipSmudgeFilterAttribute().() *Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute# {
91 return &Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#{
92 Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section.: "filter.lfs",
93 Propertiesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Properties.: map[string]string{
94 "clean": "git-lfs clean -- %f",
95 "smudge": "git-lfs smudge --skip -- %f",
96 "process": "git-lfs filter-process --skip",
97 "required": "true",
98 },
99 Upgradeablesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Upgradeables.: map[string][]string{
100 "clean": []string{
101 "git-lfs clean -- %f",
102 },
103 "smudge": []string{
104 "git-lfs smudge %f",
105 "git-lfs smudge --skip %f",
106 "git-lfs smudge -- %f",
107 },
108 "process": []string{
109 "git-lfs filter",
110 "git-lfs filter --skip",
111 "git-lfs filter-process",
112 },
113 },
114 }
115 }
116
117 // Install instructs Git to set all keys and values relative to the root
118 // location of this Attribute. For any particular key/value pair, if a matching
119 // key is already set, it will be overridden if it is either a) empty, or b) the
120 // `force` argument is passed as true. If an attribute is already set to a
121 // different value than what is given, and force is false, an error will be
122 // returned immediately, and the rest of the attributes will not be set.
123 func (a *Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#) Installscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Install().(opt *FilterOptionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#) error {
124 for k, v := range a.Propertiesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Properties. {
125 var upgradeables []string
126 if a.Upgradeablesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Upgradeables. != nil {
127 // use pre-normalised key since caller will have set up the same
128 upgradeables = a.Upgradeablesscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Upgradeables.[k]
129 }
130 key := a.normalizeKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#normalizeKey().(k)
131 if err := a.setscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#set().(opt.GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig., key, v, upgradeables, opt); err != nil {
132 return err
133 }
134 }
135
136 return nil
137 }
138
139 // normalizeKey makes an absolute path out of a partial relative one. For a
140 // relative path of "foo", and a root Section of "bar", "bar.foo" will be returned.
141 func (a *Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#) normalizeKeyscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#normalizeKey().(relative string) string {
142 return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.0 strings/Join().([]string{a.Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section., relative}, ".")
143 }
144
145 // set attempts to set a single key/value pair portion of this Attribute. If a
146 // matching key already exists and the value is not equal to the desired value,
147 // an error will be thrown if force is set to false. If force is true, the value
148 // will be overridden.
149 func (a *Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#) setscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#set().(gitConfig *gitscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/.Configurationscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#, key, value string, upgradeables []string, opt *FilterOptionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#) error {
150 var currentValue string
151 if opt.Localscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Local. {
152 currentValue = gitConfig.FindLocalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#FindLocal().(key)
153 } else if opt.Worktreescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Worktree. {
154 currentValue = gitConfig.FindWorktreescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#FindWorktree().(key)
155 } else if opt.Systemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#System. {
156 currentValue = gitConfig.FindSystemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#FindSystem().(key)
157 } else if opt.Filescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#File. != "" {
158 currentValue = gitConfig.FindFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#FindFile().(opt.Filescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#File., key)
159 } else {
160 currentValue = gitConfig.FindGlobalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#FindGlobal().(key)
161 }
162
163 if opt.Forcescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Force. || shouldResetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/shouldReset().(currentValue, upgradeables) {
164 var err error
165 if opt.Localscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Local. {
166 _, err = gitConfig.SetLocalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#SetLocal().(key, value)
167 } else if opt.Worktreescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Worktree. {
168 _, err = gitConfig.SetWorktreescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#SetWorktree().(key, value)
169 } else if opt.Systemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#System. {
170 _, err = gitConfig.SetSystemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#SetSystem().(key, value)
171 } else if opt.Filescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#File. != "" {
172 _, err = gitConfig.SetFilescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#SetFile().(opt.Filescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#File., key, value)
173 } else {
174 _, err = gitConfig.SetGlobalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#SetGlobal().(key, value)
175 }
176 return err
177 } else if currentValue != value {
178 return errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().(trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/.Trscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tr`/Tr..Getscip-go gomod github.com/leonelquinteros/gotext v1.7.2 `github.com/leonelquinteros/gotext`/Locale#Get().("the %q attribute should be %q but is %q",
179 key, value, currentValue))
180 }
181
182 return nil
183 }
184
185 // Uninstall removes all properties in the path of this property.
186 func (a *Attributescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#) Uninstallscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Uninstall().(opt *FilterOptionsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#) error {
187 var err error
188 if opt.Localscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Local. {
189 _, err = opt.GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig..UnsetLocalSectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#UnsetLocalSection().(a.Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section.)
190 } else if opt.Worktreescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#Worktree. {
191 _, err = opt.GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig..UnsetWorktreeSectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#UnsetWorktreeSection().(a.Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section.)
192 } else if opt.Systemscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#System. {
193 _, err = opt.GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig..UnsetSystemSectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#UnsetSystemSection().(a.Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section.)
194 } else if opt.Filescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#File. != "" {
195 _, err = opt.GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig..UnsetFileSectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#UnsetFileSection().(opt.Filescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#File., a.Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section.)
196 } else {
197 _, err = opt.GitConfigscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/FilterOptions#GitConfig..UnsetGlobalSectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/git`/Configuration#UnsetGlobalSection().(a.Sectionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/Attribute#Section.)
198 }
199 return err
200 }
201
202 // shouldReset determines whether or not a value is resettable given its current
203 // value on the system. If the value is empty (length = 0), then it will pass.
204 // It will also pass if it matches any upgradeable value
205 func shouldResetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/lfs`/shouldReset().(value string, upgradeables []string) bool {
206 if len(value) == 0 {
207 return true
208 }
209
210 for _, u := range upgradeables {
211 if value == u {
212 return true
213 }
214 }
215
216 return false
217 }