@@ -66,7 +66,7 @@ def version_key(version: str) -> int:
6666
6767
6868def find_commits_versions (
69- commits : list [str ], single_script_path : str
69+ commits : list [str ], all : bool , single_script_path : str
7070) -> tuple [list [str ], dict [str , list ]]:
7171 """Find all the versions associated to the commits
7272
@@ -78,12 +78,24 @@ def find_commits_versions(
7878 versions = linux_version_finder_single (single_script_path , commit )
7979 for version in versions :
8080 minor_version = get_minor_version (version )
81- versions_count [minor_version ].append (version )
81+ if all :
82+ # If the --no-all option isn't used add the version
83+ # because we need to know the version where the commit
84+ # was merged.
85+ versions_count [minor_version ].append (version )
86+ else :
87+ # If the --no-all option is used add the sha1 of the
88+ # commit because we need to know which commit was
89+ # merged/backported.
90+ versions_count [minor_version ].append (commit )
8291 if minor_version :
8392 start = minor_versions .index (minor_version ) + 1
8493 for i in range (start , len (minor_versions )):
8594 minor_version = minor_versions [i ]
86- versions_count [minor_version ].append (minor_version + "-rc0" )
95+ if all :
96+ versions_count [minor_version ].append (minor_version + "-rc0" )
97+ else :
98+ versions_count [minor_version ].append (commit )
8799 return minor_versions , versions_count
88100
89101
@@ -106,17 +118,55 @@ def print_versions_with_all_commits(
106118 print ("" )
107119
108120
121+ def get_short_sha (commit : str ) -> str :
122+ """Get a short unique sha
123+
124+ E.g. 51b6489 instead of 51b6489bbe2d5433993c7e6dcf5a99039760d3b0."""
125+ completedProcess = subprocess .run (
126+ ["git" , "rev-parse" , "--short" , commit ],
127+ capture_output = True ,
128+ check = True ,
129+ )
130+ return completedProcess .stdout .decode ("utf-8" ).strip ()
131+
132+
133+ def print_versions_without_all_commits (
134+ commits : list [str ], minor_versions : list [str ], versions_count : dict [str , list ]
135+ ) -> None :
136+ """Print Linux versions that don't contain all the commits"""
137+ len_commits = len (commits )
138+ short_sha = {commit : get_short_sha (commit ) for commit in commits }
139+
140+ for minor_version in reversed (minor_versions ):
141+ minor_version_count = versions_count [minor_version ]
142+ if len_commits > len (minor_version_count ):
143+ print (f"{ minor_version } :\t " , end = "" )
144+ # to speed up the check use a set
145+ set_commits_presents = set (minor_version_count )
146+ missing_commits = [x for x in commits if x not in set_commits_presents ]
147+ for commit in missing_commits :
148+ short = short_sha [commit ]
149+ print (f" { short } " , end = "" )
150+ print ("" )
151+
152+
109153def main (
110154 commits : List [str ],
155+ all : bool = typer .Option (True , help = "Print the versions with all commits." ),
111156 debug : bool = typer .Option (False , help = "Print debug info." ),
112157):
113158 if debug :
114159 logging .basicConfig (level = logging .DEBUG )
115160 single_script_path = os .path .dirname (sys .argv [0 ]) + "/linux-version-finder-single"
116- minor_versions , versions_count = find_commits_versions (commits , single_script_path )
161+ minor_versions , versions_count = find_commits_versions (
162+ commits , all , single_script_path
163+ )
117164 logging .debug (versions_count )
118165
119- print_versions_with_all_commits (commits , minor_versions , versions_count )
166+ if all :
167+ print_versions_with_all_commits (commits , minor_versions , versions_count )
168+ else :
169+ print_versions_without_all_commits (commits , minor_versions , versions_count )
120170
121171
122172if __name__ == "__main__" :
0 commit comments