Artifact [06d28fb587]
Not logged in

Artifact 06d28fb58758681f93d5a13b13a75224a2f2bd8e18a571ad45d03b46f419600c:

Wiki page [Vendor branches] by dmestas on 2026-11-26 04:45:26.
D 2026-11-26T04:45:26.393
L Vendor\sbranches
N text/x-markdown
P 28e3caec3db0f1784a10b62fa29d1fb313d1523171cd346eb9e33c41d3596afe
U dmestas
W 8920
# Vendor branches

**The problem.** Your project (A) needs someone else's code (B). You copy B into
your tree, and then two things happen: you change a few lines of B for your own
needs, and B keeps putting out new releases. Copying each new release over your
copy throws your changes away.

**The fix.** Keep B's releases, exactly as shipped, on a branch of their own, and
merge that branch into your project. Fossil then works out what changed upstream
since the last release you took, and merges only that into your copy, so your own
changes stay.

This repository does exactly that. Its trunk is project A, `notes`, a small tool
that prints text wrapped to a width. The `vendor-wrap` branch holds B, a tiny
library called `wrap`, through three releases.

See it all at once on the [timeline](/timeline?n=all&y=ci).

## Where the vendor branch starts

The vendor branch starts from the repository's first check-in, the
"[initial empty check-in](/info/f2e1f9f4c8)" that `fossil new` makes. It has no
files, so the vendor branch carries none of A's files, only B. But trunk
descends from it, so the two branches share an ancestor and merge normally.

A truly separate root (made with `fossil open --empty` and a first commit)
doesn't work for this: `fossil merge` refuses it with "cannot find a common
ancestor". Branching from your latest code does work, but it puts all of A's
files on the vendor branch too.

## The history

Time runs down the page. Upstream releases arrive on `vendor-wrap` exactly as
shipped, and each one is merged across into trunk. From the moment A patches its copy of wrap, that change
rides along trunk through every later release, including the one that renames
the file.

```pikchr center
scale = 0.9
fontscale = 1.0
thickness = 0.015
arrowht = 0.08; arrowwid = 0.06
$ink = 0x29333a; $muted = 0x53616c; $rule = 0x6b737b
$base = 0xe7eef2; $vend = 0xdde8f3; $accent = 0x9a3f08; $patch = 0xf6e2d2
$r = 0.085
$vx = 1.7
$lx = -0.28
$rx = $vx + 0.28

# column headings
text "TRUNK" bold at (0, 0.62)
text "project A" small color $muted at (0, 0.46)
text "VENDOR-WRAP" bold at ($vx, 0.62)
text "upstream, exactly as shipped" small color $muted at ($vx, 0.46)

# check-ins, oldest at the top
Root:  circle rad $r fill none color $rule dashed at (0, 0)
Start: circle rad $r fill $base color $ink at (0, -0.62)
Cont:  circle rad $r fill $base color $ink at (0, -1.24)
V10:   circle rad $r fill $vend color $ink at ($vx, -1.86)
M10:   circle rad $r fill $base color $ink at (0, -2.48)
Use:   circle rad $r fill $base color $ink at (0, -3.10)
Patch: circle rad $r*1.35 fill $patch color $accent thick at (0, -3.72)
V11:   circle rad $r fill $vend color $ink at ($vx, -4.40)
M11:   circle rad $r fill $base color $ink at (0, -5.10)
V20:   circle rad $r fill $vend color $ink at ($vx, -5.86)
M20:   circle rad $r fill $base color $ink at (0, -6.56)

# trunk: plain until the patch, then carrying A's change
line from Root.s to Start.n color $ink
line from Start.s to Cont.n color $ink
line from Cont.s to M10.n color $ink
line from M10.s to Use.n color $ink
line from Use.s to Patch.n color $ink
line from Patch.s to M11.n color $accent thickness 0.04
line from M11.s to M20.n color $accent thickness 0.04
arrow from M20.s down 0.35 color $accent thickness 0.04

# vendor-wrap: starts at the empty root, has no files of A's
line from Root.e right until even with V10 then to V10.n rad 0.2 color $ink
line from V10.s to V11.n color $ink
line from V11.s to V20.n color $ink

# merges: fossil merge vendor-wrap, run on trunk
arrow from V10.w to M10.ne chop dashed color $muted
arrow from V11.w to M11.ne chop dashed color $muted
arrow from V20.w to M20.ne chop dashed color $muted

# trunk annotations, right-aligned to the left of the column
define tl { text $1 bold rjust at ($lx, $4.y + 0.14)
            text $2 small mono rjust color $muted at ($lx, $4.y - 0.02)
            text $3 small rjust color $muted at ($lx, $4.y - 0.17) }
define tp { text $1 bold rjust color $accent at ($lx, $4.y + 0.14)
            text $2 small mono rjust color $accent at ($lx, $4.y - 0.02)
            text $3 small rjust color $accent at ($lx, $4.y - 0.17) }
tl("INITIAL EMPTY CHECK-IN", "f2e1f9f4c8", "fossil new; 0 files", Root)
tl("START notes", "cd2c8ca84b", "+notes.c +Makefile +README.md", Start)
tl("CONTINUE", "930eb4ff6b", "no wrap library yet", Cont)
tl("MERGE wrap 1.0", "e8cd137bb0", "ADDED vendor/wrap/* (4 files)", M10)
tl("USE wrap", "5781ae8096", "notes.c, Makefile edited", Use)
tp("PATCH wrap.c:7", "b9eed52216", "is_space() also breaks at '\\t'", Patch)
tl("MERGE wrap 1.1", "c977a16fd1", "MERGE wrap.c, +wrap_test.c, −legacy.c", M11)
text "PATCH RETAINED" small bold rjust color $accent at ($lx, M11.y - 0.32)
tl("MERGE wrap 2.0", "e305905700", "RENAME wrap.c → textwrap.c", M20)
text "PATCH RETAINED AT textwrap.c:7" small bold rjust color $accent at ($lx, M20.y - 0.32)

# vendor annotations, left-aligned to the right of the column
define vl { text $1 bold ljust at ($rx, $4.y + 0.14)
            text $2 small mono ljust color $muted at ($rx, $4.y - 0.02)
            text $3 small ljust color $muted at ($rx, $4.y - 0.17) }
vl("IMPORT wrap 1.0", "ab245b7902", "4 files into vendor/wrap/", V10)
vl("IMPORT wrap 1.1", "6e37e4e613", "wrap.c:20 >= → >, +wrap_test.c, −legacy.c", V11)
vl("IMPORT wrap 2.0", "b6163fde93", "fossil mv wrap.c textwrap.c", V20)
```

