kriti21

Untitled

Apr 29th, 2018
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1.  
  2.         revert_shortlog_regex = re.compile('^Revert\s\"[\S+\s*]*\"')
  3.         headline_regex = re.compile(
  4.             '^This reverts commit [0-9a-f]{40}')
  5.         sha_regex = re.compile(r'\b[0-9a-f]{40}\b')
  6.         if not allow_revert_commits and revert_shortlog_regex.match(shortlog):
  7.  
  8.             reverted_shortlog = shortlog.lstrip('Revert ')
  9.  
  10.             if len(body) != 0:
  11.                 body = body.strip('\n')
  12.                 blankline = body.find('\n\n')
  13.                 headline = body[:blankline] if blankline != -1 else body
  14.  
  15.                 if headline_regex.match(headline):
  16.                     commit_sha = re.search(sha_regex, headline)
  17.                     commit_sha = commit_sha.group(0)
  18.                     command = 'git log -n 1 ' + str(commit_sha)
  19.                     rstdout, rstderr = run_shell_command(command)
  20.  
  21.                     if rstderr:
  22.                         self.err('git:', repr(stderr))
  23.                         yield Result(self, 'Invalid revert commit.')
  24.  
  25.                     rstdout = rstdout.rstrip('\n')
  26.                     rpos = rstdout.find('\n')
  27.                     old_shortlog = rstdout[:rpos] if rpos != -1 else rstdout
  28.  
  29.                     if old_shortlog != reverted_shortlog:
  30.                         yield Result(self, 'Shortlog of revert commit does \
  31.                                            not match the original commit.')
  32.  
  33.                 reason = body[blankline+1:] if blankline != -1 else ''
  34.  
  35.                 if len(reason) == 0:
  36.                     yield Result(self, 'Revert commit does not have a reason.')
  37.  
  38.                 elif len(reason) > 50:
  39.                     yield Result(self, 'Reason of revert commit contains too \
  40.                                        long lines.')
  41.  
  42.             else:
  43.                 yield Result(self, 'Revert commit does not have a reason.')
Add Comment
Please, Sign In to add comment