-
Notifications
You must be signed in to change notification settings - Fork 6
Do not duplicate packages when running gazelle-update-repos #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GuillaumeGen
wants to merge
7
commits into
main
Choose a base branch
from
gg/#46
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4729a48
Do not duplicate packages when running gazelle-update-repos
GuillaumeGen 124ad22
Facundo's comments
GuillaumeGen 966b082
Attempt to modify Fix function
GuillaumeGen 362e862
Syntax
GuillaumeGen 7388c7e
Ugly type annotations
GuillaumeGen fed76e2
Add an ugly print
GuillaumeGen 999e16a
Debugging
GuillaumeGen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import ( | |
| "errors" | ||
| "flag" | ||
| "fmt" | ||
| "strconv" | ||
| "regexp" | ||
|
|
||
| "github.com/bazelbuild/bazel-gazelle/config" | ||
| "github.com/bazelbuild/bazel-gazelle/label" | ||
|
|
@@ -413,7 +413,15 @@ func mapSortedStringKeys(m map[string]bool) []string { | |
| return s_result | ||
| } | ||
|
|
||
| // This function assumes that equivalent elements are bundled and only keeps the last element of each equivalence class. | ||
| // This function assumes that equivalent elements are bundled. | ||
| // Hence, the input list should be preprocessed with a function ensuring this property. | ||
| // | ||
| // In our use-case, it means that | ||
| // the input list must be sorted. | ||
| // | ||
| // This function is only keeping the last representative of the equivalence class. | ||
| // The rationale is it is used to deal with packages having or not a version number, | ||
| // and in case both option are available, the version number should be kept. | ||
| func removeEquivalent(equiv func(string, string) bool, s []string) []string { | ||
| if len(s) < 1 { | ||
| return s | ||
|
|
@@ -422,35 +430,31 @@ func removeEquivalent(equiv func(string, string) bool, s []string) []string { | |
| first_free_position := 1 | ||
| for curr := 1; curr < len(s); curr++ { | ||
| if equiv(s[first_free_position-1], s[curr]) { | ||
| // If the last added element is equivalent is considered one, | ||
| // then we move the cursor back so that the currently considered element | ||
| // replace the previously added one. | ||
| // This function is only keeping the last representative of the equivalence class | ||
| // because it is used to deal with packages having or not a version number, | ||
| // and in case both option are available, the version number should be kept. | ||
| first_free_position-- | ||
| s[first_free_position-1] = s[curr] | ||
| } else { | ||
| s[first_free_position] = s[curr] | ||
| first_free_position++ | ||
| } | ||
| s[first_free_position] = s[curr] | ||
| first_free_position++ | ||
| } | ||
|
|
||
| return s[:first_free_position] | ||
| } | ||
|
|
||
| // The same package should not appear twice in a 'stack_snapshot' rule. | ||
| // See https://github.com/tweag/gazelle_cabal/issue/46 | ||
| func samePackage(s1 string, s2 string) bool { | ||
facundominguez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ss1 := chopVersionNumber(s1) | ||
| ss2 := chopVersionNumber(s2) | ||
| return ss1 == ss2 | ||
| } | ||
|
|
||
| // Strips a suffix "-digit+[.digit+]*" from the given string if present. | ||
| // Otherwise returns the string unmodified. | ||
| func chopVersionNumber(s string) string { | ||
facundominguez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| l := strings.Split(s, "-") | ||
| n := len(l) | ||
| // strconv.Atoi converts a string to an integer, | ||
| // and potentially outputs an error message. | ||
| _, err := strconv.Atoi(strings.ReplaceAll(l[n-1], ".", "")) | ||
| // If the conversion succeeded, the error is 'nil'. | ||
| if err == nil { | ||
| matched, _ := regexp.MatchString(`^[0-9]+(\.[0-9]+)*$`, l[n-1]) | ||
|
||
| if matched { | ||
| return strings.Join(l[:n-1], "-") | ||
| } | ||
| return s | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.