def wrappedcommit(orig, repo, *args, **kwargs): try: path_matcher = args[3] except IndexError: # In a rebase for example return orig(repo, *args, **kwargs) # In case hg changes the position of the arg # path_matcher will be empty in case of histedit assert isinstance(path_matcher, match.basematcher) or path_matcher is None try: lock = repo.wlock() status = repo.status(match=path_matcher) changed_files = sorted(status.modified + status.added) if not is_firefox_repo(repo) or not changed_files: # this isn't a firefox repo, don't run clang-format # as it is fx specific # OR we don't modify any files lock.release() return orig(repo, *args, **kwargs) call_clang_format(repo, changed_files) except Exception as e: repo.ui.warn('Exception %s\n' % str(e)) finally: lock.release() return orig(repo, *args, **kwargs)
def reposetup(ui, repo): # Avoid setup altogether if `moz-phab` is executing hg, # or the repository is not a Firefox derivative, # or the repo is not local if not repo.local() or 'MOZPHAB' in os.environ or not is_firefox_repo(repo): return extensions.wrapfunction(localrepo.localrepository, b'commit', wrappedcommit) extensions.wrapfunction(cmdutil, b'amend', wrappedamend)
def wrappedamend(orig, ui, repo, old, extra, pats, opts): '''Wraps cmdutil.amend to run clang-format during `hg commit --amend`''' wctx = repo[None] matcher = scmutil.match(wctx, pats, opts) filestoamend = [f for f in wctx.files() if matcher(f)] if not is_firefox_repo(repo) or not filestoamend: return orig(ui, repo, old, extra, pats, opts) try: with repo.wlock(): call_clang_format(repo, filestoamend) except Exception as e: repo.ui.warn('Exception %s\n' % str(e)) return orig(ui, repo, old, extra, pats, opts)
def db_for_repo(repo): """Obtain a FirefoxReleaseDatabase for a repo or None.""" if not repo.local(): return None if not repo.ui.configbool('mozilla', 'enablefirefoxreleases', False): return None if not is_firefox_repo(repo): return None default = repo.vfs.join('firefoxreleases.db') path = repo.ui.config('mozilla', 'firefoxreleasesdb', default) if not os.path.exists(path): return None return releasedb.FirefoxReleaseDatabase(path)
def db_for_repo(repo): """Obtain a FirefoxReleaseDatabase for a repo or None.""" if not repo.local(): return None if (not repo.ui.configbool(b'mozilla', b'enablefirefoxreleases', False) # deprecated and not repo.ui.configbool(b'mozilla', b'firefox_releasing', False)): return None if not is_firefox_repo(repo): return None default = repo.vfs.join(b'firefoxreleases.db') path = repo.ui.config(b'mozilla', b'firefoxreleasesdb', default) if not os.path.exists(path): return None return releasedb.FirefoxReleaseDatabase(pycompat.sysstr(path), bytestype=pycompat.bytestr)
def should_use_default(repo, tool): return tool == 'clang-format' and not repo.ui.config( 'format-source', tool) and is_firefox_repo(repo)
def should_use_default(repo, tool): # Only enable formatting with prettier, to avoid unnecessary overhead. return tool == 'prettier-format' and not repo.ui.config( 'format-source', tool) and is_firefox_repo(repo)