This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 0.6: * Unset upstream support. * Better wrapping of git log. * Apply patch suppport. * Return number of additions and deletions in diff. * Bug fixes and code cleanups.
- Loading branch information
Showing
14 changed files
with
197 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# gitpylib - a Python library for Git. | ||
# Licensed under GNU GPL v2. | ||
|
||
|
||
from . import common | ||
|
||
|
||
def on_index(patch_file): | ||
ok, _, _ = common.git_call('apply --cached {0}'.format(patch_file)) | ||
return ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,81 @@ | ||
# gitpylib - a Python library for Git. | ||
# Copyright (c) 2013 Santiago Perez De Rosso. | ||
# Licensed under GNU GPL, version 2. | ||
# Licensed under GNU GPL v2. | ||
|
||
|
||
import subprocess | ||
import collections | ||
import re | ||
|
||
from . import common | ||
from . import file as git_file | ||
|
||
def log(): | ||
# The pipe to less shouldn't be here. TODO: fix. | ||
subprocess.call('git log | less', shell=True) | ||
|
||
# TODO: add more info like parents, tree, committer, etc. | ||
Commit = collections.namedtuple( | ||
'Commit', ['id', 'author', 'msg', 'diffs']) | ||
|
||
def log_p(): | ||
# The pipe to less shouldn't be here. TODO: fix. | ||
subprocess.call('git log -p | less', shell=True) | ||
CommitAuthor = collections.namedtuple( | ||
'CommitAuthor', ['name', 'email', 'date', 'date_relative']) | ||
|
||
CommitDiff = collections.namedtuple( | ||
'CommitDiff', ['fp_before', 'fp_after', 'diff']) | ||
|
||
def log(include_diffs=False): | ||
log_fmt = r'[[%H] [%an] [%ae] [%aD] [%ar]]%n%B' | ||
out, _ = common.safe_git_call( | ||
'log --format=format:"{0}" {1}'.format( | ||
log_fmt, '-p' if include_diffs else '')) | ||
return _parse_log_output(out) | ||
|
||
|
||
def _parse_log_output(out): | ||
def _create_ci(m, msg, diffs): | ||
processed_diffs = [] | ||
for diff in diffs: | ||
fp_before, fp_after = re.match( | ||
'diff --git a/(.*) b/(.*)', diff[0]).group(1, 2) | ||
processed_diffs.append( | ||
CommitDiff( | ||
fp_before, fp_after, | ||
git_file._process_diff_output(git_file._split_diff(diff)[1]))) | ||
return Commit( | ||
m.group(1), CommitAuthor(*m.group(2, 3, 4, 5)), '\n'.join(msg), | ||
processed_diffs) | ||
|
||
if not out: | ||
return [] | ||
|
||
pattern = re.compile(r'\[\[(.*)\] \[(.*)\] \[(.*)\] \[(.*)\] \[(.*)\]\]') | ||
out_it = iter(out.splitlines()) | ||
m = None | ||
msg = None | ||
diffs = [] | ||
curr_diff = None | ||
ret = [] | ||
try: | ||
line = next(out_it) | ||
while True: | ||
m = re.match(pattern, line) | ||
if not m: | ||
raise common.UnexpectedOutputError('log', line) | ||
line = next(out_it) | ||
msg = [] | ||
while not line.startswith('diff --git') and not line.startswith('[['): | ||
msg.append(line) | ||
line = next(out_it) | ||
diffs = [] | ||
curr_diff = [] | ||
while not line.startswith('[['): | ||
curr_diff.append(line) | ||
line = next(out_it) | ||
while not line.startswith('diff --git') and not line.startswith('[['): | ||
curr_diff.append(line) | ||
line = next(out_it) | ||
diffs.append(curr_diff) | ||
curr_diff = [] | ||
|
||
ret.append(_create_ci(m, msg, diffs)) | ||
except StopIteration: | ||
if curr_diff: | ||
diffs.append(curr_diff) | ||
ret.append(_create_ci(m, msg, diffs)) | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.