zpmod  b19981f
High-performance Zsh module for script optimization and filesystem helpers
rehash_diff.c File Reference

Incremental PATH diff snapshot (initial slice). More...

#include "zpmod.mdh"
#include "zpmod.pro"
#include "zpmod_emoji.h"
#include "zpmod_rehash.h"
#include "zpmod_vendor_shims.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
Include dependency graph for rehash_diff.c:

Go to the source code of this file.

Data Structures

struct  rh_entry
 
struct  rh_vec
 

Macros

#define ZP_RH_SUBDIR   "zpmod"
 
#define ZP_RH_FILE   "rehash_path_v1.snapshot"
 

Functions

static char * zp_rh_base_cache_dir (void)
 
static char * zp_rh_dir (char *nam)
 
static char * zp_rh_file (char *nam)
 
static void rh_vec_init (struct rh_vec *v)
 
static int rh_vec_push (struct rh_vec *v, struct rh_entry *e)
 
static void rh_vec_free (struct rh_vec *v)
 
static int rh_load (const char *nam, const char *file, struct rh_vec *out)
 
static int rh_write (char *nam, const char *file, struct rh_vec *paths)
 
static void rh_collect_current (struct rh_vec *out)
 
int zp_rehash_diff_core (char *nam)
 

Detailed Description

Incremental PATH diff snapshot (initial slice).

Goal: avoid full command rehash when PATH unchanged. This slice:

  • Persists a snapshot file with directory list + per-dir mtime+inode hash
  • On invocation, loads snapshot and computes diff: added, removed, metadata-changed
  • Prints summary and lists changed dirs
  • Future slices: selectively invoke internal hash invalidation for changed dirs only

Definition in file rehash_diff.c.

Macro Definition Documentation

◆ ZP_RH_FILE

#define ZP_RH_FILE   "rehash_path_v1.snapshot"

Definition at line 26 of file rehash_diff.c.

◆ ZP_RH_SUBDIR

#define ZP_RH_SUBDIR   "zpmod"

Definition at line 25 of file rehash_diff.c.

Function Documentation

◆ rh_collect_current()

static void rh_collect_current ( struct rh_vec out)
static

Definition at line 214 of file rehash_diff.c.

References getaparam(), rh_entry::ino, rh_entry::mtime, rh_entry::path, rh_entry::present_now, rh_vec_push(), zalloc(), and zsfree().

Referenced by zp_rehash_diff_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rh_load()

static int rh_load ( const char *  nam,
const char *  file,
struct rh_vec out 
)
static

Definition at line 138 of file rehash_diff.c.

References rh_entry::ino, rh_entry::mtime, rh_entry::path, rh_entry::present_now, rh_vec_push(), zalloc(), and zsfree().

Referenced by zp_rehash_diff_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rh_vec_free()

static void rh_vec_free ( struct rh_vec v)
static

Definition at line 120 of file rehash_diff.c.

References rh_vec::cap, rh_vec::items, rh_entry::path, rh_vec::size, zfree(), and zsfree().

Referenced by zp_rehash_diff_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rh_vec_init()

static void rh_vec_init ( struct rh_vec v)
static

Definition at line 102 of file rehash_diff.c.

References rh_vec::cap, rh_vec::items, and rh_vec::size.

Referenced by zp_rehash_diff_core().

Here is the caller graph for this function:

◆ rh_vec_push()

static int rh_vec_push ( struct rh_vec v,
struct rh_entry e 
)
static

Definition at line 107 of file rehash_diff.c.

References rh_vec::cap, rh_vec::items, rh_vec::size, and zrealloc().

Referenced by rh_collect_current(), and rh_load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rh_write()

static int rh_write ( char *  nam,
const char *  file,
struct rh_vec paths 
)
static

Definition at line 194 of file rehash_diff.c.

References rh_vec::items, rh_entry::path, rh_vec::size, zp_icon(), and zwarnnam().

Referenced by zp_rehash_diff_core().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zp_rehash_diff_core()

int zp_rehash_diff_core ( char *  nam)

Definition at line 241 of file rehash_diff.c.

References rh_entry::ino, rh_vec::items, rh_entry::mtime, rh_entry::path, rh_entry::present_now, rh_collect_current(), rh_load(), rh_vec_free(), rh_vec_init(), rh_write(), rh_vec::size, zp_icon(), zp_rh_file(), and zsfree().

Referenced by bin_zpmod().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zp_rh_base_cache_dir()

static char* zp_rh_base_cache_dir ( void  )
static

Definition at line 28 of file rehash_diff.c.

References getsparam(), zalloc(), and ztrdup().

Referenced by zp_rh_dir().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zp_rh_dir()

static char* zp_rh_dir ( char *  nam)
static

Definition at line 48 of file rehash_diff.c.

References zalloc(), zp_icon(), zp_rh_base_cache_dir(), ZP_RH_SUBDIR, zsfree(), and zwarnnam().

Referenced by zp_rh_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zp_rh_file()

static char* zp_rh_file ( char *  nam)
static

Definition at line 75 of file rehash_diff.c.

References zalloc(), zp_rh_dir(), ZP_RH_FILE, and zsfree().

Referenced by zp_rehash_diff_core().

Here is the call graph for this function:
Here is the caller graph for this function: