Teach "delta" attribute to pack-objects.
This teaches pack-objects to use .gitattributes mechanism so that the user can specify certain blobs are not worth spending CPU cycles to attempt deltification. The name of the attrbute is "delta", and when it is set to false, like this: == .gitattributes == *.jpg -delta they are always stored in the plain-compressed base object representation. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
May 19, 2007 at 00:39 UTC
a74db82e15cd8a2c53a4a83e9a36dc7bf7a4c750
1 file changed
+34
-1
builtin-pack-objects.c
+34
-1
@@ -1,5 +1,6 @@
1
#include "builtin.h"
2
#include "cache.h"
3
+#include "attr.h"
4
#include "object.h"
5
#include "blob.h"
6
#include "commit.h"
@@ -40,9 +41,10 @@ struct object_entry {
41
enum object_type in_pack_type; /* could be delta */
42
unsigned char in_pack_header_size;
43
unsigned char preferred_base; /* we do not pack this, but is available
43
- * to be used as the base objectto delta
44
+ * to be used as the base object to delta
45
* objects against.
46
*/
47
+ unsigned char no_try_delta;
48
};
49
50
/*
@@ -739,6 +741,28 @@ static unsigned name_hash(const char *name)
741
return hash;
742
}
743
744
+static void setup_delta_attr_check(struct git_attr_check *check)
745
+{
746
+ static struct git_attr *attr_delta;
747
+
748
+ if (!attr_delta)
749
+ attr_delta = git_attr("delta", 5);
750
+
751
+ check[0].attr = attr_delta;
752
+}
753
+
754
+static int no_try_delta(const char *path)
755
+{
756
+ struct git_attr_check check[1];
757
+
758
+ setup_delta_attr_check(check);
759
+ if (git_checkattr(path, ARRAY_SIZE(check), check))
760
+ return 0;
761
+ if (ATTR_FALSE(check->value))
762
+ return 1;
763
+ return 0;
764
+}
765
+
766
static int add_object_entry(const unsigned char *sha1, enum object_type type,
767
const char *name, int exclude)
768
{
@@ -803,6 +827,9 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
827
if (progress)
828
display_progress(&progress_state, nr_objects);
829
830
+ if (name && no_try_delta(name))
831
+ entry->no_try_delta = 1;
832
+
833
return 1;
834
}
835
@@ -1351,6 +1378,10 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1378
1379
if (entry->size < 50)
1380
continue;
1381
+
1382
+ if (entry->no_try_delta)
1383
+ continue;
1384
+
1385
free_delta_index(n->index);
1386
n->index = NULL;
1387
free(n->data);
@@ -1378,6 +1409,8 @@ static void find_deltas(struct object_entry **list, int window, int depth)
1409
m = array + other_idx;
1410
if (!m->entry)
1411
break;
1412
+ if (m->entry->no_try_delta)
1413
+ continue;
1414
if (try_delta(n, m, max_depth) < 0)
1415
break;
1416
}