repo sync下载代码时经常 fatal: read error: Connection reset by peer
可能是向同一个repo url连接数过多引起的吧
此补丁增加了 repo sync --ignore-list选项, 配合repo sync -j1 使用,可以在失败后不再重新同步已经同步过的工程,能缓解出错的情况
diff --git a/project.py b/project.py
index 22e4a5d..f2e7ccc 100644
--- a/project.py
+++ b/project.py
@@ -490,7 +490,8 @@ class Project(object):
sync_s = False,
upstream = None,
parent = None,
- is_derived = False):
+ is_derived = False,
+ is_ignored = False):
"""Init a Project object.
Args:
@@ -536,6 +537,7 @@ class Project(object):
self.upstream = upstream
self.parent = parent
self.is_derived = is_derived
+ self.is_ignored = is_ignored
self.subprojects = []
self.snapshots = {}
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 9ed84b9..d3639b1 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -192,6 +192,10 @@ later is required to fix a server side protocol bug.
p.add_option('--no-tags',
dest='no_tags', action='store_true',
help="don't fetch tags")
+ p.add_option('--ignore-list',
+ dest='ignore_list', action='store_true',
+ help="don't fetch projects in ignore-list")
+
if show_smart:
p.add_option('-s', '--smart-sync',
dest='smart_sync', action='store_true',
@@ -267,12 +271,30 @@ later is required to fix a server side protocol bug.
lock.release()
sem.release()
+ def Append_ignore_projects(self,name):
+ file_name = 'project.ignore'
+ file_path = os.path.join(self.manifest.repodir, file_name)
+
+ #if os.path.exists(file_path):
+ fd = open(file_path, 'a')
+ try:
+ print(name, file=fd)
+ finally:
+ fd.close()
+
def _Fetch(self, projects, opt):
fetched = set()
pm = Progress('Fetching projects', len(projects))
if self.jobs == 1:
for project in projects:
+ if project.is_ignored:
+ print("Ignore project={0}".format(project.name))
+ pm.update()
+ fetched.add(project.gitdir)
+ continue
+
+ print("Fetching project={0}".format(project.name))
pm.update()
if project.Sync_NetworkHalf(
quiet=opt.quiet,
@@ -280,6 +302,9 @@ later is required to fix a server side protocol bug.
clone_bundle=not opt.no_clone_bundle,
no_tags=opt.no_tags):
fetched.add(project.gitdir)
+ print("\nFetchDone: {0}".format(project.name))
+ if opt.ignore_list:
+ self.Append_ignore_projects(project.relpath)
else:
print('error: Cannot fetch %s' % project.name, file=sys.stderr)
if opt.force_broken:
@@ -379,6 +404,18 @@ later is required to fix a server side protocol bug.
else:
self.manifest._Unload()
+ def GetIgnoreProjectsName(self):
+ file_name = 'project.ignore'
+ file_path = os.path.join(self.manifest.repodir, file_name)
+ project_names = 0
+ if os.path.exists(file_path):
+ fd = open(file_path, 'r')
+ try:
+ project_names = fd.read().split('\n')
+ finally:
+ fd.close()
+ return project_names
+
def UpdateProjectList(self):
new_project_paths = []
for project in self.GetProjects(None, missing_ok=True):
@@ -585,6 +622,20 @@ later is required to fix a server side protocol bug.
missing_ok=True,
submodules_ok=opt.fetch_submodules)
+ if opt.ignore_list:
+ ignore_projects_name = self.GetIgnoreProjectsName()
+ #print(ignore_projects_name)
+ #for i in all_projects:
+ # print(i.name)
+ #sys.exit(1)
+ if ignore_projects_name:
+ temp_projects = []
+ for i in all_projects:
+ if i.relpath in ignore_projects_name:
+ i.is_ignored = True
+ temp_projects.append(i)
+ all_projects = temp_projects
+
self._fetch_times = _FetchTimes(self.manifest)
if not opt.local_only:
to_fetch = []