# How Git Diff Impact Mapping Helps You Understand Code Changes

> Understand code changes with Git diff impact mapping. Discover affected system parts, their importance, and change propagation in call graphs. Learn more today.

- Repository: [Martin Vogel/codebase-memory-mcp](https://github.com/DeusData/codebase-memory-mcp)
- Tags: deep-dive
- Published: 2026-07-15

---

**Git diff impact mapping converts line-oriented diffs into symbol-oriented impact maps that reveal exactly which system parts are affected, why they matter, and how changes propagate through call graphs.**

The **codebase-memory-mcp** repository provides a specialized toolchain that turns raw version control output into actionable intelligence. By leveraging **git diff impact mapping**, developers move beyond simple line counts to understand the semantic footprint of every commit, calculating blast radius and risk classification automatically. This approach parses diffs and traverses abstract syntax graphs to make impact analysis reproducible and programmatic.

## The Core Pipeline: From Diff Output to Impact Summary

The transformation from raw diff to actionable insight follows a four-stage pipeline centered around the **`detect_changes()`** entry point. Each stage is implemented in specific source files that handle distinct responsibilities.

### Parsing the Raw Diff

At the foundation, a pure-C parser in **[`src/pipeline/pass_gitdiff.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/pipeline/pass_gitdiff.c)** understands both the `--name-status` and `--unified=0` diff formats (lines 276‑279). The parser exposes two primary functions:

```c
/* Returns the number of lines written to `out`. */
int parse_name_status(const char *diff_output, char **out);
int parse_unified0(const char *diff_output, char **out);

```

These functions extract file change metadata without relying on external Git libraries, ensuring fast, portable processing of diff strings.

### Mapping Files to Code Symbols

Once files are identified, the system must determine what code symbols reside within them. This occurs in **[`src/mcp/mcp.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/mcp/mcp.c)** (lines 895‑896), where the pipeline constructs a `"review_change_impact"` request. The module walks the abstract syntax graph (AST) for every changed file and collects all symbols defined there, establishing the link between version control changes and actual code entities.

### Building the Impact Summary

The heart of the analysis lives in **[`src/store/store.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/store/store.c)** (lines 3781‑3783), where **`cbm_build_impact_summary()`** aggregates visited hops and edges into a compact structure. The function, declared in **[`src/store/store.h`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/store/store.h)** (lines 519‑522), produces a **`cbm_impact_summary_t`** value containing:

- **Symbol counts**: How many symbols were touched
- **Module involvement**: Which modules participate in the change
- **Risk classification**: High, medium, or low impact ratings

This aggregation transforms disconnected file changes into a coherent picture of system-wide effects.

### Delivering Human and Machine-Readable Output

The final stage exposes results through two channels. **[`src/cli/cli.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cli/cli.c)** (line 530) prints a human-readable report for immediate developer review, while the underlying system returns a JSON payload that downstream tools can consume. This dual output makes the analysis suitable for both interactive debugging and automated CI/CD integration.

## Practical Usage: CLI and Programmatic Examples

You can trigger the detection pipeline directly from the repository root using the built-in CLI:

```bash

# Detect uncommitted changes

./cbm detect_changes

# Compare HEAD against the main branch

./cbm detect_changes -b main

```

For programmatic integration, build a request using the JSON API and call the summary builder:

```c
/* Build a request that asks the MCP to review change impact */
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
yyjson_mut_val *review = yyjson_mut_obj_add_obj(doc, NULL);
yyjson_mut_obj_add_str(doc, review, "name", "review_change_impact");
yyjson_mut_obj_add_str(doc, review, "title", "Review change impact");

/* The MCP will eventually call cbm_build_impact_summary to
   produce the final impact_summary_t value */
cbm_impact_summary_t summary = cbm_build_impact_summary(
        hops, hop_count, edges, edge_count);

```

## Summary

- **`detect_changes()`** serves as the unified entry point that orchestrates the entire git diff impact mapping workflow.
- The pure-C parser in **[`src/pipeline/pass_gitdiff.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/pipeline/pass_gitdiff.c)** handles multiple diff formats without external dependencies.
- **Git diff impact mapping** converts line-oriented version control output into symbol-oriented analysis, revealing blast radius and risk levels.
- The system delivers both human-readable CLI output and machine-parseable JSON for CI/CD automation.
- Impact analysis becomes reproducible and programmatic, eliminating manual grepping and commit log scanning.

## Frequently Asked Questions

### What is git diff impact mapping?

**Git diff impact mapping** is the process of converting raw `git diff` output into a semantic analysis of code changes. It maps modified files to specific symbols in the codebase, then calculates how those changes propagate through call graphs to determine the true blast radius and risk level of a commit.

### How does codebase-memory-mcp parse different git diff formats?

The system uses a lightweight pure-C parser located in **[`src/pipeline/pass_gitdiff.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/pipeline/pass_gitdiff.c)**. This implementation understands both the `--name-status` format for quick file identification and the `--unified=0` format for detailed change analysis, allowing it to process diff output from various Git commands without requiring the Git binary at runtime.

### What data does the cbm_build_impact_summary function provide?

The **`cbm_build_impact_summary()`** function, implemented in **[`src/store/store.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/store/store.c)**, aggregates traversal results into a **`cbm_impact_summary_t`** structure. This summary includes the total number of symbols affected by the change, which specific modules are involved, and a risk classification (high, medium, or low) that indicates the potential for cascading effects.

### Can I integrate git diff impact mapping into automated workflows?

Yes, the architecture supports automation through its dual output model. While **[`src/cli/cli.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/cli/cli.c)** provides formatted text for human review, the underlying **`detect_changes()`** pipeline returns structured JSON payloads that CI/CD systems can ingest. The C API also allows direct integration into custom tooling via the **`review_change_impact`** request mechanism in **[`src/mcp/mcp.c`](https://github.com/DeusData/codebase-memory-mcp/blob/main/src/mcp/mcp.c)**.