New categories arise from time to time. The descriptions for all categories are held in www/en/ports/categories. There are two situations when FreshPorts needs to fetch this file from CVS:
- When a new port is created.
- When www/en/ports/categories is updated.
I have case #2 coded. Case #1 is not as easy to do. In case #2, I special case the filename and fetch it whenever I see a commit against it. A flag is raised to indicate that this file needs to be proceesed. If the file is not properly fetched, the commit is marked as REFRESH_NEEDED. The system monitors such commits and eventually the commit will be reprocessed and the categories updated based on a successful fetch of www/en/ports/categories.
Case #1 is more challenging. We are processing a commit. We encounter a new category, often as a secondary category within the CATEGORIES field of a Makefile. cvs-all emails are processed in two stages. First, we capture the basic information, creating any new ports as required. Later, in another transaction, we refresh that port. This ensures that the cvs-all commit is recorded, despite not having complete information. Before the port can be created, we need to create the category.
If we were to process the commit again, the category already exists, and thus we don’t go through the same code path.
Tricky.
On a related note: if you create a category which contains no ports, the CategoryStatsUpdate() function will fail with a “null value in column “last_update” violates not-null constraint” error. That’s easily fixed if you allow null for that column.