|
1 | | - |
2 | 1 | # RepoDiff |
3 | 2 |
|
4 | | -**RepoDiff** is a tool designed to simplify code reviews by generating dynamic git diffs between two commits or branches. It allows you to configure diff options based on file paths, optimizing the output for consumption by large language models (LLMs). |
| 3 | +**RepoDiff** is a tool designed to simplify code reviews by generating dynamic git diffs between two commits or branches. It optimizes diffs for analysis by large language models (LLMs) with features like context line adjustment and method body removal. |
5 | 4 |
|
6 | 5 | ## Features |
7 | 6 |
|
8 | | -- Generate diffs between two commits or branches with customizable options. |
9 | | -- Supports customized diff options depending on file type. |
10 | | -- Combines diffs into a single file. |
11 | | -- Calculates token counts for estimating the query cost for LLMs. |
| 7 | +- Generate diffs between two commits or branches with a single pass |
| 8 | +- Configurable file pattern matching for different file types |
| 9 | +- Smart method body removal for C# files to improve readability |
| 10 | +- Adjustable context lines per file pattern |
| 11 | +- Token counting for estimating LLM query costs |
| 12 | +- Combines all changes into a single, well-formatted output |
12 | 13 |
|
13 | | -## Usage |
| 14 | +## Installation |
14 | 15 |
|
15 | | -You can either provide commit hashes to compare directly, or use the -b option to compare the latest commit in the current branch with the latest common commit in another branch (e.g., `master`). You can also specify an output file, or let the script default to the system's temporary directory if no output file is provided. |
| 16 | +### Option 1: Download the Executable |
16 | 17 |
|
17 | | -### Compare Latest Commit with Another Branch |
| 18 | +1. Go to the [Releases](https://github.com/EntityProcess/RepoDiff/releases) page. |
| 19 | +2. Download the latest version of the `repodiff.exe` executable. |
| 20 | +3. Move the `repodiff.exe` file to a directory included in your system's `PATH`. |
| 21 | + |
| 22 | +### Option 2: Install from Source |
18 | 23 |
|
19 | | -To compare the latest commit in the current branch with the latest common commit in another branch (e.g., `master`), use the `-b` option: |
20 | 24 | ```bash |
21 | | -repodiff -b <branch> [-o /path/to/output_file.txt] |
| 25 | +git clone https://github.com/EntityProcess/RepoDiff.git |
| 26 | +cd RepoDiff |
| 27 | +pip install -e . |
22 | 28 | ``` |
23 | 29 |
|
24 | | -**Example:** |
25 | | -Compare the latest commit in the current branch with the latest common commit in master, and write the result to a default file in the system's temporary directory |
| 30 | +### Option 3: Build the Executable Yourself |
| 31 | + |
| 32 | +Clone the repository and navigate to the directory: |
26 | 33 |
|
27 | 34 | ```bash |
28 | | -repodiff -b master |
| 35 | +git clone https://github.com/EntityProcess/RepoDiff.git |
| 36 | +cd RepoDiff |
29 | 37 | ``` |
30 | 38 |
|
31 | | -### Compare Two Commits |
| 39 | +Install PyInstaller and build the executable: |
32 | 40 |
|
33 | 41 | ```bash |
34 | | -repodiff -c1 <commit1> -c2 <commit2> [-o /path/to/output_file.txt] |
| 42 | +pip install pyinstaller |
| 43 | +# On Windows, run: |
| 44 | +build.bat |
35 | 45 | ``` |
36 | 46 |
|
37 | | -* `-c1`, `--commit1`: First commit hash. |
38 | | -* `-c2`, `--commit2`: Second commit hash. |
39 | | -* `-o`, `--output_file`: (Optional) Path to the output file. If not provided, the diff will be written to a default file in the system's temporary directory. |
| 47 | +Add `./RepoDiff/dist` to your `PATH` environmental variable. |
40 | 48 |
|
41 | | -### Configuring Diff Options |
| 49 | +## Usage |
42 | 50 |
|
43 | | -You can customize the diff options using a `config.json` file. This allows you to apply different diff strategies depending on the file path. |
| 51 | +### Compare Latest Commit with Another Branch |
44 | 52 |
|
45 | | -For example: |
| 53 | +To compare the latest commit in the current branch with the latest common commit in another branch: |
46 | 54 |
|
47 | 55 | ```bash |
| 56 | +repodiff -b main -o output.txt |
| 57 | +``` |
| 58 | + |
| 59 | +### Compare Two Specific Commits |
| 60 | + |
| 61 | +```bash |
| 62 | +repodiff -c1 abcdef1234567890 -c2 0987654321fedcba -o output.txt |
| 63 | +``` |
| 64 | + |
| 65 | +Parameters: |
| 66 | +* `-b`, `--branch`: Branch to compare with (e.g., `main` or `master`) |
| 67 | +* `-c1`, `--commit1`: First commit hash |
| 68 | +* `-c2`, `--commit2`: Second commit hash |
| 69 | +* `-o`, `--output_file`: (Optional) Path to the output file. If not provided, the diff will be written to a default file in the system's temporary directory. |
| 70 | +* `--version`: Display the current version of RepoDiff |
| 71 | + |
| 72 | +## Configuration |
| 73 | + |
| 74 | +RepoDiff uses a `config.json` file in the project root directory. Example configuration: |
| 75 | + |
| 76 | +```json |
48 | 77 | { |
49 | 78 | "tiktoken_model": "gpt-4o", |
50 | | - "diffs": [ |
51 | | - ["-U50", "--ignore-all-space", "--", ":!*Test*"], |
52 | | - ["-U20", "--ignore-all-space", "--", "*Test*"] |
| 79 | + "filters": [ |
| 80 | + { |
| 81 | + "file_pattern": "*.cs", |
| 82 | + "include_entire_file_with_signatures": true, |
| 83 | + "method_body_threshold": 10 |
| 84 | + }, |
| 85 | + { |
| 86 | + "file_pattern": "*Test*.cs", |
| 87 | + "context_lines": 20 |
| 88 | + }, |
| 89 | + { |
| 90 | + "file_pattern": "*.xml", |
| 91 | + "context_lines": 5 |
| 92 | + }, |
| 93 | + { |
| 94 | + "file_pattern": "*", |
| 95 | + "context_lines": 3 |
| 96 | + } |
53 | 97 | ] |
54 | 98 | } |
55 | 99 | ``` |
56 | 100 |
|
57 | | -Explanation of the options: |
| 101 | +Configuration options: |
58 | 102 |
|
59 | | -* `tiktoken_model`: This specifies the language model you're using (for example, gpt-4o), which helps estimate how many tokens the output will contain. |
60 | | -* `diffs`: This is a list of different comparison rules. Each rule has settings that control how Git compares the files: |
61 | | - * `-U50`: Show 50 lines of context around changes (default is 3 lines). |
62 | | - * `--ignore-all-space`: Ignore spaces when comparing files (useful when whitespace changes don't matter). |
63 | | - * `--`: Signals the end of options and the start of file patterns. |
64 | | - * `:!*Test*`: Exclude files with Test in their path. |
65 | | - * `*Test*`: Include only files with Test in their path. |
| 103 | +* `tiktoken_model`: Specifies the language model for token counting (e.g., "gpt-4o"). |
| 104 | +* `filters`: An array of filter rules that determine how different files are processed. |
| 105 | + * `file_pattern`: Glob pattern to match files (e.g., "*.cs", "*Test*.cs"). |
| 106 | + * `include_entire_file_with_signatures`: (Optional) When true, keeps method signatures but replaces large method bodies with `{ ... }`. |
| 107 | + * `method_body_threshold`: (Optional) Maximum number of lines in a method before its body is replaced with `{ ... }`. |
| 108 | + * `context_lines`: (Optional) Number of context lines to show around changes (default: 3). |
66 | 109 |
|
67 | | -This setup means: |
68 | | -* For most files, it shows a larger context (50 lines around each change) and ignores spaces. |
69 | | -* For test files (*Test*), it shows fewer lines of context (20 lines) and also ignores spaces. |
| 110 | +Filter rules are applied in order, with the first matching pattern being used. |
70 | 111 |
|
71 | | -## Prerequisites |
| 112 | +## Output Format |
72 | 113 |
|
73 | | -- **PowerShell (Windows Only)**: If you're using Windows, you need to run the script in PowerShell. The pattern matching functionality in the script will not work properly in Command Prompt (`cmd`). |
74 | | -- **Python 3.x**: Ensure Python is installed on your system. |
| 114 | +The tool generates a unified diff format with some enhancements: |
75 | 115 |
|
76 | | -## Installation |
| 116 | +1. A header explaining any placeholders used (e.g., `{ ... }` for removed method bodies). |
| 117 | +2. Standard git diff headers for each file. |
| 118 | +3. Modified hunks based on the applied filters: |
| 119 | + - Adjusted context lines |
| 120 | + - Method bodies replaced with `{ ... }` where applicable |
| 121 | + - Original line numbers preserved |
77 | 122 |
|
78 | | -### Option 1: Download the Executable |
| 123 | +Example output: |
79 | 124 |
|
80 | | -1. Go to the [Releases](https://github.com/EntityProcess/RepoDiff/releases) page. |
81 | | -2. Download the latest version of the `repodiff.exe` executable. |
82 | | -3. Move the `repodiff.exe` file to a directory included in your system's `PATH`. |
| 125 | +```diff |
| 126 | +NOTE: Some method bodies have been replaced with "{ ... }" to improve clarity for code reviews and LLM analysis. |
83 | 127 |
|
84 | | -### Option 2: Build the Executable Yourself |
| 128 | +diff --git a/src/MyClass.cs b/src/MyClass.cs |
| 129 | +--- a/src/MyClass.cs |
| 130 | ++++ b/src/MyClass.cs |
| 131 | +@@ -10,7 +10,7 @@ public class MyClass |
| 132 | + public void ProcessData(int value) |
| 133 | + { |
| 134 | + { ... } |
| 135 | + } |
| 136 | +``` |
85 | 137 |
|
86 | | -Clone the repository and navigate to the directory: |
| 138 | +## Prerequisites |
87 | 139 |
|
88 | | -```bash |
89 | | -git clone https://github.com/EntityProcess/RepoDiff.git |
90 | | -cd RepoDiff |
91 | | -``` |
| 140 | +- **PowerShell (Windows Only)**: If you're using Windows, you need to run the script in PowerShell. The pattern matching functionality in the script will not work properly in Command Prompt (`cmd`). |
| 141 | +- **Python 3.x**: Ensure Python is installed on your system. |
92 | 142 |
|
93 | | -Install PyInstaller by running the following command: |
| 143 | +## Running Tests |
94 | 144 |
|
95 | 145 | ```bash |
96 | | -pip install pyinstaller |
97 | | -``` |
| 146 | +# Run all tests |
| 147 | +pytest |
98 | 148 |
|
99 | | -Generate the executable by running `build.bat`. |
| 149 | +# Run specific test file |
| 150 | +pytest tests/test_filters.py |
100 | 151 |
|
101 | | -Add `./RepoDiff/dist` to your `PATH` environmental variable. |
| 152 | +# Run with coverage |
| 153 | +pytest --cov=repodiff |
| 154 | +``` |
102 | 155 |
|
103 | 156 | ## Contributing |
104 | 157 |
|
105 | | -Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests. |
| 158 | +Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests. |
0 commit comments