reactivated project (dev: http://git-dev.pk910.de)
[phpgitweb.git] / htdocs / lib / GitCommand.class.php
index a8ede915817beaafc0e070ddcb8027248bd8ae2a..198cc61f6ce166f5e7fcbe78d2dd7be7ee0fb13e 100644 (file)
@@ -68,8 +68,10 @@ class GitCommand {
                if($ref)
                        $args[] = $ref;
                $age = self::git_execute($args, $git_path);
-               preg_match("/[0-9]{9,}/i", $age, $result);
-               return $result[0];
+               if(preg_match("/[0-9]{9,}/i", $age, $result))
+                       return $result[0];
+               else
+                       return -1;
        }
        
        private static function parse_commit($commit_data) {
@@ -124,7 +126,7 @@ class GitCommand {
        }
        
        public static function get_commit($git_path, $commit_id) {
-               $args = array("rev-list", "--header", "--max-count=1", $commit_id, "--");
+               $args = array("rev-list", "--header", "--max-count=1", ($commit_id ? $commit_id : "--all"), "--");
                $commit_data = self::git_execute($args, $git_path);
                $commit = self::parse_commit($commit_data);
                return $commit;
@@ -153,17 +155,18 @@ class GitCommand {
                                $files = explode("\t", $entry['file']);
                                $entry['from_file'] = $files[0];
                                $entry['to_file'] = $files[1];
-                       }
+                       } else
+                               $entry['from_file'] = $entry['to_file'] = $entry['file'];
                } else if(preg_match('/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$/i', $line, $matches)) {
                        $entry['parents'] = strlen($matches[1]);
                        $from_modes = explode(" ", $matches[2]);
-                       $entry['from_mode'] = array_slice($from_modes, 1);
+                       $entry['from_mode'] = array_slice($from_modes, 1, -1);
                        $entry['to_mode'] = $from_modes[0];
                        $from_ids = explode(" ", $matches[3]);
-                       $entry['from_id'] = array_slice($from_ids, 1);
+                       $entry['from_id'] = array_slice($from_ids, 1, -1);
                        $entry['to_id'] = $from_ids[0];
                        $entry['status'] = str_split($matches[4]);
-                       $entry['file'] = $matches[5];
+                       $entry['file'] = $entry['from_file'] = $entry['to_file'] = $matches[5];
                }
                return $entry;
        }