Understanding Pijul's Patch-Based Architecture

Pijul vs Traditional VCS

Unlike Git, which stores snapshots of the file tree, Pijul stores changes as atomic patches. These patches form a directed acyclic graph (DAG) where each node is a change and dependencies are strictly enforced. This model provides deterministic merges but introduces fragility when patches are reordered or partially applied.

Patch Dependencies and Repositories

Each patch contains metadata about its dependencies—other patches that must be present before it can apply. If a patch is pushed or pulled without its full dependency tree, the receiving repository may silently defer application or report indirect merge conflicts.

Symptoms of Divergence

What It Looks Like in Practice

  • pijul pull completes but new changes do not appear in the working copy.
  • pijul log shows missing dependencies or truncated history.
  • Conflicts occur on seemingly unrelated files or lines.
  • Pushes are rejected due to missing dependencies.

Validating the Issue

pijul log --reverse
pijul debug dependencies > deps.json

Inspect the graph for missing intermediate patches. Compare deps.json with a reference clone to identify inconsistencies.

Root Causes

Partial Patch Transfer

Using filesystem copies instead of proper pijul clone or push/pull may result in incomplete patch histories. Each patch must include its dependency metadata to apply correctly.

Concurrent Patch Creation

When multiple collaborators create patches without pulling each other's changes, a push may fail due to missing prerequisites. This is a natural consequence of Pijul's patch dependency model.

Improper Channel Usage

Pijul supports channels (like Git branches). Creating patches in one channel and applying them in another without proper rebasing can break the patch graph consistency.

Step-by-Step Troubleshooting

1. Ensure Complete Sync Before Patch Creation

pijul pull origin
pijul log

Always pull and apply latest patches before recording new ones. This ensures your patch will correctly reference the current state of the repo.

2. Repair Patch Dependencies

If a patch was received without its dependencies, manually pull the missing patches from a peer repository:

pijul pull ssh://user@peer/repo
pijul apply missing_patch_hash

This allows the patch DAG to reassemble correctly.

3. Check Channel Context

pijul channel
pijul channel switch main

Ensure you're operating in the correct channel. Patches are scoped per channel, and cross-channel merges require explicit rebasing or applying.

4. Rebuild Repository from Canonical Clone

If divergence is too severe, consider recloning from a canonical source:

mv repo repo.bak
pijul clone ssh://origin/repo
mv repo.bak .repo_recovery

Salvage unpushed patches from .repo_recovery and reapply carefully using pijul apply.

5. Audit Patch Files Directly

ls .pijul/changes
cat .pijul/changes/<hash>

Patch metadata includes dependencies, timestamps, and authors. Use this to trace application order and missing references.

Best Practices to Avoid Patch Divergence

  • Use pijul clone, pull, and push exclusively—avoid file copying repos.
  • Always pull and apply before recording or pushing new patches.
  • Coordinate on channels for team workflows; prefer one channel per stable integration line.
  • Use commit hooks or CI scripts to verify complete dependency chains.
  • Consider mirroring patches to shared archives to reduce dependency loss.

Conclusion

Pijul's powerful patch-based model enables elegant concurrent workflows, but it also introduces unique failure modes when dependency integrity breaks down. Repository divergence due to missing patch dependencies is a critical issue that demands understanding of Pijul's internal DAG structure. With careful patch hygiene, channel discipline, and structured diagnostics, teams can resolve and prevent these inconsistencies effectively.

FAQs

1. Why does Pijul require patches to include dependencies?

To ensure deterministic, conflict-free application of changes. This guarantees the patch graph remains valid across clones.

2. Can I fix a broken repo without recloning?

Yes, if you can identify and apply the missing patches. Use pijul log and peer pulls to fill in the gaps.

3. Are patch conflicts avoidable in concurrent teams?

Mostly. If teams regularly pull and apply from each other before pushing, dependency resolution stays clean.

4. What tools help visualize Pijul patch graphs?

Currently, third-party tools or custom scripts parsing pijul debug dependencies are needed. Official visualization is limited.

5. How does Pijul handle patch ordering?

Pijul uses topological sorting of the patch DAG to determine application order, respecting all declared dependencies strictly.