• repo status过滤项目


    repo status命令过滤没有任何改动的仓库

    repo status命令正常的输出包含了所有仓库的状态信息,如果仓库数量很多的情况下,会打印大量无用信息。比如安卓源码项目AOSP,repo工具可能需要管理上百个git仓库,此时直接输入repo status命令,得到的结果几乎全部是空状态信息,如下 :

    1. project art/ X9_3.0.0_PTG4.0
    2. project bionic/ X9_3.0.0_PTG4.0
    3. project bootable/recovery/ X9_3.0.0_PTG4.0
    4. project build/blueprint/ X9_3.0.0_PTG4.0
    5. project build/kati/ X9_3.0.0_PTG4.0
    6. project build/make/ X9_3.0.0_PTG4.0
    7. project build/soong/ X9_3.0.0_PTG4.0
    8. project cts/ X9_3.0.0_PTG4.0
    9. project dalvik/ X9_3.0.0_PTG4.0
    10. project developers/build/ X9_3.0.0_PTG4.0
    11. project developers/demos/ X9_3.0.0_PTG4.0
    12. project developers/samples/android/ X9_3.0.0_PTG4.0
    13. project development/ X9_3.0.0_PTG4.0
    14. project device/amlogic/yukawa/ X9_3.0.0_PTG4.0
    15. project device/amlogic/yukawa-kernel/ X9_3.0.0_PTG4.0
    16. project device/common/ X9_3.0.0_PTG4.0
    17. project device/generic/arm64/ X9_3.0.0_PTG4.0
    18. project device/generic/armv7-a-neon/ X9_3.0.0_PTG4.0
    19. project device/generic/car/ X9_3.0.0_PTG4.0
    20. project device/generic/common/ X9_3.0.0_PTG4.0
    21. project device/generic/goldfish/ X9_3.0.0_PTG4.0
    22. project device/generic/goldfish-opengl/ X9_3.0.0_PTG4.0

    打印仓库状态的函数是PrintWorkTreeStatus,代码路径是.repo/repo/project.py

    相关代码修改后如下:

    1. def PrintWorkTreeStatus(self, output_redir=None, quiet=False):
    2. """Prints the status of the repository to stdout.
    3. Args:
    4. output_redir: If specified, redirect the output to this object.
    5. quiet: If True then only print the project name. Do not print
    6. the modified files, branch name, etc.
    7. """
    8. if not platform_utils.isdir(self.worktree):
    9. if output_redir is None:
    10. output_redir = sys.stdout
    11. print(file=output_redir)
    12. print('project %s/' % self.relpath, file=output_redir)
    13. print(' missing (run "repo sync")', file=output_redir)
    14. return
    15. self.work_git.update_index('-q',
    16. '--unmerged',
    17. '--ignore-missing',
    18. '--refresh')
    19. rb = self.IsRebaseInProgress()
    20. di = self.work_git.DiffZ('diff-index', '-M', '--cached', HEAD)
    21. df = self.work_git.DiffZ('diff-files')
    22. do = self.work_git.LsOthers()
    23. if not rb and not di and not df and not do and not self.CurrentBranch:
    24. return 'CLEAN'
    25. out = StatusColoring(self.config)
    26. if output_redir is not None:
    27. out.redirect(output_redir)
    28. """
    29. out.project('project %-40s', self.relpath + '/ ')
    30. if quiet:
    31. out.nl()
    32. return 'DIRTY'
    33. branch = self.CurrentBranch
    34. if branch is None:
    35. out.nobranch('(*** NO BRANCH ***)')
    36. else:
    37. out.branch('branch %s', branch)
    38. out.nl()
    39. """
    40. branch = self.CurrentBranch
    41. if rb:
    42. out.important('prior sync failed; rebase still in progress')
    43. out.nl()
    44. paths = list()
    45. paths.extend(di.keys())
    46. paths.extend(df.keys())
    47. paths.extend(do)
    48. if paths != []:
    49. out.nl()
    50. out.project('project %-40s', self.relpath + '/')
    51. if branch is None:
    52. out.branch('(*** NO BRANCH ***)')
    53. else:
    54. out.branch('%s', branch)
    55. out.nl()
    56. for p in sorted(set(paths)):
    57. try:
    58. i = di[p]
    59. except KeyError:
    60. i = None
    61. try:
    62. f = df[p]
    63. except KeyError:
    64. f = None
    65. if i:
    66. i_status = i.status.upper()
    67. else:
    68. i_status = '-'
    69. if f:
    70. f_status = f.status.lower()
    71. else:
    72. f_status = '-'
    73. if i and i.src_path:
    74. line = ' %s%s\t%s => %s (%s%%)' % (i_status, f_status,
    75. i.src_path, p, i.level)
    76. else:
    77. line = ' %s%s\t%s' % (i_status, f_status, p)
    78. if i and not f:
    79. out.added('%s', line)
    80. elif (i and f) or (not i and f):
    81. out.changed('%s', line)
    82. elif not i and not f:
    83. out.untracked('%s', line)
    84. else:
    85. out.write('%s', line)
    86. out.nl()
    87. return 'DIRTY'

    修改说明:

    1.通过三引号注释原有的输出内容

    2.对上述输出内容进行判断

  • 相关阅读:
    Android通知怎么实现?Android开发如何操作相机和相册?
    请输入一个整数
    java毕业设计电影院售票系统Mybatis+系统+数据库+调试部署
    神经网络常用的训练方式,神经网络是怎么训练的
    Spring常用注解(2)
    docker报错standard init linux.go:228 exec user process caused: exec format error
    MySQL中索引的基本知识
    2-Dubbo架构设计与底层原理-SPI源码分析
    神经网络模型的基本原理,神经网络模型结构图
    Css的flex布局(弹性盒子)详解
  • 原文地址:https://blog.csdn.net/hhdsyxwei/article/details/125536982