Get git log data and parse into structured format.
()
| 13 | |
| 14 | |
| 15 | def parse_git_log(): |
| 16 | """Get git log data and parse into structured format.""" |
| 17 | try: |
| 18 | result = subprocess.run( |
| 19 | ["git", "log", "--pretty=format:%H|%ad|%s", "--date=iso", "--all"], |
| 20 | capture_output=True, |
| 21 | text=True, |
| 22 | cwd=".", |
| 23 | ) |
| 24 | |
| 25 | if result.returncode != 0: |
| 26 | print("Error running git log command") |
| 27 | return [] |
| 28 | |
| 29 | commits = [] |
| 30 | lines = result.stdout.strip().split("\n") |
| 31 | |
| 32 | for line in lines: |
| 33 | if "|" in line: |
| 34 | parts = line.split("|", 2) |
| 35 | if len(parts) >= 3: |
| 36 | commit_hash = parts[0] |
| 37 | date_str = parts[1].strip() |
| 38 | message = parts[2] |
| 39 | |
| 40 | try: |
| 41 | dt = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S %z") |
| 42 | commits.append( |
| 43 | { |
| 44 | "hash": commit_hash, |
| 45 | "datetime": dt, |
| 46 | "message": message, |
| 47 | "date_str": date_str, |
| 48 | } |
| 49 | ) |
| 50 | except ValueError as e: |
| 51 | print(f"Error parsing date '{date_str}': {e}") |
| 52 | |
| 53 | commits.sort(key=lambda x: x["datetime"]) |
| 54 | return commits |
| 55 | |
| 56 | except Exception as e: |
| 57 | print(f"Error getting git log: {e}") |
| 58 | return [] |
| 59 | |
| 60 | |
| 61 | def calculate_programming_sessions(commits, max_gap_minutes=120): |