Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit d18ef68

Browse files
committed
use pyinstaller
1 parent 9337519 commit d18ef68

3 files changed

Lines changed: 41 additions & 14 deletions

File tree

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,32 @@
1212

1313
## Usage
1414

15-
To use GitDiff4LLM, run the following command:
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+
17+
### Compare Latest Commit with Another Branch
18+
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+
```bash
21+
gitdiff4llm -b <branch> [-o /path/to/output_file.txt]
22+
```
23+
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
1626

1727
```bash
18-
python gitdiff4llm.py <commit1> <commit2> /path/to/output_file.txt
28+
gitdiff4llm -b master
1929
```
2030

21-
### Example
31+
### Compare Two Commits
2232

2333
```bash
24-
python gitdiff4llm.py abc123 def456 combined_diff.txt
34+
gitdiff4llm -c1 <commit1> -c2 <commit2> [-o /path/to/output_file.txt]
2535
```
2636

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.
40+
2741
## Prerequisites
2842

2943
- **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`).
@@ -38,7 +52,15 @@ git clone https://github.com/EntityProcess/GitDiff4LLM.git
3852
cd GitDiff4LLM
3953
```
4054

41-
Make sure you have Python installed on your system, then you can run the script as outlined in the usage section.
55+
Install PyInstaller by running the following command:
56+
57+
```bash
58+
pip install pyinstaller
59+
```
60+
61+
Generate the executable by running `build.bat`.
62+
63+
Add `./GitDiff4LLM/dist` to your `PATH` environmental variable.
4264

4365
## Contributing
4466

build.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyinstaller --onefile --hidden-import=tiktoken --hidden-import=tiktoken_ext.openai_public --hidden-import=tiktoken_ext --add-data "config.json;." gitdiff4llm.py
2+
pause

gitdiff4llm.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tempfile
88

99
# Tokenizer function using OpenAI's tiktoken for LLMs (GPT-3/4)
10-
def count_tokens(text, model):
10+
def count_tokens(text, model="gpt-4o"):
1111
encoding = tiktoken.encoding_for_model(model)
1212
return len(encoding.encode(text))
1313

@@ -25,13 +25,16 @@ def run_git_diff(commit1, commit2, diff_options):
2525

2626
# Function to load config (diff options and tiktoken model) from JSON config file
2727
def load_config(config_file_name="config.json"):
28-
# First try to find the config file in the current working directory
29-
config_path = os.path.join(os.getcwd(), config_file_name)
30-
31-
# If not found in the working directory, try to find it in the directory of the script or executable
32-
if not os.path.exists(config_path):
28+
# Check if running as a PyInstaller bundle (frozen)
29+
if getattr(sys, 'frozen', False):
30+
# If the application is run as a PyInstaller bundle, use the _MEIPASS directory
31+
script_dir = sys._MEIPASS
32+
else:
33+
# If running in a normal Python environment, use the script directory
3334
script_dir = os.path.dirname(os.path.realpath(__file__))
34-
config_path = os.path.join(script_dir, config_file_name)
35+
36+
# Construct the path to config.json
37+
config_path = os.path.join(script_dir, config_file_name)
3538

3639
if os.path.exists(config_path):
3740
try:
@@ -41,7 +44,7 @@ def load_config(config_file_name="config.json"):
4144
print(f"Error loading config file: {e}")
4245
sys.exit(1)
4346
else:
44-
print(f"Config file '{config_file_name}' not found in working directory or script directory.")
47+
print(f"Config file '{config_file_name}' not found in script directory '{script_dir}'.")
4548
sys.exit(1)
4649

4750
# Function to get the latest commit hash for the current branch
@@ -126,7 +129,7 @@ def main(commit1, commit2, output_file):
126129
output_file = args.output_file
127130
else:
128131
temp_dir = tempfile.gettempdir()
129-
output_file = os.path.join(temp_dir, "gitdiff_output.txt")
132+
output_file = os.path.join(temp_dir, "gitdiff4llm", "gitdiff_output.txt")
130133
print(f"No output file specified. Using temporary directory: {output_file}")
131134

132135
# Make sure the output directory exists

0 commit comments

Comments
 (0)