{%- if merge_type == "git_diff" -%}
如果你需要生成代码，对于每个需要更改的文件,你需要按 * Unified Diff * 的格式进行生成。

# Unified Diff Format Rules

1. **File Header**:
   - The file header contains identifiers for the old and new versions of the file.
   - The format is: `--- a/file_path` and `+++ b/file_path`.
   - `---` indicates the old version of the file, and `+++` indicates the new version of the file.

2. **Hunk Header**:
   - Each hunk represents a section of the file that has been changed.
   - The format is: `@@ -start,length +start,length @@`
   - `-start,length` indicates the starting line and length of the old version.
   - `+start,length` indicates the starting line and length of the new version.

3. **Change Lines**:
   - Lines prefixed with `-` are removed from the old version.
   - Lines prefixed with `+` are added in the new version.
   - Lines prefixed with a space are unchanged and are included for context.

4. **Context Lines**:
   - Context lines are prefixed with a space and are included to provide context around the changes.

# Example of a Unified Diff

```diff
--- a/example.txt
+++ b/example.txt
@@ -1,3 +1,4 @@
 This is the old content.
-This line is removed.
+This line is added.
 This line remains unchanged.
+This is a new line added.
```

# Explanation of the Example

- **File Header**:
  - `--- a/example.txt` indicates the old version of the file.
  - `+++ b/example.txt` indicates the new version of the file.

- **Hunk Header**:
  - `@@ -1,3 +1,4 @@` indicates that the hunk starts at line 1 in the old version and spans 3 lines, and starts at line 1 in the new version and spans 4 lines.

- **Change Lines**:
  - `-This line is removed.` indicates that this line was removed from the old version.
  - `+This line is added.` indicates that this line was added in the new version.
  - `+This is a new line added.` indicates that this new line was added in the new version.

- **Context Lines**:
  - `This is the old content.` and `This line remains unchanged.` are context lines that provide context around the changes.

{%- endif %}
{%- if merge_type == "search_replace" -%}
如果你需要生成代码，对于每个需要更改的文件,你需要按 *SEARCH/REPLACE block* 的格式进行生成。

# *SEARCH/REPLACE block* Rules:

Every *SEARCH/REPLACE block* must use this format:
1. The opening fence and code language, eg: ```python
2. The file path alone on a line, starting with "##File:" and verbatim. No bold asterisks, no quotes around it, no escaping of characters, etc.
3. The start of search block: <<<<<<< SEARCH
4. A contiguous chunk of lines to search for in the existing source code
5. The dividing line: =======
6. The lines to replace into the source code
7. The end of the replace block: >>>>>>> REPLACE
8. The closing fence: ```

Every *SEARCH* section must *EXACTLY MATCH* the existing source code, character for character, including all comments, docstrings, etc.

*SEARCH/REPLACE* blocks will replace *all* matching occurrences.
Include enough lines to make the SEARCH blocks unique.

Include *ALL* the code being searched and replaced!

To move code within a file, use 2 *SEARCH/REPLACE* blocks: 1 to delete it from its current location, 1 to insert it in the new location.

If you want to put code in a new file, use a *SEARCH/REPLACE block* with:
- A new file path, including dir name if needed
- An empty `SEARCH` section
- The new file's contents in the `REPLACE` section

ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*!

下面我们来看一个例子：

当前项目目录结构：
1. 项目根目录： /tmp/projects/mathweb
2. 项目子目录/文件列表(类似tree 命令输出)
flask/
    app.py
    templates/
        index.html
    static/
        style.css

用户需求： Change get_factorial() to use math.factorial

回答： To make this change we need to modify `/tmp/projects/mathweb/flask/app.py` to:

1. Import the math package.
2. Remove the existing factorial() function.
3. Update get_factorial() to call math.factorial instead.

Here are the *SEARCH/REPLACE* blocks:

```python
##File: /tmp/projects/mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```

```python
##File: /tmp/projects/mathweb/flask/app.py
<<<<<<< SEARCH
def factorial(n):
    "compute factorial"

    if n == 0:
        return 1
    else:
        return n * factorial(n-1)

=======
>>>>>>> REPLACE
```

```python
##File: /tmp/projects/mathweb/flask/app.py
<<<<<<< SEARCH
    return str(factorial(n))
=======
    return str(math.factorial(n))
>>>>>>> REPLACE
```

用户需求： Refactor hello() into its own file.

回答：To make this change we need to modify `main.py` and make a new file `hello.py`:

1. Make a new hello.py file with hello() in it.
2. Remove hello() from main.py and replace it with an import.

Here are the *SEARCH/REPLACE* blocks:

```python
##File: /tmp/projects/mathweb/hello.py
<<<<<<< SEARCH
=======
def hello():
    "print a greeting"

    print("hello")
>>>>>>> REPLACE
```

```python
##File: /tmp/projects/mathweb/main.py
<<<<<<< SEARCH
def hello():
    "print a greeting"

    print("hello")
=======
from hello import hello
>>>>>>> REPLACE
```
{%- endif %}

现在让我们开始一个新的任务:

当前项目目录结构：
1. 项目根目录： {{ project_root}}
2. 项目子目录/文件列表(类似tree 命令输出)：
{% if show_file_tree %}
{{ files }}
{% endif %}
下面是一些文件路径以及每个文件对应的源码：

{{ files_code }}

下面是用户的需求：

{{ query }}