Skip to content

Commit

Permalink
Add support for disabling auto align
Browse files Browse the repository at this point in the history
  • Loading branch information
mstg committed Mar 28, 2022
1 parent e0081b4 commit 2fafeba
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 76 deletions.
153 changes: 82 additions & 71 deletions pb/cfg.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions pkg/directives/spec_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func sourcePatchOperationAfterLoop(req *sourcePatchOperationAfterLoopRequest) (b
case *srpmprocpb.SpecChange_FileOperation_Add:
fieldNum := *req.lastNum + 1
field := fmt.Sprintf("%s%d", req.expectedField, fieldNum)
spaces := calculateSpaces(req.longestField, len(field))
spaces := calculateSpaces(req.longestField, len(field), req.cfg.SpecChange.DisableAutoAlign)
*req.newLines = append(*req.newLines, fmt.Sprintf("%s:%s%s", field, spaces, file.Name))

if req.expectedField == "Patch" && file.AddToPrep {
Expand All @@ -132,7 +132,10 @@ func sourcePatchOperationAfterLoop(req *sourcePatchOperationAfterLoopRequest) (b
return false, nil
}

func calculateSpaces(longestField int, fieldLength int) string {
func calculateSpaces(longestField int, fieldLength int, disableAutoAlign bool) string {
if disableAutoAlign {
return ""
}
return strings.Repeat(" ", longestField+8-fieldLength)
}

Expand Down Expand Up @@ -284,7 +287,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
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)
newLine := fmt.Sprintf("%s:%s%s", field, calculateSpaces(longestField, len(field), cfg.SpecChange.DisableAutoAlign), value)
setFASlice(futureAdditions, lineNum+1, newLine)
}
}
Expand Down Expand Up @@ -339,7 +342,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
}
}

spaces := calculateSpaces(longestField, len(field))
spaces := calculateSpaces(longestField, len(field), cfg.SpecChange.DisableAutoAlign)

err := sourcePatchOperationInLoop(&sourcePatchOperationInLoopRequest{
cfg: cfg,
Expand Down Expand Up @@ -410,7 +413,7 @@ func specChange(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, _
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)
newLine := fmt.Sprintf("%s:%s%s", field, calculateSpaces(longestField, len(field), cfg.SpecChange.DisableAutoAlign), value)
if ln == 0 {
if isNextLineSection(lineNum, lines) {
innerNewLines = append(innerNewLines, newLine)
Expand Down
1 change: 1 addition & 0 deletions proto/cfg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ message SpecChange {
repeated SearchAndReplaceOperation search_and_replace = 3;
repeated AppendOperation append = 4;
repeated NewFieldOperation new_field = 5;
bool disable_auto_align = 6;
}

message Patch {
Expand Down

0 comments on commit 2fafeba

Please sign in to comment.