Detailed technical architecture of the gitignore tool.
Gitignore is a compiled C application with embedded templates and smart merging capabilities.
gitignore/
โโโ src/ # Source code
โ โโโ main.c # Command-line interface & argument parsing
โ โโโ init.c # Template initialization
โ โโโ sync.c # GitHub template synchronization
โ โโโ utils.c # Utility functions
โ โโโ features.c # Advanced features (backup, global)
โ โโโ global_backup.c # Global gitignore management
โ โโโ cache_config.c # Caching and configuration
โ โโโ templates.c # Embedded template data (generated)
โโโ templates/ # Template source files
โโโ scripts/ # Build scripts
โโโ man/ # Manual pages
โโโ Makefile # Build system
User Input โ main.c::parse_flags() โ Command Dispatch โ Feature Implementation
Template Selection โ templates.c::get_builtin_template() โ merge_templates() โ .gitignore
Language Request โ download_template() โ Cache Check โ HTTP Download โ Cache Store โ Merge
main.c)Responsibilities:
--dry-run, --verbose, --quiet)Key Functions:
parse_flags() - Main argument processingis_command_name() - Command vs pattern detectionis_path_or_pattern() - Smart pattern recognitiontemplates.c)Generated from: scripts/generate_templates.sh
Features:
Structure:
const char* get_builtin_template(const char *name) {
if (strcmp(name, "python") == 0) return python_template;
if (strcmp(name, "node") == 0) return node_template;
// ... etc
}
cache_config.c)Configuration File: ~/.config/gitignore/config.conf
Features:
Structure:
typedef struct {
char **default_templates;
int default_count;
int auto_backup;
int cache_enabled;
int cache_duration;
int verbose;
int quiet;
int use_color;
} config_t;
Cache Location: ~/.config/gitignore/cache/
Features:
Cache Structure:
~/.config/gitignore/cache/
โโโ python.gitignore
โโโ node.gitignore
โโโ ... (other synced templates)
Backup Location: ~/.config/gitignore/backups/
Features:
Backup Naming: backup_YYYY-MM-DD_HH-MM-SS
Purpose: Intelligently combine multiple templates while removing duplicates.
Process:
.gitignoreKey Features:
.gitignore contentMERGE_APPEND, MERGE_SMART)Purpose: Distinguish between commands and file patterns.
Rules:
/ โ Path pattern* โ Wildcard pattern. โ Hidden file pattern--add flagPurpose: Automatically determine project type from files.
Detection Map:
// File โ Template mapping
"package.json" โ "node"
"requirements.txt" โ "python"
"setup.py" โ "python"
"Cargo.toml" โ "rust"
"go.mod" โ "go"
"pom.xml" โ "java"
"build.gradle" โ "java"
src/
โโโ main.c # CLI entry point (263 lines)
โโโ init.c # Template initialization
โโโ sync.c # GitHub synchronization
โโโ utils.c # String/file utilities
โโโ features.c # Interactive mode, auto-detect
โโโ global_backup.c # Global gitignore features
โโโ cache_config.c # Configuration and caching
โโโ templates.c # Generated template data
~/.config/gitignore/
โโโ config.conf # User configuration
โโโ templates/ # Custom user templates
โโโ cache/ # Downloaded templates
โโโ backups/ # .gitignore backups
Function Call โ Error Check โ Error Code Return โ User-Friendly Message
all: templates $(TARGET) # Build everything
templates: templates.c # Generate embedded templates
clean: # Remove build artifacts
install: # Install system-wide
test: # Run test suite
regen-templates: # Force template regeneration
templates/*.gitignore โ scripts/generate_templates.sh โ src/templates.c
Generated Code Structure:
// Auto-generated file - DO NOT EDIT
const char *python_template = "# Python\n*.pyc\n__pycache__/\n...";
const char *node_template = "# Node.js\nnode_modules/\n...";
// ... etc
const char* get_builtin_template(const char *name) {
// Lookup logic
}