Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ensure_dependencies.py

Issue 5934936779390976: 1377 - Blacklist dependencies from SCM tracking (Closed)
Patch Set: 1377 - Blacklist dependencies from Mercurial and Git tracking Created Sept. 28, 2014, 12:23 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ensure_dependencies.py
===================================================================
--- a/ensure_dependencies.py
+++ b/ensure_dependencies.py
@@ -25,7 +25,9 @@
import logging
import subprocess
import urlparse
+
from collections import OrderedDict
+from ConfigParser import RawConfigParser
USAGE = """
A dependencies file should look like this:
@@ -42,7 +44,20 @@
buildtools = buildtools hg:016d16f7137b git:f3f8692f82e5
"""
-class Mercurial():
+class SCM(object):
+ def _ignore(self, target, file_name):
Wladimir Palant 2014/10/07 22:30:14 That should simply be a helper function _ensure_li
aalvz 2014/10/08 13:49:18 Done.
Wladimir Palant 2014/10/08 21:40:30 And the same file format? That's merely a coincide
+ with open(file_name, 'a+') as f:
+ file_content = [l.strip() for l in f.readlines()]
+ if not target in file_content:
+ if len(file_content):
+ f.seek(-1, os.SEEK_CUR)
+ last_character = f.read(1)
+ if not last_character in "\r\n":
Wladimir Palant 2014/10/07 22:30:14 No need to overcomplicate this: file_content.appe
aalvz 2014/10/08 13:49:18 I think the solution you are suggesting and the cu
mathias 2014/10/08 17:37:55 While the first point is not really true (though i
+ f.write(os.linesep)
+ f.write(target)
+ f.write(os.linesep)
+
+class Mercurial(SCM):
def istype(self, repodir):
return os.path.exists(os.path.join(repodir, ".hg"))
@@ -67,7 +82,30 @@
def update(self, repo, rev):
subprocess.check_call(["hg", "update", "--repository", repo, "--quiet", "--check", "--rev", rev])
-class Git():
+ def ignore(self, target, repo):
+
+ if not self.istype(target):
+
+ config_path = os.path.join(repo, ".hg", "hgrc")
+ ignore_path = os.path.join(".", ".hg", "dependencies")
+
+ config = RawConfigParser()
+ config.read(config_path)
+
+ if not config.has_section("ui"):
+ config.add_section("ui")
+
+ if not config.has_option("ui", "ignore.dependencies"):
+ config.set("ui", "ignore.dependencies", ignore_path)
+ with open(config_path, "w") as stream:
+ config.write(stream)
+ else:
+ ignore_path = config.get("ui", "ignore.dependencies")
Wladimir Palant 2014/10/07 22:30:14 Please set that option regardless of whether it is
mathias 2014/10/08 16:32:11 Agreed, this is necessary due to the issue above,
+
+ module = os.path.relpath(target, repo)
+ self._ignore(module, ignore_path)
+
+class Git(SCM):
def istype(self, repodir):
return os.path.exists(os.path.join(repodir, ".git"))
@@ -87,6 +125,11 @@
def update(self, repo, rev):
subprocess.check_call(["git", "checkout", "--quiet", rev], cwd=repo)
+ def ignore(self, target, repo):
+ module = os.path.relpath(target, repo)
+ exclude_file = os.path.join(repo, ".git", "info", "exclude")
+ self._ignore(module, exclude_file)
+
repo_types = {
"hg": Mercurial(),
"git": Git(),
@@ -161,7 +204,6 @@
def ensure_repo(parentrepo, target, roots, sourcename):
if os.path.exists(target):
return
-
parenttype = get_repo_type(parentrepo)
type = None
for key in roots:
@@ -174,6 +216,10 @@
logging.info("Cloning repository %s into %s" % (url, target))
repo_types[type].clone(url, target)
+ for repo in repo_types.itervalues():
+ if repo.istype(parentrepo):
+ repo.ignore(target, parentrepo)
+
def update_repo(target, revisions):
type = get_repo_type(target)
if type is None:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld