Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: appengine/findit/lib/gitiles/repo_util.py

Issue 2432113002: [Findit] Add local_git_repository (Closed)
Patch Set: Rebase. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json
6 import logging
5 import re 7 import re
8 import subprocess
9 import urllib2
6 10
7 CODE_REVIEW_URL_PATTERN = re.compile( 11 CODE_REVIEW_URL_PATTERN = re.compile(
8 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE) 12 '^(?:Review URL|Review-Url): (.*\d+).*$', re.IGNORECASE)
9 COMMIT_POSITION_PATTERN = re.compile( 13 COMMIT_POSITION_PATTERN = re.compile(
10 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE) 14 '^Cr-Commit-Position: refs/heads/master@{#(\d+)}$', re.IGNORECASE)
11 REVERTED_REVISION_PATTERN = re.compile( 15 REVERTED_REVISION_PATTERN = re.compile(
12 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE) 16 '^> Committed: https://.+/([0-9a-fA-F]{40})$', re.IGNORECASE)
13 START_OF_CR_COMMIT_POSITION = -5 17 START_OF_CR_COMMIT_POSITION = -5
14 18
15 19
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 """Parse message to get the reverted revision if there is one.""" 66 """Parse message to get the reverted revision if there is one."""
63 lines = message.strip().splitlines() 67 lines = message.strip().splitlines()
64 if not lines[0].lower().startswith('revert'): 68 if not lines[0].lower().startswith('revert'):
65 return None 69 return None
66 70
67 for line in reversed(lines): # pragma: no cover 71 for line in reversed(lines): # pragma: no cover
68 # TODO: Handle cases where no reverted_revision in reverting message. 72 # TODO: Handle cases where no reverted_revision in reverting message.
69 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line) 73 reverted_revision_match = REVERTED_REVISION_PATTERN.match(line)
70 if reverted_revision_match: 74 if reverted_revision_match:
71 return reverted_revision_match.group(1) 75 return reverted_revision_match.group(1)
76
77
78 # TODO(katesonia): Add local cache for this function.
79 def GetCommandOutput(command):
80 """Gets the output stream of executable command.
81
82 Args:
83 command (str): Command to execute to get output.
84
85 Return:
86 Output steam of the command.
87 """
88 p = subprocess.Popen(
89 command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
90 stdoutdata, stderrdata = p.communicate()
91
92 if p.returncode != 0:
93 logging.error('Error running command %s: %s', command, stderrdata)
94 return None
wrengr 2016/11/01 20:26:53 You probably want to throw an exception packaging
Sharu Jiang 2016/11/05 01:18:15 Crashing the program working for local testing, bu
95
96 return stdoutdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698