이 글에서는 'repo manifests' 명령에 대한 내용을 서술한다.

 

개요

업무시에 일정한 시점 사이동안 변경된 commit을 확인이 필요한 경우가 있다.

이 경우에는 두 시점의 manifest 파일을 생성하고, 이 둘 사이의 commit을 비교하면 된다.

회사에서 이러한 용도를 위해 작성된 Linux Shell Script를 사용하고 있는데, 조금 아쉽기는 했다.

다른 유틸리티를 찾다보니, repo 명령어에도 이러한 기능을 제공하는 명령어가 있었다.

 

$ repo help diffmanifests

Summary

Manifest diff utility

Usage: repo diffmanifests manifest1.xml [manifest2.xml] [options]

Options:
  -h, --help            show this help message and exit
  --raw                 Display raw diff.
  --no-color            does not display the diff in color.
  --pretty-format=<FORMAT>
                        print the log using a custom git pretty format string

Description

The repo diffmanifests command shows differences between project
revisions of manifest1 and manifest2. if manifest2 is not specified,
current manifest.xml will be used instead. Both absolute and relative
paths may be used for manifests. Relative paths start from project's
".repo/manifests" folder.

The --raw option Displays the diff in a way that facilitates parsing,
the project pattern will be <status> <path> <revision from> [<revision
to>] and the commit pattern will be <status> <onelined log> with status
values respectively :

  A = Added project
  R = Removed project
  C = Changed project
  U = Project with unreachable revision(s) (revision(s) not found)

for project, and

   A = Added commit
   R = Removed commit

for a commit.

Only changed projects may contain commits, and commit status always
starts with a space, and are part of last printed project. Unreachable
revisions may occur if project is not up to date or if repo has not been
initialized with all the groups, in which case some projects won't be
synced and their revisions won't be found.

 

사용법은 단순히 'repo diffmanifests <manifest 1> <manifest 2> <option>'을 사용하면 된다.

이 명령을 실행하면, <manifest 1>기준으로 <manifest 2>와의 변경된 commit을 보여준다.

만약 <manifest 2>를 생략하면, manifest.xml으로 대체된다. 즉, 현재 사용중인 maniefst와 비교한다.

 

실행화면

다음은 실제 실행 화면이다.

added projects는 두번째 manifest 파일에서 추가된 저장소이며,

changed projects는 변경된 저장소와 commit을 표시한다.

그런데, 나는 commit의 작성자 정보도 잘 사용하는 편이기 때문에, '--pretty-format' 옵션으로 작성자 정보도 추가해보았다.

 

 

기능 변경

그런데, diffmanifests 명령의 기준이 저장소 이름 (name)이 아니라 저장소 경로 (path)이다.

해당 코드를 살펴보면, 저장소 경로를 기준으로 정렬한 이후에 해당 저장소의 commit을 보여준다.

저장소 경로는 저장소의 unique한 식별자가 아니기 때문에, 나는 저장소 이름 기준으로 표시하도록 수정하였다.

 

관련된 코드 경로는 다음과 같다.

  • .repo/repo/manifest_xml.py
  • .repo/repo/subcmds/diffmanifests.py
$ git diff
diff --git a/subcmds/diffmanifests.py b/subcmds/diffmanifests.py
index b999699..f2269d3 100644
--- a/subcmds/diffmanifests.py
+++ b/subcmds/diffmanifests.py
@@ -79,21 +79,21 @@ synced and their revisions won't be found.

   def _printRawDiff(self, diff):
     for project in diff['added']:
-      self.printText("A %s %s" % (project.relpath, project.revisionExpr))
+      self.printText("A %s %s" % (project.name, project.revisionExpr))
       self.out.nl()

     for project in diff['removed']:
-      self.printText("R %s %s" % (project.relpath, project.revisionExpr))
+      self.printText("R %s %s" % (project.name, project.revisionExpr))
       self.out.nl()

     for project, otherProject in diff['changed']:
-      self.printText("C %s %s %s" % (project.relpath, project.revisionExpr,
+      self.printText("C %s %s %s" % (project.name, project.revisionExpr,
                                      otherProject.revisionExpr))
       self.out.nl()
       self._printLogs(project, otherProject, raw=True, color=False)

     for project, otherProject in diff['unreachable']:
-      self.printText("U %s %s %s" % (project.relpath, project.revisionExpr,
+      self.printText("U %s %s %s" % (project.name, project.revisionExpr,
                                      otherProject.revisionExpr))
       self.out.nl()

@@ -103,7 +103,7 @@ synced and their revisions won't be found.
       self.printText('added projects : \n')
       self.out.nl()
       for project in diff['added']:
-        self.printProject('\t%s' % (project.relpath))
+        self.printProject('\t%s' % (project.name))
         self.printText(' at revision ')
         self.printRevision(project.revisionExpr)
         self.out.nl()
@@ -113,7 +113,7 @@ synced and their revisions won't be found.
       self.printText('removed projects : \n')
       self.out.nl()
       for project in diff['removed']:
-        self.printProject('\t%s' % (project.relpath))
+        self.printProject('\t%s' % (project.name))
         self.printText(' at revision ')
         self.printRevision(project.revisionExpr)
         self.out.nl()
@@ -123,7 +123,7 @@ synced and their revisions won't be found.
       self.printText('changed projects : \n')
       self.out.nl()
       for project, otherProject in diff['changed']:
-        self.printProject('\t%s' % (project.relpath))
+        self.printProject('\t%s' % (project.name))
         self.printText(' changed from ')
         self.printRevision(project.revisionExpr)
         self.printText(' to ')
@@ -138,7 +138,7 @@ synced and their revisions won't be found.
       self.printText('projects with unreachable revisions : \n')
       self.out.nl()
       for project, otherProject in diff['unreachable']:
-        self.printProject('\t%s ' % (project.relpath))
+        self.printProject('\t%s ' % (project.name))
         self.printRevision(project.revisionExpr)
         self.printText(' or ')
         self.printRevision(otherProject.revisionExpr)

 

수정된 사항을 내용을 적용하여 다시 'repo manifests' 명령을 실행하였다.

vendor/....  경로로 표시되던 저장소가 projects/... 이름으로 표시됨을 알 수 있다.

 

+ Recent posts