+def modules_diff(first, second):
+ diff = {}
+
+ for module in first:
+ if module not in second:
+ print("=== module {} missing in right-hand side ===".format(module))
+ continue
+ if first[module]['tag_or_branch'] != second[module]['tag_or_branch']:
+ diff[module] = (first[module]['tag_or_branch'], second[module]['tag_or_branch'])
+
+ first_set = set(first.keys())
+ second_set = set(second.keys())
+
+ new_modules = list(second_set - first_set)
+ removed_modules = list(first_set - second_set)
+
+ return diff, new_modules, removed_modules
+
+def release_changelog(options, buildtag_old, buildtag_new):
+
+ # the command line expects new old, so we treat the tagfiles in the same order
+ nb_tags = len(options.distrotags)
+ if nb_tags == 1:
+ tagfile_new = tagfile_old = options.distrotags[0]
+ elif nb_tags == 2:
+ tagfile_new, tagfile_old = options.distrotags
+ else:
+ print("ERROR: provide one or two tagfile name (eg. onelab-k32-tags.mk)")
+ print("two tagfiles can be mentioned when a tagfile has been renamed")
+ return
+
+ if options.dry_run:
+ print("------------------------------ Computing Changelog from")
+ print("buildtag_old", buildtag_old, "tagfile_old", tagfile_old)
+ print("buildtag_new", buildtag_new, "tagfile_new", tagfile_new)
+ return
+
+ print('----')
+ print('----')
+ print('----')
+ print('= build tag {} to {} ='.format(buildtag_old, buildtag_new))
+ print('== distro {} ({} to {}) =='.format(tagfile_new, buildtag_old, buildtag_new))
+
+ build = Build("build@{}".format(buildtag_old), options)
+ build.init_module_dir()
+ first = build.get_modules(tagfile_old)
+
+ print(' * from', buildtag_old, build.repository.gitweb())
+
+ build = Build("build@{}".format(buildtag_new), options)
+ build.init_module_dir()
+ second = build.get_modules(tagfile_new)
+
+ print(' * to', buildtag_new, build.repository.gitweb())
+
+ diff, new_modules, removed_modules = modules_diff(first, second)
+
+
+ def get_module(name, tag):
+ if not tag or tag == "trunk":
+ return Module("{}".format(module), options)
+ else:
+ return Module("{}@{}".format(module, tag), options)
+
+
+ for module in diff:
+ print('=== {} - {} to {} : package {} ==='.format(tagfile_new, buildtag_old, buildtag_new, module))
+
+ first, second = diff[module]
+ m = get_module(module, first)
+ os.system('rm -rf {}'.format(m.module_dir)) # cleanup module dir
+ m.init_module_dir()
+
+ print(' * from', first, m.repository.gitweb())
+
+ specfile = m.main_specname()
+ (tmpfd, tmpfile) = tempfile.mkstemp()
+ os.system("cp -f /{} {}".format(specfile, tmpfile))
+
+ m = get_module(module, second)
+ # patch for ipfw that, being managed in a separate repo, won't work for now
+ try:
+ m.init_module_dir()
+ except Exception as e:
+ print("""Could not retrieve module {} - skipped
+{{{{{{ {} }}}}}}
+""".format( m.friendly_name(), e))
+ continue
+ specfile = m.main_specname()
+
+ print(' * to', second, m.repository.gitweb())
+
+ print('{{{')
+ os.system("diff -u {} {} | sed -e 's,{},[[previous version]],'"\
+ .format(tmpfile, specfile, tmpfile))
+ print('}}}')
+
+ os.unlink(tmpfile)
+
+ for module in new_modules:
+ print('=== {} : new package in build {} ==='.format(tagfile_new, module))
+
+ for module in removed_modules:
+ print('=== {} : removed package from build {} ==='.format(tagfile_new, module))
+
+
+def adopt_tag(options, args):
+ modules=[]
+ for module in options.modules:
+ modules += module.split()
+ for module in modules:
+ modobj=Module(module,options)
+ for tags_file in args:
+ if options.verbose:
+ print('adopting tag {} for {} in {}'.format(options.tag, module, tags_file))
+ modobj.patch_tags_file(tags_file, '_unused_', options.tag, fine_grain=False)
+ if options.verbose:
+ Command("git diff {}".format(" ".join(args)), options).run()