Skip to content

Commit

Permalink
Merge branch 'fix-stats-pattern-git' of 'https://github.com/sduenas/p…
Browse files Browse the repository at this point in the history
…erceval'

Merges #852 
Closes #852
  • Loading branch information
jjmerchante authored Dec 3, 2024
2 parents 8c1aadf + fa3d0a6 commit f16b29d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions perceval/backends/core/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Git(Backend):
:raises RepositoryError: raised when there was an error cloning or
updating the repository.
"""
version = '1.0.0'
version = '1.0.1'

CATEGORIES = [CATEGORY_COMMIT]

Expand Down Expand Up @@ -567,7 +567,7 @@ class GitParser:
(?P<file>[^\t]+)
(?:\t+(?P<newfile>.+))?$"""

STATS_PATTERN = r"^(?P<added>\d+|-)[ \t]+(?P<removed>\d+|-)[ \t]+(?P<file>.+)$"
STATS_PATTERN = r"^(?P<added>\d+|-)\t+(?P<removed>\d+|-)\t+(?P<file>.+)$"

EMPTY_LINE_PATTERN = r"^$"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Git stats not assigned with their actions
category: fixed
author: Santiago Dueñas <[email protected]>
issue: null
notes: >
Git stats were not assigned to their actions in
a commit for filenames that contain whitespaces.
Instead, an empty stat was created like in a
merge commit, where actions normally don't take
place.
6 changes: 3 additions & 3 deletions tests/data/git/git_log_merge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ CommitDate: Tue Aug 2 19:47:06 2016 -0400

Merge tag 'for-linus-v4.8' of git://github.com/martinbrandenburg/linux

46 4 Documentation/filesystems/orangefs.txt
4 0 fs/orangefs/dcache.c
3 3 fs/orangefs/inode.c
46 4 Documentation/filesystems/orangefs.txt
4 0 fs/orangefs/dcache.c
3 3 fs/orangefs/inode.c

commit 456a68ee1407a77f3e804a30dff245bb6c6b872f ce8e0b86a1e9877f42fe9453ede418519115f367 51a3b654f252210572297f47597b31527c475fb8 (HEAD -> refs/heads/master)
Merge: ce8e0b8 51a3b65
Expand Down
13 changes: 13 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,19 @@ def test_stats_pattern(self):
self.assertEqual(m.group('removed'), "0")
self.assertEqual(m.group('file'), "bbb/{something => something.renamed}")

# Test with files that have whitespaces
s = "5\t0\t afile.txt"
m = pattern.match(s)
self.assertEqual(m.group('added'), "5")
self.assertEqual(m.group('removed'), "0")
self.assertEqual(m.group('file'), " afile.txt")

s = "5\t0\ta fi le.txt"
m = pattern.match(s)
self.assertEqual(m.group('added'), "5")
self.assertEqual(m.group('removed'), "0")
self.assertEqual(m.group('file'), "a fi le.txt")

def test_empty_line(self):
"""Test empty line pattern"""

Expand Down

0 comments on commit f16b29d

Please sign in to comment.