Skip to content

About

A KISS approach to project external artefact copy-pasta

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

68 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vendor branching : importing external artifacts without copy-pasta

image

Someday ImageMagick will finally break for good and we'll have a long period of scrambling as we try to reassemble civilization from the rubble. explainxkcd

TL;DR?

Just read the (very short) Wikipedia article.

Fork it here!

You may use vendor branching to do that :-J

Introduction

You copied artefacts from a fancy place to your favourite VCS, tweaked it and now you discover that meanwhile the fancy place updated their code. What now? Artefacts can be source code, data files, PDF files, supporting documentation...

This document is the zillionth attempt at explaining the vendor branching mechanism. Despite the Internet abound with how-to's, developers keep falling in the trap.

There is more: this is related to the concept of the software supply chain.

The problem

In short: copy-pasting artefacts is a seemingly easy way to get things imported in a project. The problem is the maintainance effort that will follow. Do not assume the data is "written in stone" and will never change any more (be it inside your project or externally). Instead, every time you import anything from outside your project, be it code or data, do not bluntly copy-paste; don't just create a "fork" of foreign artefacts unless there really is no other way.

Unless you want to produce a hostile fork...

Sometimes this problem is then solved by manual labor: porting the external changes in Stellarium, a laborous approach prone to bugs. Extremely instructive use cases are presented on Wikipedia.

Usually references of some form are added to the source code, e.g. ftp, snail mail, http, ... The problem is that these references might disappear at some point in the future. This happens all the time with personal pages. An example can be found in this comment: you will get a 404: the pages are gone. Those pages should somehow have been imported as vendor data.

The approach looks daunting, but that is only appearance.

The external (source) version of such artifacts will often continue to evolve, but these modifications obviously will not be magically reflected in the project repository, thus sometimes, if not often leading to artifacts slowly getting totally outdated (hence the term "code rot").

What can go wrong

Cases of special interest

First, there are cases that I'm personally interested in, and are discussed separately:

Don't take it personally: the issue is widespread and totally forgiveable, as the pattern is seldom taken into consideration when a solution is needed for this typical problem.

  1. copy-paste issues in Stellarium started the whole "vendor branching" project after an interesting discussion
  2. the SGP4 copy-pasting is a specific example inside Stellarium. I never thought it would become such an expanding oil spill
  3. a subdirectory of the C47 project drew my attention: it imports and then patches the vendor rejig

More examples can be found here.

A solution: package managers

Sometimes this can be solved by using package managers that automate the importing and updating of external "stuff" (typically code) and - important - allow to fine tune which version is to be imported. But package managers do not allow to modify the imported code out of the box and benefit from external updates. Also, package managers are not always the easiest way to deal with vendors, sometimes due to a lack of experience of contributing C++ developers. Vendor branching is far easier to work with than configuring package managers, as all the required knowledge resides in how to deal with branching.

Python's pip -e is a great example of this. Modifying the vendor code is less great.

Artefacts that can be managed by package managers are not discussed here. An inconvenience of package managers might be that local modifications might be more difficult to manage. This is precisely what vendor branching has been designed for.

And sometimes there will be no package manager provided with the artefact. Often, the artefacts will live in zip or PDF files or HTML pages...

Package managers do not allow to modify the imported code out of the box and benefit from external updates. Also, package managers are not always the easiest way to deal with vendors, sometimes due to a lack of experience of contributing developers that often are volunteers - that come and go.

Another solution: patches

The idea is not to import the vendor artefacts, but create (and store in the repo) patches that patch the vendor at compile/make/... whatever time.

An advanced solution might be Not-forking.

and now the KISS solution: vendor branching!�

Prior note: it is obvious that the problem is widespread, and it is unlikely that the affected projects will change the chosen path (don't fix what isn't broken?)... So this whole discussion is mainly oriented to those who are still fresh in the discipline... And especially towards devs that are about to commit a "copy-paste offence".

Vendor branching is far easier to work with than working with package managers, as all the required knowledge resides in how to work with branching (and merging).

The concept already exists:

Importing external artifacts requires a specific (and in this case a simple - believe me, it is not rocket science - as well as generic) and approach: the Vendor Branch approach. The proposed approach is KISS: simple to apply to novice programmers. By the way, the approach is valid in any VCS, such as SVN, Git, Mercurial, ClearCase, Fossil, TFS, CVS (where it already exists), you name it.

Importing external artefacts in vendor branches will also provide insight in what changed in those artefacts, just by inspecting the "diff" between successive vendor versions. Normally such changes should also be announced by the vendor.

This is in fact an important version control pattern.

The essential steps

  1. Track external changes in vendor branches by successive imports and vendor tags
  2. Do not modify anything in vendor branches
  3. Updates in successive vendor artefact versions can be detected via diffs
  4. ... and merged to local branches (and finally end up in your project's main branch)
  5. ... where changes can be applied.
  6. A local file (or script) tracks metadata about the vendor artefacts so that the vendor artefacts can always be found (until they vanish).
  7. Feel for contributing to the vendor code? Branch off the vendor branch, send the patch and merge locally. (Remember that the next vendor drop might generate conflicts)
  8. All this needs basic VCS mastery.

See the page systems for the more detailed steps using various VCS.

As a side note: the reverse situation: you are the vendor

Interestingly, one could also use the same concept when "subcontracting" your code as vendor code to an outside contractor company.

  1. You create a vendor branch from (a subset of) your own code and send that to the external party. That branch might sometimes need some tweaks so that you prevent things from reaching the external party. That branch serves as a reference.
  2. When changes come back you merge those changes in that vendor branch (without changing them); maybe revert some things your removed earlier in the branch;
  3. and finally merge to your own main.

The difference

  1. Advantages
    • easier for the average developer
    • no manual patching, no need for separate patch scripts
    • no dependency on the vendor (or even a network connection)
  2. Inconveniences
    • the vendor creation might much more space than needed if the vendor drop is huge
    • the repo will grow a bit larger
      • for example, one simple test shows that (using Git and Fossil as a case)
        1. a bare Fossil repo (=SQLite format) file (e.g. rejig) is about ~6Mb (2026-11)
        2. fossil open inflates to 17M
        3. a .git/ vendor drop of that repo takes 5.1M (8.3M but then cleaned by git gc)
        4. git can further reduce disk space with a sparse checkout
  3. What barely changes
    • a vendor drop ingests diffs on a branch first prior to the merge

Other options, to discuss

See also

vendor branching concept

Github

Copy-pasta

still TODO

image

You say no human would reply to a forum thread about Tom Bombadil by writing and editing hundreds of words of text, complete with formatting, fancy punctuation, and two separate uses of the word 'delve'. Unfortunately for both of us, you are wrong. explainxkcd

About

A KISS approach to project external artefact copy-pasta

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors