17
17
#include "promisor-remote.h"
18
18
19
19
static const char index_pack_usage [] =
20
- "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])" ;
20
+ "git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [-- verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])" ;
21
21
22
22
struct object_entry {
23
23
struct pack_idx_entry idx ;
@@ -1436,15 +1436,15 @@ static void fix_unresolved_deltas(struct hashfile *f)
1436
1436
free (sorted_by_pos );
1437
1437
}
1438
1438
1439
- static const char * derive_filename (const char * pack_name , const char * suffix ,
1440
- struct strbuf * buf )
1439
+ static const char * derive_filename (const char * pack_name , const char * strip ,
1440
+ const char * suffix , struct strbuf * buf )
1441
1441
{
1442
1442
size_t len ;
1443
- if (!strip_suffix (pack_name , ".pack" , & len ))
1444
- die (_ ("packfile name '%s' does not end with '.pack'" ),
1445
- pack_name );
1443
+ if (!strip_suffix (pack_name , strip , & len ) || !len ||
1444
+ pack_name [len - 1 ] != '.' )
1445
+ die (_ ("packfile name '%s' does not end with '.%s'" ),
1446
+ pack_name , strip );
1446
1447
strbuf_add (buf , pack_name , len );
1447
- strbuf_addch (buf , '.' );
1448
1448
strbuf_addstr (buf , suffix );
1449
1449
return buf -> buf ;
1450
1450
}
@@ -1459,7 +1459,7 @@ static void write_special_file(const char *suffix, const char *msg,
1459
1459
int msg_len = strlen (msg );
1460
1460
1461
1461
if (pack_name )
1462
- filename = derive_filename (pack_name , suffix , & name_buf );
1462
+ filename = derive_filename (pack_name , "pack" , suffix , & name_buf );
1463
1463
else
1464
1464
filename = odb_pack_name (& name_buf , hash , suffix );
1465
1465
@@ -1484,12 +1484,14 @@ static void write_special_file(const char *suffix, const char *msg,
1484
1484
1485
1485
static void final (const char * final_pack_name , const char * curr_pack_name ,
1486
1486
const char * final_index_name , const char * curr_index_name ,
1487
+ const char * final_rev_index_name , const char * curr_rev_index_name ,
1487
1488
const char * keep_msg , const char * promisor_msg ,
1488
1489
unsigned char * hash )
1489
1490
{
1490
1491
const char * report = "pack" ;
1491
1492
struct strbuf pack_name = STRBUF_INIT ;
1492
1493
struct strbuf index_name = STRBUF_INIT ;
1494
+ struct strbuf rev_index_name = STRBUF_INIT ;
1493
1495
int err ;
1494
1496
1495
1497
if (!from_stdin ) {
@@ -1524,6 +1526,16 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
1524
1526
} else
1525
1527
chmod (final_index_name , 0444 );
1526
1528
1529
+ if (curr_rev_index_name ) {
1530
+ if (final_rev_index_name != curr_rev_index_name ) {
1531
+ if (!final_rev_index_name )
1532
+ final_rev_index_name = odb_pack_name (& rev_index_name , hash , "rev" );
1533
+ if (finalize_object_file (curr_rev_index_name , final_rev_index_name ))
1534
+ die (_ ("cannot store reverse index file" ));
1535
+ } else
1536
+ chmod (final_rev_index_name , 0444 );
1537
+ }
1538
+
1527
1539
if (do_fsck_object ) {
1528
1540
struct packed_git * p ;
1529
1541
p = add_packed_git (final_index_name , strlen (final_index_name ), 0 );
@@ -1553,6 +1565,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
1553
1565
}
1554
1566
}
1555
1567
1568
+ strbuf_release (& rev_index_name );
1556
1569
strbuf_release (& index_name );
1557
1570
strbuf_release (& pack_name );
1558
1571
}
@@ -1578,6 +1591,12 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
1578
1591
}
1579
1592
return 0 ;
1580
1593
}
1594
+ if (!strcmp (k , "pack.writereverseindex" )) {
1595
+ if (git_config_bool (k , v ))
1596
+ opts -> flags |= WRITE_REV ;
1597
+ else
1598
+ opts -> flags &= ~WRITE_REV ;
1599
+ }
1581
1600
return git_default_config (k , v , cb );
1582
1601
}
1583
1602
@@ -1695,12 +1714,14 @@ static void show_pack_info(int stat_only)
1695
1714
1696
1715
int cmd_index_pack (int argc , const char * * argv , const char * prefix )
1697
1716
{
1698
- int i , fix_thin_pack = 0 , verify = 0 , stat_only = 0 ;
1717
+ int i , fix_thin_pack = 0 , verify = 0 , stat_only = 0 , rev_index ;
1699
1718
const char * curr_index ;
1700
- const char * index_name = NULL , * pack_name = NULL ;
1719
+ const char * curr_rev_index = NULL ;
1720
+ const char * index_name = NULL , * pack_name = NULL , * rev_index_name = NULL ;
1701
1721
const char * keep_msg = NULL ;
1702
1722
const char * promisor_msg = NULL ;
1703
1723
struct strbuf index_name_buf = STRBUF_INIT ;
1724
+ struct strbuf rev_index_name_buf = STRBUF_INIT ;
1704
1725
struct pack_idx_entry * * idx_objects ;
1705
1726
struct pack_idx_option opts ;
1706
1727
unsigned char pack_hash [GIT_MAX_RAWSZ ];
@@ -1727,6 +1748,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1727
1748
if (prefix && chdir (prefix ))
1728
1749
die (_ ("Cannot come back to cwd" ));
1729
1750
1751
+ if (git_env_bool (GIT_TEST_WRITE_REV_INDEX , 0 ))
1752
+ rev_index = 1 ;
1753
+ else
1754
+ rev_index = !!(opts .flags & (WRITE_REV_VERIFY | WRITE_REV ));
1755
+
1730
1756
for (i = 1 ; i < argc ; i ++ ) {
1731
1757
const char * arg = argv [i ];
1732
1758
@@ -1805,6 +1831,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1805
1831
if (hash_algo == GIT_HASH_UNKNOWN )
1806
1832
die (_ ("unknown hash algorithm '%s'" ), arg );
1807
1833
repo_set_hash_algo (the_repository , hash_algo );
1834
+ } else if (!strcmp (arg , "--rev-index" )) {
1835
+ rev_index = 1 ;
1836
+ } else if (!strcmp (arg , "--no-rev-index" )) {
1837
+ rev_index = 0 ;
1808
1838
} else
1809
1839
usage (index_pack_usage );
1810
1840
continue ;
@@ -1824,7 +1854,16 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1824
1854
if (from_stdin && hash_algo )
1825
1855
die (_ ("--object-format cannot be used with --stdin" ));
1826
1856
if (!index_name && pack_name )
1827
- index_name = derive_filename (pack_name , "idx" , & index_name_buf );
1857
+ index_name = derive_filename (pack_name , "pack" , "idx" , & index_name_buf );
1858
+
1859
+ opts .flags &= ~(WRITE_REV | WRITE_REV_VERIFY );
1860
+ if (rev_index ) {
1861
+ opts .flags |= verify ? WRITE_REV_VERIFY : WRITE_REV ;
1862
+ if (index_name )
1863
+ rev_index_name = derive_filename (index_name ,
1864
+ "idx" , "rev" ,
1865
+ & rev_index_name_buf );
1866
+ }
1828
1867
1829
1868
if (verify ) {
1830
1869
if (!index_name )
@@ -1878,11 +1917,16 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1878
1917
for (i = 0 ; i < nr_objects ; i ++ )
1879
1918
idx_objects [i ] = & objects [i ].idx ;
1880
1919
curr_index = write_idx_file (index_name , idx_objects , nr_objects , & opts , pack_hash );
1920
+ if (rev_index )
1921
+ curr_rev_index = write_rev_file (rev_index_name , idx_objects ,
1922
+ nr_objects , pack_hash ,
1923
+ opts .flags );
1881
1924
free (idx_objects );
1882
1925
1883
1926
if (!verify )
1884
1927
final (pack_name , curr_pack ,
1885
1928
index_name , curr_index ,
1929
+ rev_index_name , curr_rev_index ,
1886
1930
keep_msg , promisor_msg ,
1887
1931
pack_hash );
1888
1932
else
@@ -1893,10 +1937,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1893
1937
1894
1938
free (objects );
1895
1939
strbuf_release (& index_name_buf );
1940
+ strbuf_release (& rev_index_name_buf );
1896
1941
if (pack_name == NULL )
1897
1942
free ((void * ) curr_pack );
1898
1943
if (index_name == NULL )
1899
1944
free ((void * ) curr_index );
1945
+ if (rev_index_name == NULL )
1946
+ free ((void * ) curr_rev_index );
1900
1947
1901
1948
/*
1902
1949
* Let the caller know this pack is not self contained
0 commit comments