factory_diff: Add option to only show commits on factory branch

When we want to merge factory branch back to master, this can be very
handy.

BUG=chrome-os-partner:18833
TEST=Run with '-o' and check only factory branch commits are shown.

Change-Id: I7d11b3688b74e31313b45e3f0912432da2c9085c
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/48748
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
diff --git a/py/tools/factory_diff.py b/py/tools/factory_diff.py
index 717a46c..15bf5e4 100755
--- a/py/tools/factory_diff.py
+++ b/py/tools/factory_diff.py
@@ -129,7 +129,7 @@
           not in cherrypicked]
 
 
-def DiffRepo(repo_path, branch, author):
+def DiffRepo(repo_path, branch, author, branch_only):
   print '%s*** Diff %s ***%s' % (COLOR_GREEN, repo_path, COLOR_RESET)
   os.chdir(GetFullRepoPath(repo_path))
   prefix = FindGitPrefix(repo_path)
@@ -147,6 +147,8 @@
   # To make [Master] stands out, we only show [------] for commits that
   # are in factory branch.
   for entry in diff_list:
+    if branch_only and entry.left_right == '<':
+      continue
     print '%s%s %s%s %s %s(%s)%s' % (COLOR_YELLOW,
                                      '[Master]' if entry.left_right == '<'
                                      else '[------]',
@@ -170,6 +172,8 @@
                       help='board name')
   parser.add_argument('--author', '-a', default=None,
                       help='Limit the output to this author only')
+  parser.add_argument('--factory_only', '-o', action='store_true',
+                      help='Only show commits on factory branch')
   args = parser.parse_args()
   if not args.branch:
     args.branch = GetBranch(args.board)
@@ -182,7 +186,7 @@
     REPO_LIST.append(GetPrivateOverlay(args.board))
 
   for repo in REPO_LIST:
-    DiffRepo(repo, args.branch, args.author)
+    DiffRepo(repo, args.branch, args.author, args.factory_only)
   sys.exit(0)
 
 if __name__ == '__main__':