@ -140,7 +140,7 @@ def UploadCl(refactor_branch, refactor_branch_upstream, directory, files,
publish = True )
publish = True )
def GetFilesSplitByOwners ( files ):
def GetFilesSplitByOwners ( files , max_depth ):
""" Returns a map of files split by OWNERS file.
""" Returns a map of files split by OWNERS file.
Returns :
Returns :
@ -149,7 +149,13 @@ def GetFilesSplitByOwners(files):
"""
"""
files_split_by_owners = { }
files_split_by_owners = { }
for action , path in files :
for action , path in files :
dir_with_owners = os . path . dirname ( path )
# normpath() is important to normalize separators here, in prepration for
# str.split() before. It would be nicer to use something like pathlib here
# but alas...
dir_with_owners = os . path . normpath ( os . path . dirname ( path ) )
if max_depth > = 1 :
dir_with_owners = os . path . join (
* dir_with_owners . split ( os . path . sep ) [ : max_depth ] )
# Find the closest parent directory with an OWNERS file.
# Find the closest parent directory with an OWNERS file.
while ( dir_with_owners not in files_split_by_owners
while ( dir_with_owners not in files_split_by_owners
and not os . path . isfile ( os . path . join ( dir_with_owners , ' OWNERS ' ) ) ) :
and not os . path . isfile ( os . path . join ( dir_with_owners , ' OWNERS ' ) ) ) :
@ -184,7 +190,7 @@ def PrintClInfo(cl_index, num_cls, directory, file_paths, description,
def SplitCl ( description_file , comment_file , changelist , cmd_upload , dry_run ,
def SplitCl ( description_file , comment_file , changelist , cmd_upload , dry_run ,
cq_dry_run , enable_auto_submit , repository_root) :
cq_dry_run , enable_auto_submit , max_depth, repository_root) :
""" " Splits a branch into smaller branches and uploads CLs.
""" " Splits a branch into smaller branches and uploads CLs.
Args :
Args :
@ -195,6 +201,8 @@ def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
dry_run : Whether this is a dry run ( no branches or CLs created ) .
dry_run : Whether this is a dry run ( no branches or CLs created ) .
cq_dry_run : If CL uploads should also do a cq dry run .
cq_dry_run : If CL uploads should also do a cq dry run .
enable_auto_submit : If CL uploads should also enable auto submit .
enable_auto_submit : If CL uploads should also enable auto submit .
max_depth : The maximum directory depth to search for OWNERS files . A value
less than 1 means no limit .
Returns :
Returns :
0 in case of success . 1 in case of error .
0 in case of success . 1 in case of error .
@ -224,7 +232,7 @@ def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
assert refactor_branch_upstream , \
assert refactor_branch_upstream , \
" Branch %s must have an upstream. " % refactor_branch
" Branch %s must have an upstream. " % refactor_branch
files_split_by_owners = GetFilesSplitByOwners ( files )
files_split_by_owners = GetFilesSplitByOwners ( files , max_depth )
num_cls = len ( files_split_by_owners )
num_cls = len ( files_split_by_owners )
print ( ' Will split current branch ( ' + refactor_branch + ' ) into ' +
print ( ' Will split current branch ( ' + refactor_branch + ' ) into ' +