@@ -261,36 +261,58 @@ function _package_is_supported(argv, packagename)
261261 end
262262end
263263
264+ function append_package_version (packages , line )
265+ local version = line :match (" add_versions%(\" (.-)\" " ) or line :match (" package:add%(\" versions\" ,%s*\" (.-)\" " )
266+ if version then
267+ if version :find (" :" , 1 , true ) then
268+ version = version :split (" :" )[2 ]
269+ end
270+ if # packages > 0 and version then
271+ local lastpackage = packages [# packages ]
272+ local splitinfo = lastpackage :split (" %s+" )
273+ table.insert (packages , splitinfo [1 ] .. " " .. version )
274+ end
275+ end
276+ end
277+
264278function get_modified_packages ()
265- local packages = {}
279+ local new_packages = {}
280+ local old_packages = {}
266281 local diff = os .iorun (" git --no-pager diff HEAD^" )
267282 for _ , line in ipairs (diff :split (" \n " )) do
268283 if line :startswith (" +++ b/" ) then
269284 local file = line :sub (7 )
270285 if file :startswith (" packages" ) then
271286 assert (file == file :lower (), " %s must be lower case!" , file )
272287 local package = file :match (" packages/%w/(%S-)/" )
273- table.insert (packages , package )
288+ table.insert (new_packages , package )
289+ table.insert (old_packages , package )
274290 end
275291 elseif line :startswith (" +" ) and (line :find (" add_versions" , 1 , true ) or line :find (" package:add(\" versions\" " , 1 , true )) then
276- local version = line :match (" add_versions%(\" (.-)\" " ) or line :match (" package:add%(\" versions\" ,%s*\" (.-)\" " )
277- if version then
278- if version :find (" :" , 1 , true ) then
279- version = version :split (" :" )[2 ]
280- end
281- if # packages > 0 and version then
282- local lastpackage = packages [# packages ]
283- local splitinfo = lastpackage :split (" %s+" )
284- if # splitinfo > 1 then
285- table.insert (packages , splitinfo [1 ] .. " " .. version )
286- else
287- packages [# packages ] = splitinfo [1 ] .. " " .. version
288- end
289- end
292+ append_package_version (new_packages , line )
293+ elseif line :startswith (" -" ) and (line :find (" add_versions" , 1 , true ) or line :find (" package:add(\" versions\" " , 1 , true )) then
294+ append_package_version (old_packages , line )
295+ end
296+ end
297+ if # old_packages > 0 then
298+ table .remove_if (old_packages , function (_ , package )
299+ local splitinfo = package :split (" %s+" )
300+ return # splitinfo == 1
301+ end )
302+ table .remove_if (new_packages , function (_ , package )
303+ return table .contains (old_packages , package )
304+ end )
305+ -- {
306+ -- "pkgname", <-- remove this
307+ -- "pkgname pkgver"
308+ -- }
309+ for i = # new_packages - 1 , 1 , - 1 do
310+ if new_packages [i + 1 ]:startswith (new_packages [i ] .. " " ) then
311+ table.remove (new_packages , i )
290312 end
291313 end
292314 end
293- return table .unique (packages )
315+ return table .unique (new_packages )
294316end
295317
296318-- @see https://github.com/xmake-io/xmake-repo/issues/6940
0 commit comments