Parse git log output into structured data.
(log_output)
| 13 | |
| 14 | |
| 15 | def parse_git_log(log_output): |
| 16 | """Parse git log output into structured data.""" |
| 17 | commits = [] |
| 18 | lines = log_output.strip().split("\n") |
| 19 | |
| 20 | for line in lines: |
| 21 | if "|" in line: |
| 22 | parts = line.split("|", 2) |
| 23 | if len(parts) >= 3: |
| 24 | commit_hash = parts[0] |
| 25 | date_str = parts[1] |
| 26 | message = parts[2] |
| 27 | |
| 28 | # Parse the date |
| 29 | try: |
| 30 | # Format: 2025-06-08 14:56:12 -0700 |
| 31 | dt = datetime.strptime(date_str.strip(), "%Y-%m-%d %H:%M:%S %z") |
| 32 | commits.append( |
| 33 | { |
| 34 | "hash": commit_hash, |
| 35 | "datetime": dt, |
| 36 | "message": message, |
| 37 | "date_str": date_str.strip(), |
| 38 | } |
| 39 | ) |
| 40 | except ValueError as e: |
| 41 | print(f"Error parsing date '{date_str}': {e}") |
| 42 | |
| 43 | # Sort by datetime (oldest first) |
| 44 | commits.sort(key=lambda x: x["datetime"]) |
| 45 | return commits |
| 46 | |
| 47 | |
| 48 | def calculate_programming_sessions(commits, max_gap_minutes=120): |