Check-ins: [notes starts](/info/cd2c8ca84b) · [wrap 1.0](/info/ab245b7902) · [merge 1.0](/info/e8cd137bb0) · [A patches wrap](/info/b9eed52216) · [wrap 1.1](/info/6e37e4e613) · [merge 1.1](/info/c977a16fd1) · [wrap 2.0](/info/b6163fde93) · [merge 2.0](/info/e305905700)

What the merges of 1.1 and 2.0 printed:

    fossil merge vendor-wrap          (wrap 1.1)
    UPDATE vendor/wrap/README.md
    UPDATE vendor/wrap/wrap.h
    MERGE vendor/wrap/wrap.c
    DELETE vendor/wrap/legacy.c
    ADDED vendor/wrap/wrap_test.c

    fossil merge vendor-wrap          (wrap 2.0)
    UPDATE vendor/wrap/README.md
    UPDATE vendor/wrap/wrap.h
    MERGE vendor/wrap/wrap.c
    RENAME vendor/wrap/wrap.c -> vendor/wrap/textwrap.c

## Doing it yourself

Once, to set up. Use a second folder for the vendor branch, so your project's
checkout is never emptied:

    mkdir ../vendor && cd ../vendor
    fossil open ../project.fossil start:trunk
    # copy B's release into vendor/b/
    fossil addremove
    fossil commit --branch vendor-b -m "Import B 1.0 exactly as upstream ships it."

    cd ../project
    fossil merge vendor-b
    fossil commit -m "Merge B 1.0 from vendor-b."

`start:trunk` names the first check-in on trunk. Fossil versions before 2.19
don't know that name: use the hash of the "initial empty check-in" from the
bottom of the timeline instead.

For each new release of B:

    cd ../vendor
    fossil update vendor-b
    rm -rf vendor/b && mkdir vendor/b
    # copy the new release into vendor/b/
    fossil addremove
    fossil commit -m "Import B 1.1 exactly as upstream ships it."

    cd ../project
    fossil merge vendor-b
    # build and test, then:
    fossil commit -m "Merge B 1.1 from vendor-b."

If a release renames a file, record it with `fossil mv OLD NEW` before
`addremove`, as [the wrap 2.0 import](/info/b6163fde93) does, and the merge carries your
changes to the new name. Without `fossil mv`, Fossil sees a deleted file and a
new one, and your changes to it don't follow.

## Seeing your own changes to B

The vendor branch always holds B exactly as upstream shipped it, so comparing it
with trunk shows exactly what your project has changed in B and nothing else:

    fossil diff --from vendor-b --to trunk vendor/b

Here, that's the one-line tab patch:

- [the diff between vendor-wrap and trunk](/vdiff?from=vendor-wrap&to=trunk&glob=vendor/*)
- [who changed what in textwrap.c](/blame?filename=vendor/wrap/textwrap.c&checkin=trunk)
- [textwrap.c's history, through the rename](/finfo?name=vendor/wrap/textwrap.c&ci=trunk)

## If B is already pasted into your project

If A already has a copy of B, perhaps with changes, the first merge from the
vendor branch conflicts, because both branches added the same files. Resolve it
once by keeping A's version of each file, then commit:

    fossil merge vendor-b
    fossil cat vendor/b/FILE -r trunk > vendor/b/FILE    # for each conflicting file
    fossil commit -m "Merge B from vendor-b, keeping our copy."

After that, each new release merges as above. (This repository's history doesn't
show this case. It was tested separately.)

## When not to use it

- If you never change B, a plain copy is simpler: replace the folder with each
  new release.
- If your changes to B could go upstream, send them there, and you won't have to
  carry them at all.
- If your changes are large, or B moves files around a lot, three-way merges
  struggle. Dan Shearer's
  [Not-forking](https://shearer.org/articles/not-forking/) is built for that case.

Z 257aa449ee90a0b32b2c50e31e53b296