- # print warning if pending diffs
- if diff_listing:
- print """*** WARNING : Module %s has pending diffs on its trunk
-It is safe to proceed, but please note that branch %s
-will be based on latest tag %s and *not* on the current trunk"""%(self.name,branch_name,latest_tag_name)
- while True:
- answer = prompt ('Are you sure you want to proceed with branching',True,('d','iff'))
- if answer is True:
- break
- elif answer is False:
- raise Exception,"User quit"
- elif answer == 'd':
- print '<<<< %s'%tag_url
- print '>>>> %s'%edge_url
- print diff_listing
-
- branch_url = "%s/%s/branches/%s"%(Module.config['svnpath'],self.name,branch_name)
- self.check_svnpath_not_exists (branch_url,"new branch")
-
- # patching trunk
- spec_dict[self.module_version_varname]=new_trunk_name
- spec_dict[self.module_taglevel_varname]='0'
- # remember this in the trunk for easy location of the current branch
- spec_dict['module_current_branch']=branch_name
- self.patch_spec_var(spec_dict,True)
-
- # create commit log file
- tmp="/tmp/branching-%d"%os.getpid()
- f=open(tmp,"w")
- f.write("Branch %s for module %s created from tag %s\n"%(new_trunk_name,self.name,latest_tag_name))
- f.close()
-
- # we're done, let's commit the stuff
- command="svn diff %s"%self.edge_dir()
- self.run_prompt("Review changes in trunk",command)
- command="svn copy --file %s %s %s"%(tmp,self.edge_url(),branch_url)
- self.run_prompt("Create branch",command)
- command="svn commit --file %s %s"%(tmp,self.edge_dir())
- self.run_prompt("Commit trunk",command)
- new_tag_url=self.tag_url(spec_dict)
- command="svn copy --file %s %s %s"%(tmp,self.edge_url(),new_tag_url)
- self.run_prompt("Create initial tag in trunk",command)
- os.unlink(tmp)
+
+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()