def getconfigs(wctx): """returns {name: [path]}. [path] under a same name are synced. name is not useful. """ # read from .hgdirsync in repo filename = ".hgdirsync" try: content = pycompat.decodeutf8(wctx[filename].data()) except (error.ManifestLookupError, IOError, AttributeError, KeyError): content = "" cfg = config.config() if content: cfg.parse(filename, "[dirsync]\n%s" % content, ["dirsync"]) maps = util.sortdict() repo = wctx.repo() for key, value in repo.ui.configitems("dirsync") + cfg.items("dirsync"): if "." not in key: continue name, disambig = key.split(".", 1) # Normalize paths to have / at the end. For easy concatenation later. if value[-1] != "/": value = value + "/" if name not in maps: maps[name] = [] maps[name].append(value) return maps
def __init__(self, ui, root, data): self._decode = {"LF": "to-lf", "CRLF": "to-crlf", "BIN": "is-binary"} self._encode = {"LF": "to-lf", "CRLF": "to-crlf", "BIN": "is-binary"} self.cfg = config.config() # Our files should not be touched. The pattern must be # inserted first override a '** = native' pattern. self.cfg.set("patterns", ".hg*", "BIN", "eol") # We can then parse the user's patterns. self.cfg.parse(".hgeol", data) isrepolf = self.cfg.get("repository", "native") != "CRLF" self._encode["NATIVE"] = isrepolf and "to-lf" or "to-crlf" iswdlf = ui.config("eol", "native") in ("LF", "\n") self._decode["NATIVE"] = iswdlf and "to-lf" or "to-crlf" include = [] exclude = [] self.patterns = [] for pattern, style in self.cfg.items("patterns"): key = style.upper() if key == "BIN": exclude.append(pattern) else: include.append(pattern) m = match.match(root, "", [pattern]) self.patterns.append((pattern, key, m)) # This will match the files for which we need to care # about inconsistent newlines. self.match = match.match(root, "", [], include, exclude)
def _get(repo, name): """Read commitcloudrc file to get a value""" if repo.svfs.exists(filename): with repo.svfs.open(filename, r"rb") as f: cloudconfig = config.config() cloudconfig.read(filename, f) return cloudconfig.get("commitcloud", name) else: return None
def _gettokenfromfile(self): """On platforms except macOS tokens are stored in a file""" if not self.vfs.exists(self.filename): return None with self.vfs.open(self.filename, r"rb") as f: tokenconfig = config.config() tokenconfig.read(self.filename, f) token = tokenconfig.get("commitcloud", "user_token") return token
def _get(repo, *names): """Read commitcloudrc file to get a value""" if repo.svfs.exists(filename): with repo.svfs.open(filename, r"rb") as f: cloudconfig = config.config() cloudconfig.read(filename, f) return (cloudconfig.get( "commitcloud", names[0]) if len(names) == 1 else tuple( cloudconfig.get("commitcloud", name) for name in names)) else: return None if len(names) == 1 else tuple(None for name in names)
def parsegitmodules(self, content): """Parse the formatted .gitmodules file, example file format: [submodule "sub"]\n \tpath = sub\n \turl = git://giturl\n """ self.submodules = [] c = config.config() # Each item in .gitmodules starts with whitespace that cant be parsed content = decodeutf8(content) c.parse(".gitmodules", "\n".join(line.strip() for line in content.split("\n"))) for sec in c.sections(): s = c[sec] if "url" in s and "path" in s: self.submodules.append(submodule(s["path"], "", s["url"]))
def getconfigs(repo): # read from wvfs/.hgdirsync filename = ".hgdirsync" content = repo.wvfs.tryreadutf8(filename) cfg = config.config() if content: cfg.parse(filename, "[dirsync]\n%s" % content, ["dirsync"]) maps = util.sortdict() for key, value in repo.ui.configitems("dirsync") + cfg.items("dirsync"): if "." not in key: continue name, disambig = key.split(".", 1) # Normalize paths to have / at the end. For easy concatenation later. if value[-1] != "/": value = value + "/" if name not in maps: maps[name] = [] maps[name].append(value) return maps
def _gettokenfromfile(self): """On platforms except macOS tokens are stored in a file""" if not self.vfs.exists(self.filename): if self.usesecretstool: # check if token has been backed up and recover it if possible try: token = self._gettokenfromsecretstool() if token: self._settokentofile(token, isbackedup=True) return token except Exception: pass return None with self.vfs.open(self.filename, r"rb") as f: tokenconfig = config.config() tokenconfig.read(self.filename, f) token = tokenconfig.get("commitcloud", "user_token") if self.usesecretstool: isbackedup = tokenconfig.get("commitcloud", "backedup") if not isbackedup: self._settokentofile(token) return token