1794
return rc;
1795
}
1796
1797
+static const char *get_ident_string(void)
1798
+{
1799
+ static struct strbuf sb = STRBUF_INIT;
1800
+ struct utsname uts;
1801
+
1802
+ if (sb.len)
1803
+ return sb.buf;
1804
+ if (uname(&uts))
1805
+ die_errno(_("failed to get kernel name and information"));
1806
+ strbuf_addf(&sb, "Location %s, system %s %s %s", get_git_work_tree(),
1807
+ uts.sysname, uts.release, uts.version);
1808
+ return sb.buf;
1809
+}
1810
+
1811
+static int ident_in_untracked(const struct untracked_cache *uc)
1812
+{
1813
+ const char *end = uc->ident.buf + uc->ident.len;
1814
+ const char *p = uc->ident.buf;
1815
+
1816
+ for (p = uc->ident.buf; p < end; p += strlen(p) + 1)
1817
+ if (!strcmp(p, get_ident_string()))
1818
+ return 1;
1819
+ return 0;
1820
+}
1821
+
1822
+void add_untracked_ident(struct untracked_cache *uc)
1823
+{
1824
+ if (ident_in_untracked(uc))
1825
+ return;
1826
+ strbuf_addstr(&uc->ident, get_ident_string());
1827
+ /* this strbuf contains a list of strings, save NUL too */
1828
+ strbuf_addch(&uc->ident, 0);
1829
+}
1830
+
1831
static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
1832
int base_len,
1833
const struct pathspec *pathspec)
1894
if (ce_skip_worktree(active_cache[i]))
1895
return NULL;
1896
1897
+ if (!ident_in_untracked(dir->untracked)) {
1898
+ warning(_("Untracked cache is disabled on this system."));
1899
+ return NULL;
1900
+ }
1901
+
1902
if (!dir->untracked->root) {
1903
const int len = sizeof(*dir->untracked->root);
1904
dir->untracked->root = xmalloc(len);
2307
hashcpy(ouc->excludes_file_sha1, untracked->ss_excludes_file.sha1);
2308
ouc->dir_flags = htonl(untracked->dir_flags);
2309
memcpy(ouc->exclude_per_dir, untracked->exclude_per_dir, len + 1);
2310
+
2311
+ varint_len = encode_varint(untracked->ident.len, varbuf);
2312
+ strbuf_add(out, varbuf, varint_len);
2313
+ strbuf_add(out, untracked->ident.buf, untracked->ident.len);
2314
+
2315
strbuf_add(out, ouc, ouc_size(len));
2316
free(ouc);
2317
ouc = NULL;
2497
struct untracked_cache *uc;
2498
struct read_data rd;
2499
const unsigned char *next = data, *end = (const unsigned char *)data + sz;
2456
- int len;
2500
+ const char *ident;
2501
+ int ident_len, len;
2502
2503
if (sz <= 1 || end[-1] != '\0')
2504
return NULL;
2505
end--;
2506
2507
+ ident_len = decode_varint(&next);
2508
+ if (next + ident_len > end)
2509
+ return NULL;
2510
+ ident = (const char *)next;
2511
+ next += ident_len;
2512
+
2513
ouc = (const struct ondisk_untracked_cache *)next;
2514
if (next + ouc_size(0) > end)
2515
return NULL;
2516
2517
uc = xcalloc(1, sizeof(*uc));
2518
+ strbuf_init(&uc->ident, ident_len);
2519
+ strbuf_add(&uc->ident, ident, ident_len);
2520
load_sha1_stat(&uc->ss_info_exclude, &ouc->info_exclude_stat,
2521
ouc->info_exclude_sha1);
2522
load_sha1_stat(&uc->ss_excludes_file, &ouc->excludes_file_stat,