def liveversion(): 'Attempt to read the version from the live repository' utilpath = os.path.dirname(os.path.realpath(__file__)) thgpath = os.path.dirname(os.path.dirname(utilpath)) if not os.path.isdir(os.path.join(thgpath, '.hg')): raise error.RepoError(_('repository %s not found') % thgpath) u = ui.ui() # prevent loading additional extensions for k, _v in u.configitems('extensions'): u.setconfig('extensions', k, '!') repo = hg.repository(u, path=thgpath) u.pushbuffer() commands.identify(u, repo, id=True, tags=True, rev='.') l = u.popbuffer().split() while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags l.pop() if len(l) > 1: # tag found version = l[-1] if l[0].endswith('+'): # propagate the dirty status to the tag version += '+' elif len(l) == 1: # no tag found u.pushbuffer() commands.parents(u, repo, template='{latesttag}+{latesttagdistance}-') version = u.popbuffer().rpartition(':')[2] + l[0] return repo[None].branch(), version
def _get_hg_version(path): from mercurial import hg, ui, commands u = ui.ui() u.pushbuffer() repo = hg.repository(u, path) commands.identify(u, repo) return u.popbuffer()
def _update_hg(path): from mercurial import hg, ui, commands f = open(os.path.join(path, "yt_updater.log"), "a") u = ui.ui() u.pushbuffer() config_fn = os.path.join(path, ".hg", "hgrc") print "Reading configuration from ", config_fn u.readconfig(config_fn) repo = hg.repository(u, path) commands.pull(u, repo) f.write(u.popbuffer()) f.write("\n\n") u.pushbuffer() commands.identify(u, repo) if "+" in u.popbuffer(): print "Can't rebuild modules by myself." print "You will have to do this yourself. Here's a sample commands:" print print " $ cd %s" % (path) print " $ hg up" print " $ %s setup.py develop" % (sys.executable) sys.exit(1) f.write("Rebuilding modules\n\n") p = subprocess.Popen([sys.executable, "setup.py", "build_ext", "-i"], cwd=path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = p.communicate() f.write(stdout) f.write("\n\n") if p.returncode: print "BROKEN: See %s" % (os.path.join(path, "yt_updater.log")) sys.exit(1) f.write("Successful!\n")
def identify(self, wire): repo = self._factory.repo(wire) baseui = self._factory._create_config(wire['config']) output = io.BytesIO() baseui.write = output.write # This is required to get a full node id baseui.debugflag = True commands.identify(baseui, repo, id=True) return output.getvalue()
def get_repo_revision(): repo_path, repo_type = get_repo_root() if repo_type == 'hg': from mercurial import hg, ui, commands ui = ui.ui() repo = hg.repository(ui, repo_path) ui.pushbuffer() commands.identify(ui, repo, rev='.') return ui.popbuffer().split()[0] elif repo_type == 'git': import subprocess return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
def __init__(self, repoRoot): super(HgResourceProvider, self).__init__() self.repoRoot = repoRoot print "Mercurial version %s" % hgversion self.ui = mercurial.ui.ui() self.repo = hg.repository(self.ui, repoRoot) self.ui.status("Connected to repository %s\n" % self.repo.root) self.repoRoot = self.repo.root # Some commands (remove) seem to expect cwd set to the repo # TODO: try to go along without this, because it prevents serving # multiple repos. Instead pass absolute paths to the commands. # print os.getcwd() os.chdir(self.repo.root) # Verify integrity of the repository util.status("Verify repository '%s' tree..." % self.repo.root) commands.verify(self.ui, self.repo) # self.ui.status("Changelog: %s\n" % self.repo.changelog) print "Status:" pprint(self.repo.status()) self.repo.ui.status( "the default username to be used in commits: %s\n" % self.repo.ui.username()) # self.repo.ui.status("a short form of user name USER %s\n" % self.repo.ui.shortuser(user)) self.ui.status("Expandpath: %s\n" % self.repo.ui.expandpath(repoRoot)) print "Working directory state summary:" self.ui.pushbuffer() commands.summary(self.ui, self.repo, remote=False) res = self.ui.popbuffer().strip() reslines = [tuple(line.split(":", 1)) for line in res.split("\n")] pprint(reslines) print "Repository state summary:" self.ui.pushbuffer() commands.identify(self.ui, self.repo, num=True, id=True, branch=True, tags=True) res = self.ui.popbuffer().strip() reslines = [tuple(line.split(":", 1)) for line in res.split("\n")] pprint(reslines) self._getLog()
def __init__(self, repoRoot): super(HgResourceProvider, self).__init__() self.repoRoot = repoRoot print("Mercurial version %s" % hgversion) self.ui = mercurial.ui.ui() self.repo = hg.repository(self.ui, repoRoot) self.ui.status("Connected to repository %s\n" % self.repo.root) self.repoRoot = self.repo.root # Some commands (remove) seem to expect cwd set to the repo # TODO: try to go along without this, because it prevents serving # multiple repos. Instead pass absolute paths to the commands. # print(os.getcwd()) os.chdir(self.repo.root) # Verify integrity of the repository _logger.warning("Verify repository '%s' tree..." % self.repo.root) commands.verify(self.ui, self.repo) # self.ui.status("Changelog: %s\n" % self.repo.changelog) print("Status:") pprint(self.repo.status()) self.repo.ui.status( "the default user_name to be used in commits: %s\n" % self.repo.ui.user_name() ) # self.repo.ui.status("a short form of user name USER %s\n" % self.repo.ui.shortuser(user)) self.ui.status("Expandpath: %s\n" % self.repo.ui.expandpath(repoRoot)) print("Working directory state summary:") self.ui.pushbuffer() commands.summary(self.ui, self.repo, remote=False) res = self.ui.popbuffer().strip() reslines = [tuple(line.split(":", 1)) for line in res.split("\n")] pprint(reslines) print("Repository state summary:") self.ui.pushbuffer() commands.identify(self.ui, self.repo, num=True, id=True, branch=True, tags=True) res = self.ui.popbuffer().strip() reslines = [tuple(line.split(":", 1)) for line in res.split("\n")] pprint(reslines) self._get_log()
def get_hg_info(): try: from mercurial import hg, ui, commands from mercurial.error import RepoError except ImportError: print "WARNING: could not get version information. Please install mercurial." return ('unknown', 'unknown', None) try: u = ui.ui() u.pushbuffer() repo = hg.repository(u, os.path.expanduser('../..')) commands.identify(u, repo) my_info = u.popbuffer().strip().split() u.pushbuffer() commands.diff(u, repo) my_diff = u.popbuffer() return (my_info[0], my_info[1], my_diff) except RepoError: print "WARNING: could not get version information." return ('unknown', 'unknown', None)
def liveversion(): 'Attempt to read the version from the live repository' utilpath = os.path.dirname(os.path.realpath(__file__)) thgpath = os.path.dirname(os.path.dirname(utilpath)) if not os.path.isdir(os.path.join(thgpath, '.hg')): raise error.RepoError(_('repository %s not found') % thgpath) u = ui.ui() repo = hg.repository(u, path=thgpath) u.pushbuffer() commands.identify(u, repo, id=True, tags=True, rev='.') l = u.popbuffer().split() while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags l.pop() if len(l) > 1: # tag found version = l[-1] if l[0].endswith('+'): # propagate the dirty status to the tag version += '+' elif len(l) == 1: # no tag found u.pushbuffer() commands.parents(u, repo, template='{latesttag}+{latesttagdistance}-') version = u.popbuffer() + l[0] return repo[None].branch(), version
def checkconflict(ui, repo, source=None, **opts): """Print there will be a conflict after merge or not.""" check_uncommited_changes(repo) cur_dir = repo.root local_clone_dir = cur_dir + '-local' remote_clone_dir = cur_dir + '-remote' # if the source is not specified, # we take the default one from the repo configuration. # otherwise we take source if source is None: clone_source = check_config(repo, 'default') else: is_URL = bool(urlparse.urlparse(source).netloc) if os.path.isdir(source) or is_URL: clone_source = source else: clone_source = check_config(repo, str(source)) # path to the cache list cache_dir = os.path.expanduser('~\\.hg.cache') cache_list = os.path.join(cache_dir, 'cache_list.json') # if the source is local, then just clone if hg.islocal(clone_source): clone(repo, clone_source, remote_clone_dir) # otherwise, open the cache list and see # if it contains path information to the cache # of the specified resource for the current working repo else: cache_source = None # clear the cache list if this option is set, or # if the cache list does not exist, create it if not os.path.exists(cache_list) or opts.get('clear_cache_list'): if not os.path.exists(cache_dir): make_dir(cache_dir) create_cache_list(cache_list) else: data = read_cache_list(cache_list) cache_source = find_cache_src(data, cur_dir, clone_source) # if the cache resource is found but this path does not exist or the path exists, # but it is not a repo, or set_cache_repo option, # we delete information about this cache repo from the cache list was_cached = cache_source is not None if was_cached: cache_source = cache_source.encode('cp1251') if not is_repo(repo, cache_source) or opts.get('set_cache_repo'): cache_data = read_cache_list(cache_list) new_cache_data = find_cache_src(cache_data, cur_dir, clone_source, for_remove=True) write_cache_list(cache_list, new_cache_data) repo.ui.write('\nThe last path to the cache repository is broken.\n') cache_source = None # if the cache resource is not found # suggest to choose the path to the cash repo # if the paths exists and empty -> clone, # if the path exists and repo -> checkupdate # else: select empty folder if cache_source is None: cache_source = str(raw_input('Specify the path for the cache-repository,\n' 'or if no path it will be use /user/.hg.cache path.\n')).replace('\r', '') if not cache_source: cache_source = default_cache_src(cur_dir, cache_dir) if os.path.exists(cache_source): if not os.listdir(cache_source): clone(repo, clone_source, cache_source) # clone from the resource to the cache elif is_repo(repo, cache_source): clone_root = commands.identify(repo.ui, repo, rev=0) repo = hg.repository(repo.ui, cache_source) cache_root = commands.identify(repo.ui, repo, rev=0) if clone_root == cache_root: check_update(repo, clone_source) repo = hg.repository(repo.ui, cur_dir) else: repo = hg.repository(repo.ui, cur_dir) repo.ui.write('\nCache-repo and remote-repo do not match.\n') sys.exit() else: repo.ui.write('\nYou must select an empty folder or an existing repo folder.\n') sys.exit() else: make_dir(cache_source) clone(repo, clone_source, cache_source) note = gen_note(cur_dir, clone_source, cache_source) write_cache_list(cache_list, note, add=True) # if the cache resource is found, # check if new changes can be pulled. # if yes, pull and update else: repo = hg.repository(repo.ui, cache_source) check_update(repo, clone_source) repo = hg.repository(repo.ui, cur_dir) # finally clone from cache to remote clone(repo, cache_source, remote_clone_dir) # create a local repo clone clone(repo, cur_dir, local_clone_dir) repo = hg.repository(repo.ui, remote_clone_dir) # go to remote repo clone commands.pull(repo.ui, repo, local_clone_dir) # pull changes from a local repo clone to it commands.update(repo.ui, repo) # update repo.ui.pushbuffer() conflict = do_merge(repo) deleted_str = repo.ui.popbuffer() deleted_list = re.findall('\'(.*)\'', deleted_str) # if there is a conflict, # we look at the list of files with conflicts # and display them, because merge3 will mark conflicting lines with special tags if conflict: repo.ui.pushbuffer() commands.resolve(repo.ui, repo, list=True) u_files_str = repo.ui.popbuffer() u_files_list = re.findall('U (.*)\n', u_files_str) if opts.get('check_file'): file = opts.get('check_file') if file in deleted_list: repo.ui.write( '\nfile ' + file + ' was deleted in other [merge rev] but was modified in local [working ' 'copy].\n') elif file in u_files_list: show_file_merge(repo, remote_clone_dir, file) else: repo.ui.write('\nFile ' + str(file) + ' does not cause conflict.\n' 'The conflict occurs in the following files:\n') show_all_conflicts(repo, u_files_list, deleted_list) else: show_all_conflicts(repo, u_files_list, deleted_list) repo.ui.write('\nYes, here is a conflict\n') # if there is no conflict, say it else: repo.ui.write('\nNo, everything cool\n') # go back to our work repo repo = hg.repository(repo.ui, cur_dir) # delete clones remove_clones(local_clone_dir, remote_clone_dir) sys.exit()
import os from mercurial import hg, ui, commands def get_repo_root(): path = os.path.dirname(os.path.realpath(__file__)) while os.path.exists(path): if '.hg' in os.listdir(path): return path path = os.path.realpath(os.path.join(path, '..')) raise RuntimeError('No .hg repository found!') ui = ui.ui() repo_path = get_repo_root() repo = hg.repository(ui, repo_path) ui.pushbuffer() commands.identify(ui, repo, rev='.') print ui.popbuffer().split()[0]