Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Release Engineering
Public
srpmproc
Commits
b18468ed
Commit
b18468ed
authored
Mar 03, 2021
by
Mustafa Gezen
Browse files
Add `new_field` directive
parent
81b27414
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
internal/directives/spec_change.go
View file @
b18468ed
...
...
@@ -26,7 +26,7 @@ type sourcePatchOperationInLoopRequest struct {
value
*
string
longestField
int
lastNum
*
int
in
*
bool
in
*
string
expectedField
string
operation
srpmprocpb
.
SpecChange_FileOperation_Type
}
...
...
@@ -37,7 +37,7 @@ type sourcePatchOperationAfterLoopRequest struct {
lastNum
*
int
longestField
int
newLines
*
[]
string
in
*
bool
in
*
string
expectedField
string
operation
srpmprocpb
.
SpecChange_FileOperation_Type
}
...
...
@@ -70,7 +70,7 @@ func sourcePatchOperationInLoop(req *sourcePatchOperationInLoopRequest) error {
}
func
sourcePatchOperationAfterLoop
(
req
*
sourcePatchOperationAfterLoopRequest
)
(
bool
,
error
)
{
if
req
.
inLoopNum
==
*
req
.
lastNum
&&
*
req
.
in
{
if
req
.
inLoopNum
==
*
req
.
lastNum
&&
*
req
.
in
==
req
.
expectedField
{
for
_
,
file
:=
range
req
.
cfg
.
SpecChange
.
File
{
if
file
.
Type
!=
req
.
operation
{
continue
...
...
@@ -85,7 +85,7 @@ func sourcePatchOperationAfterLoop(req *sourcePatchOperationAfterLoopRequest) (b
break
}
}
*
req
.
in
=
false
*
req
.
in
=
""
return
true
,
nil
}
...
...
@@ -119,6 +119,25 @@ func searchAndReplaceLine(line string, sar []*srpmprocpb.SpecChange_SearchAndRep
return
line
}
func
isNextLineSection
(
lineNum
int
,
lines
[]
string
)
bool
{
if
len
(
lines
)
-
1
>
lineNum
{
if
strings
.
HasPrefix
(
strings
.
TrimSpace
(
lines
[
lineNum
+
1
]),
"%"
)
{
return
true
}
return
false
}
return
true
}
func
setFASlice
(
futureAdditions
map
[
int
][]
string
,
key
int
,
addition
string
)
{
if
futureAdditions
[
key
]
==
nil
{
futureAdditions
[
key
]
=
[]
string
{}
}
futureAdditions
[
key
]
=
append
(
futureAdditions
[
key
],
addition
)
}
func
specChange
(
cfg
*
srpmprocpb
.
Cfg
,
pd
*
data
.
ProcessData
,
md
*
data
.
ModeData
,
_
*
git
.
Worktree
,
pushTree
*
git
.
Worktree
)
error
{
// no spec change operations present
// skip parsing spec
...
...
@@ -155,12 +174,12 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
lines
:=
strings
.
Split
(
specStr
,
"
\n
"
)
var
newLines
[]
string
futureAdditions
:=
map
[
int
]
string
{}
futureAdditions
:=
map
[
int
][]
string
{}
newFieldMemory
:=
map
[
string
]
map
[
string
]
int
{}
lastSourceNum
:=
0
lastPatchNum
:=
0
inSources
:=
false
inPatches
:=
false
inSection
:=
""
inField
:=
""
lastSource
:=
""
lastPatch
:=
""
...
...
@@ -182,7 +201,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
fieldValueRegex
:=
regexp
.
MustCompile
(
"^[A-Z].+:"
)
longestField
:=
0
for
_
,
line
:=
range
lines
{
for
lineNum
,
line
:=
range
lines
{
if
fieldValueRegex
.
MatchString
(
line
)
{
fieldValue
:=
strings
.
SplitN
(
line
,
":"
,
2
)
field
:=
strings
.
TrimSpace
(
fieldValue
[
0
])
...
...
@@ -190,10 +209,32 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
if
strings
.
HasPrefix
(
field
,
"Source"
)
{
lastSource
=
field
}
else
if
strings
.
HasPrefix
(
field
,
"Patch"
)
{
lastPatch
=
field
}
else
{
for
_
,
nf
:=
range
cfg
.
SpecChange
.
NewField
{
if
field
==
nf
.
Key
{
if
newFieldMemory
[
field
]
==
nil
{
newFieldMemory
[
field
]
=
map
[
string
]
int
{}
}
newFieldMemory
[
field
][
nf
.
Value
]
=
lineNum
}
}
}
}
}
for
_
,
nf
:=
range
cfg
.
SpecChange
.
NewField
{
if
newFieldMemory
[
nf
.
Key
]
==
nil
{
newFieldMemory
[
nf
.
Key
]
=
map
[
string
]
int
{}
newFieldMemory
[
nf
.
Key
][
nf
.
Value
]
=
0
}
}
if
strings
.
HasPrefix
(
field
,
"Patch"
)
{
lastPatch
=
field
for
field
,
nfm
:=
range
newFieldMemory
{
for
value
,
lineNum
:=
range
nfm
{
if
lineNum
!=
0
{
newLine
:=
fmt
.
Sprintf
(
"%s:%s%s"
,
field
,
calculateSpaces
(
longestField
,
len
(
field
)),
value
)
setFASlice
(
futureAdditions
,
lineNum
+
1
,
newLine
)
}
}
}
...
...
@@ -203,9 +244,11 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
inLoopPatchNum
:=
lastPatchNum
prefixLine
:=
strings
.
TrimSpace
(
line
)
for
i
,
addition
:=
range
futureAdditions
{
for
i
,
addition
s
:=
range
futureAdditions
{
if
lineNum
==
i
{
newLines
=
append
(
newLines
,
addition
)
for
_
,
addition
:=
range
additions
{
newLines
=
append
(
newLines
,
addition
)
}
}
}
...
...
@@ -216,9 +259,9 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
value
:=
strings
.
TrimSpace
(
fieldValue
[
1
])
if
field
==
lastSource
{
in
Sources
=
true
in
Field
=
"Source"
}
else
if
field
==
lastPatch
{
in
Patches
=
true
in
Field
=
"Patch"
}
if
field
==
"Version"
&&
version
==
""
{
...
...
@@ -253,7 +296,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
value
:
&
value
,
lastNum
:
&
lastSourceNum
,
longestField
:
longestField
,
in
:
&
in
Sources
,
in
:
&
in
Field
,
expectedField
:
"Source"
,
operation
:
srpmprocpb
.
SpecChange_FileOperation_Source
,
})
...
...
@@ -267,7 +310,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
value
:
&
value
,
longestField
:
longestField
,
lastNum
:
&
lastPatchNum
,
in
:
&
in
Patches
,
in
:
&
in
Field
,
expectedField
:
"Patch"
,
operation
:
srpmprocpb
.
SpecChange_FileOperation_Patch
,
})
...
...
@@ -286,7 +329,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
longestField
:
longestField
,
newLines
:
&
newLines
,
expectedField
:
"Source"
,
in
:
&
in
Sources
,
in
:
&
in
Field
,
operation
:
srpmprocpb
.
SpecChange_FileOperation_Source
,
})
if
err
!=
nil
{
...
...
@@ -295,7 +338,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
if
executed
&&
!
strings
.
Contains
(
specStr
,
"Patch"
)
{
newLines
=
append
(
newLines
,
""
)
in
Patches
=
true
in
Field
=
"Patch"
}
executed
,
err
=
sourcePatchOperationAfterLoop
(
&
sourcePatchOperationAfterLoopRequest
{
...
...
@@ -305,13 +348,33 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
longestField
:
longestField
,
newLines
:
&
newLines
,
expectedField
:
"Patch"
,
in
:
&
in
Patches
,
in
:
&
in
Field
,
operation
:
srpmprocpb
.
SpecChange_FileOperation_Patch
,
})
if
err
!=
nil
{
return
err
}
if
executed
{
var
innerNewLines
[]
string
for
field
,
nfm
:=
range
newFieldMemory
{
for
value
,
ln
:=
range
nfm
{
newLine
:=
fmt
.
Sprintf
(
"%s:%s%s"
,
field
,
calculateSpaces
(
longestField
,
len
(
field
)),
value
)
if
ln
==
0
{
if
isNextLineSection
(
lineNum
,
lines
)
{
innerNewLines
=
append
(
innerNewLines
,
newLine
)
}
}
}
}
if
len
(
innerNewLines
)
>
0
{
newLines
=
append
(
newLines
,
""
)
for
_
,
il
:=
range
innerNewLines
{
newLines
=
append
(
newLines
,
il
)
}
}
}
if
executed
&&
!
strings
.
Contains
(
specStr
,
"%changelog"
)
{
newLines
=
append
(
newLines
,
""
)
newLines
=
append
(
newLines
,
"%changelog"
)
...
...
@@ -341,7 +404,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
for
i
,
x
:=
range
lines
[
lineNum
+
1
:
]
{
if
strings
.
HasPrefix
(
strings
.
TrimSpace
(
x
),
"%"
)
{
insertedLine
=
lineNum
+
i
+
2
futureAdditions
[
insertedLine
]
=
appendOp
.
Value
setFASlice
(
futureAdditions
,
insertedLine
,
appendOp
.
Value
)
break
}
}
...
...
@@ -349,7 +412,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
for
i
,
x
:=
range
lines
[
lineNum
+
1
:
]
{
if
strings
.
TrimSpace
(
x
)
==
""
{
insertedLine
=
lineNum
+
i
+
2
futureAdditions
[
insertedLine
]
=
appendOp
.
Value
setFASlice
(
futureAdditions
,
insertedLine
,
appendOp
.
Value
)
break
}
}
...
...
pb/cfg.pb.go
View file @
b18468ed
This diff is collapsed.
Click to expand it.
proto/cfg.proto
View file @
b18468ed
...
...
@@ -111,11 +111,19 @@ message SpecChange {
string
field
=
1
;
string
value
=
2
;
}
// NewFieldOperation adds a new kv to the spec
// The field will be grouped if other fields of same name exists
message
NewFieldOperation
{
// Key cannot be Source or Patch
string
key
=
1
;
string
value
=
2
;
}
repeated
FileOperation
file
=
1
;
repeated
ChangelogOperation
changelog
=
2
;
repeated
SearchAndReplaceOperation
search_and_replace
=
3
;
repeated
AppendOperation
append
=
4
;
repeated
NewFieldOperation
new_field
=
5
;
}
message
Patch
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment