support utf-8 characters in file names
authorChristian Weiske <cweiske@cweiske.de>
Wed, 13 Nov 2013 20:06:47 +0000 (21:06 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 13 Nov 2013 20:06:47 +0000 (21:06 +0100)
data/config.default.php
src/phorkie/Repository.php

index 070070ddd0e972a49c70f4207e11ca0df598d82e..85713cd450418ba83ebbde61ed7f88e928a198f1 100644 (file)
@@ -146,4 +146,7 @@ $GLOBALS['phorkie']['languages'] = array(
         'geshi' => 'xml'
     ),
 );
         'geshi' => 'xml'
     ),
 );
+
+//needed for UTF-8 characters in file names
+setlocale(LC_CTYPE, 'en_US.UTF_8');
 ?>
 ?>
index f45c76f72a7e8317ed15f23ba5e48d9a99cfbbf0..7428c8a0c093abd7f0d20a474dda6c7c028f1ed4 100644 (file)
@@ -156,6 +156,36 @@ class Repository
         return $arFiles;
     }
 
         return $arFiles;
     }
 
+    /**
+     * Decodes unicode characters in git filenames
+     * They begin and end with double quote characters, and may contain
+     * backslash + 3 letter octal code numbers representing the character.
+     *
+     * For example,
+     * > "t\303\244st.txt"
+     * means
+     * > täst.txt
+     *
+     * On the shell, you can pipe them into "printf" and have them decoded.
+     *
+     * @param string Encoded git file name
+     *
+     * @return string Decoded file name
+     */
+    protected function decodeFileName($name)
+    {
+        $name = substr($name, 1, -1);
+        $name = str_replace('\"', '"', $name);
+        $name = preg_replace_callback(
+            '#\\\\[0-7]{3}#',
+            function ($ar) {
+                return chr(octdec(substr($ar[0], 1)));
+            },
+            $name
+        );
+        return $name;
+    }
+
     protected function getFilePaths()
     {
         if ($this->hash === null) {
     protected function getFilePaths()
     {
         if ($this->hash === null) {
@@ -168,7 +198,13 @@ class Repository
             ->setOption('name-only')
             ->addArgument($hash)
             ->execute();
             ->setOption('name-only')
             ->addArgument($hash)
             ->execute();
-        return explode("\n", trim($output));
+        $files = explode("\n", trim($output));
+        foreach ($files as &$file) {
+            if ($file{0} == '"') {
+                $file = $this->decodeFileName($file);
+            }
+        }
+        return $files;
     }
 
     public function getFileByName($name, $bHasToExist = true)
     }
 
     public function getFileByName($name, $bHasToExist = true)