80 prop_re = re.compile("\s*(\S+)\s*=\s*(\S+)\s*$") 81 i = 0 82 for ln in f.readlines(): 83 i = i + 1 84 ln = ln.strip() 85 if (ln.startswith("#")): 86 continue 87 m = prop_re.match(ln) 88 if not m: 89 raise util.Abort("%s:%d: Invalid configuration syntax: %s" 90 % (fn, i, ln)) 91 cf[m.group(1)] = m.group(2) 92 finally: 93 f.close() 94 for pn in ["project"]: 95 if not cf.has_key(pn): 96 raise util.Abort("%s: Missing property: %s" % (fn, pn)) 97 return cf 98 99 100 # Author validation 101 102 author_cache = { } ## Should really cache more permanently 103 104 def validate_author(an, pn): 105 if author_cache.has_key(an): 106 return True 107 u = ("http://db.openjdk.java.net/people/%s/projects/%s" 108 % (urllib.quote(an), pn)) 109 f = None 110 try: 111 try: 112 f = urllib2.urlopen(u) 113 except urllib2.HTTPError, e: 114 if e.code == 404: 115 return False 116 raise e 117 finally: 118 if f: 119 f.close() 334 self.conf = load_conf(repo.root) 335 self.whitespace_lax = lax and not strict 336 if self.conf.get("whitespace") == "lax": 337 self.whitespace_lax = True 338 self.comments_lax = lax and not strict 339 if self.conf.get("comments") == "lax": 340 self.comments_lax = True 341 self.tags_lax = lax and not strict 342 if self.conf.get("tags") == "lax": 343 self.tags_lax = True 344 self.bugids_allow_dups = self.conf.get("bugids") == "dup" 345 self.bugids_lax = lax and not strict 346 if self.conf.get("bugids") == "lax": 347 self.bugids_lax = True 348 self.bugids_ignore = False 349 if self.conf.get("bugids") == "ignore": 350 self.bugids_ignore = True 351 if not self.bugids_ignore: 352 # only identify bug ids if we are going to use them 353 self.repo_bugids = repo_bugids(ui, repo) 354 self.blacklist = dict.fromkeys(changeset_blacklist) 355 self.read_blacklist(blacklist_file) 356 # hg < 1.0 does not have localrepo.tagtype() 357 self.tagtype = getattr(self.repo, 'tagtype', lambda k: 'global') 358 359 def read_blacklist(self, fname): 360 if not os.path.exists(fname): 361 return 362 self.ui.debug('Reading blacklist file %s\n' % fname) 363 f = open(fname) 364 for line in f: 365 # Any comment after the changeset hash becomes the dictionary value. 366 l = [s.strip() for s in line.split('#', 1)] 367 if l and l[0]: 368 self.blacklist[l[0]] = len(l) == 2 and l[1] or None 369 f.close() 370 371 def summarize(self, ctx): 372 self.ui.status("\n") 373 self.ui.status("> Changeset: %d:%s\n" % (ctx.rev(), short(ctx.node()))) 457 self.error(ctx, "Incomplete comment: Missing bugid line") 458 elif gi == 1 or (gi == 2 and n == 0): 459 self.error(ctx, "Incomplete comment: Missing reviewer attribution") 460 if (i < len(lns)): 461 self.error(ctx, "Extraneous text in comment") 462 463 def c_02_files(self, ctx): 464 changes = self.repo.status(ctx.parents()[0].node(), 465 ctx.node(), None)[:5] 466 modified, added = changes[:2] 467 # ## Skip files that were renamed but not modified 468 files = modified + added 469 if self.ui.debugflag: 470 self.ui.debug("Checking files: %s\n" % ", ".join(files)) 471 for f in files: 472 if ctx.rev() == 0: 473 ## This is loathsome 474 if f.startswith("test/java/rmi"): continue 475 if f.startswith("test/com/sun/javadoc/test"): continue 476 if f.startswith("docs/technotes/guides"): continue 477 fx = ctx.filectx(f) 478 if normext_re.match(f) and not self.whitespace_lax: 479 data = fx.data() 480 m = badwhite_re.search(data) 481 if m: 482 ln = data.count("\n", 0, m.start()) + 1 483 self.error(ctx, "%s:%d: %s" % (f, ln, badwhite_what(m))) 484 ## check_file_header(self, fx, data) 485 flags = fx.manifest().flags(f) 486 if 'x' in flags: 487 self.error(ctx, "%s: Executable files not permitted" % f) 488 if 'l' in flags: 489 self.error(ctx, "%s: Symbolic links not permitted" % f) 490 491 def c_03_hash(self, ctx): 492 hash = hex(ctx.node()) 493 if hash in self.blacklist: 494 self.error(ctx, "Blacklisted changeset: " + hash) 495 496 def check(self, node): | 80 prop_re = re.compile("\s*(\S+)\s*=\s*(\S+)\s*$") 81 i = 0 82 for ln in f.readlines(): 83 i = i + 1 84 ln = ln.strip() 85 if (ln.startswith("#")): 86 continue 87 m = prop_re.match(ln) 88 if not m: 89 raise util.Abort("%s:%d: Invalid configuration syntax: %s" 90 % (fn, i, ln)) 91 cf[m.group(1)] = m.group(2) 92 finally: 93 f.close() 94 for pn in ["project"]: 95 if not cf.has_key(pn): 96 raise util.Abort("%s: Missing property: %s" % (fn, pn)) 97 return cf 98 99 100 # Parse sub repos 101 102 def parse_subrepos(l): 103 sr = { } 104 sr = re.split(',', l) 105 return sr 106 107 108 # Author validation 109 110 author_cache = { } ## Should really cache more permanently 111 112 def validate_author(an, pn): 113 if author_cache.has_key(an): 114 return True 115 u = ("http://db.openjdk.java.net/people/%s/projects/%s" 116 % (urllib.quote(an), pn)) 117 f = None 118 try: 119 try: 120 f = urllib2.urlopen(u) 121 except urllib2.HTTPError, e: 122 if e.code == 404: 123 return False 124 raise e 125 finally: 126 if f: 127 f.close() 342 self.conf = load_conf(repo.root) 343 self.whitespace_lax = lax and not strict 344 if self.conf.get("whitespace") == "lax": 345 self.whitespace_lax = True 346 self.comments_lax = lax and not strict 347 if self.conf.get("comments") == "lax": 348 self.comments_lax = True 349 self.tags_lax = lax and not strict 350 if self.conf.get("tags") == "lax": 351 self.tags_lax = True 352 self.bugids_allow_dups = self.conf.get("bugids") == "dup" 353 self.bugids_lax = lax and not strict 354 if self.conf.get("bugids") == "lax": 355 self.bugids_lax = True 356 self.bugids_ignore = False 357 if self.conf.get("bugids") == "ignore": 358 self.bugids_ignore = True 359 if not self.bugids_ignore: 360 # only identify bug ids if we are going to use them 361 self.repo_bugids = repo_bugids(ui, repo) 362 self.subrepos = [ ] 363 if self.conf.get("subrepos") != None: 364 self.subrepos = parse_subrepos(self.conf.get("subrepos")) 365 self.blacklist = dict.fromkeys(changeset_blacklist) 366 self.read_blacklist(blacklist_file) 367 # hg < 1.0 does not have localrepo.tagtype() 368 self.tagtype = getattr(self.repo, 'tagtype', lambda k: 'global') 369 370 def read_blacklist(self, fname): 371 if not os.path.exists(fname): 372 return 373 self.ui.debug('Reading blacklist file %s\n' % fname) 374 f = open(fname) 375 for line in f: 376 # Any comment after the changeset hash becomes the dictionary value. 377 l = [s.strip() for s in line.split('#', 1)] 378 if l and l[0]: 379 self.blacklist[l[0]] = len(l) == 2 and l[1] or None 380 f.close() 381 382 def summarize(self, ctx): 383 self.ui.status("\n") 384 self.ui.status("> Changeset: %d:%s\n" % (ctx.rev(), short(ctx.node()))) 468 self.error(ctx, "Incomplete comment: Missing bugid line") 469 elif gi == 1 or (gi == 2 and n == 0): 470 self.error(ctx, "Incomplete comment: Missing reviewer attribution") 471 if (i < len(lns)): 472 self.error(ctx, "Extraneous text in comment") 473 474 def c_02_files(self, ctx): 475 changes = self.repo.status(ctx.parents()[0].node(), 476 ctx.node(), None)[:5] 477 modified, added = changes[:2] 478 # ## Skip files that were renamed but not modified 479 files = modified + added 480 if self.ui.debugflag: 481 self.ui.debug("Checking files: %s\n" % ", ".join(files)) 482 for f in files: 483 if ctx.rev() == 0: 484 ## This is loathsome 485 if f.startswith("test/java/rmi"): continue 486 if f.startswith("test/com/sun/javadoc/test"): continue 487 if f.startswith("docs/technotes/guides"): continue 488 ## check file does not start with subrepo path 489 for sr in self.subrepos: 490 if f.startswith(sr): 491 self.error(ctx, "%s: subrepo file not permitted" % f) 492 fx = ctx.filectx(f) 493 if normext_re.match(f) and not self.whitespace_lax: 494 data = fx.data() 495 m = badwhite_re.search(data) 496 if m: 497 ln = data.count("\n", 0, m.start()) + 1 498 self.error(ctx, "%s:%d: %s" % (f, ln, badwhite_what(m))) 499 ## check_file_header(self, fx, data) 500 flags = fx.manifest().flags(f) 501 if 'x' in flags: 502 self.error(ctx, "%s: Executable files not permitted" % f) 503 if 'l' in flags: 504 self.error(ctx, "%s: Symbolic links not permitted" % f) 505 506 def c_03_hash(self, ctx): 507 hash = hex(ctx.node()) 508 if hash in self.blacklist: 509 self.error(ctx, "Blacklisted changeset: " + hash) 510 511 def check(self, node): |