Subversion Repositories php_utils

Rev

Rev 24 | Rev 78 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24 Rev 77
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * PHP git functions
4
 * PHP git functions
5
 * Copyright 2021 Daniel Marschall, ViaThinkSoft
5
 * Copyright 2021 - 2023 Daniel Marschall, ViaThinkSoft
6
 * Revision 2021-12-29
6
 * Revision 2023-04-09
7
 *
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
10
 * You may obtain a copy of the License at
11
 *
11
 *
Line 74... Line 74...
74
                if ($pack_files) foreach ($pack_files as $basename) {
74
                if ($pack_files) foreach ($pack_files as $basename) {
75
                        $basename = substr(basename($basename),0,strlen(basename($basename))-5);
75
                        $basename = substr(basename($basename),0,strlen(basename($basename))-5);
76
                        try {
76
                        try {
77
                                return git_read_object($commit_object,
77
                                return git_read_object($commit_object,
78
                                        $objects_dir.'/pack/'.$basename.'.idx',
78
                                        $objects_dir.'/pack/'.$basename.'.idx',
79
                                        $objects_dir.'/pack/'.$basename.'.pack',
79
                                        $objects_dir.'/pack/'.$basename.'.pack'
80
                                        false
-
 
81
                                );
80
                                );
82
                        } catch (Exception $e) {
81
                        } catch (Exception $e) {
83
                                $last_exception = $e;
82
                                $last_exception = $e;
84
                        }
83
                        }
85
                }
84
                }
Line 99... Line 98...
99
        $fp = fopen($idx_file, 'rb');
98
        $fp = fopen($idx_file, 'rb');
100
        if (!$fp) throw new Exception("Cannot open index file $idx_file");
99
        if (!$fp) throw new Exception("Cannot open index file $idx_file");
101
 
100
 
102
        // Read version
101
        // Read version
103
        fseek($fp, 0);
102
        fseek($fp, 0);
104
        $unpacked = unpack('N', fread($fp, 4)); // vorzeichenloser Long-Typ (immer 32 Bit, Byte-Folge Big-Endian)
103
        $unpacked = unpack('H8', fread($fp, 4)); // H8 = 8x "Hex string, high nibble first"
105
        if ($unpacked[1] === 0xFF744F63) {
104
        if ($unpacked[1] === bin2hex("\377tOc")) {
106
                $version = unpack('N', fread($fp, 4))[1]; // vorzeichenloser Long-Typ (immer 32 Bit, Byte-Folge Big-Endian)
105
                $version = unpack('N', fread($fp, 4))[1]; // N = "unsigned long (always 32 bit, big endian byte order)"
107
                $fanout_offset = 8;
106
                $fanout_offset = 8;
108
                if ($version != 2) throw new Exception("Version $version unknown");
107
                if ($version != 2) throw new Exception("Version $version unknown");
109
        } else {
108
        } else {
110
                $version = 1;
109
                $version = 1;
111
                $fanout_offset = 0;
110
                $fanout_offset = 0;
Line 212... Line 211...
212
 
211
 
213
        if ($debug) echo "Packed size = ".sprintf('0x%x',$size)."\n";
212
        if ($debug) echo "Packed size = ".sprintf('0x%x',$size)."\n";
214
 
213
 
215
        // Read delta base type
214
        // Read delta base type
216
        if ($type == 6/*OBJ_OFS_DELTA*/) {
215
        if ($type == 6/*OBJ_OFS_DELTA*/) {
217
                // "a negative relative offset from the delta object's position in the pack
216
                // "a negative relative offset from the delta object's position in the pack if this is an OBJ_OFS_DELTA object"
218
                // if this is an OBJ_OFS_DELTA object"
-
 
219
                $delta_info = unpack('C*', fread($fp,4))[1]; // TODO?!
217
                $delta_info = unpack('C*', fread($fp,4))[1];
220
                if ($debug) echo "Delta negative offset: $delta_info\n";
218
                if ($debug) echo "Delta negative offset: $delta_info\n";
-
 
219
                throw new Exception("OBJ_OFS_DELTA is currently not implemented"); // TODO! Implement OBJ_OFS_DELTA!
221
        }
220
        }
222
        if ($type == 7/*OBJ_REF_DELTA*/) {
221
        if ($type == 7/*OBJ_REF_DELTA*/) {
223
                // "base object name if OBJ_REF_DELTA"
222
                // "base object name if OBJ_REF_DELTA"
224
                $delta_info = bin2hex(fread($fp,20))[1]; // TODO?!
223
                $delta_info = bin2hex(fread($fp,20));
225
                if ($debug) echo "Delta base object name: $delta_info\n";
224
                if ($debug) echo "Delta base object name: $delta_info\n";
-
 
225
                throw new Exception("OBJ_REF_DELTA is currently not implemented"); // TODO! Implement OBJ_REF_DELTA!
226
        }
226
        }
227
 
227
 
228
        // Read compressed data
228
        // Read compressed data
229
        $compressed = fread($fp,$size);
229
        $compressed = fread($fp,$size);
230
 
230