def split_targets_into_scm_root(targets, working_dir): '''Split all targets by scm root dirs''' scm_root_dirs = {} # scm_root_dir : (scm_type, target_dirs) checked_dir = set() scms = ('svn', 'git') for target in targets: target_dir = target.split(':')[0] if target_dir in checked_dir: continue checked_dir.add(target_dir) # Only check targets under working dir if not _target_in_dir(target_dir, working_dir): continue for scm in scms: scm_root = find_scm_root(target_dir, scm) if scm_root: rel_target_dir = os.path.relpath(target_dir, scm_root) if scm_root in scm_root_dirs: scm_root_dirs[scm_root][1].append(rel_target_dir) else: scm_root_dirs[scm_root] = (scm, [rel_target_dir]) return scm_root_dirs