{"thread":{"id":"9275","subject":"[PATCH] gitweb: Show submodule entries in the 'tree' view","startedAt":"2007-07-28T14:27:31Z","lastAt":"2007-07-28T14:27:31Z","messageCount":1,"participants":["Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"48907","messageId":"11856328523162-git-send-email-jnareb@gmail.com","threadId":"9275","inReplyTo":null,"subject":"[PATCH] gitweb: Show submodule entries in the 'tree' view","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-07-28T14:27:31Z","receivedAt":"2007-07-28T14:27:31Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Add S_ISGITLINK subroutine and S_IFGITLINK, S_IFINVALID constants.\nAdd support for \"commit\" (submodule) entries in the tree object to\nmode_str ('m---------', following cgit), file_type and file_type_long\n('submodule') subroutines.\n\nThere is only link to the history of submodule entry in the\nsupermodule (current repository) for now, because gitweb doesn't know\nwhere to search for submodule repository objects.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nTested on repositories from t/t3040-subprojects-basic.sh and\nt/t7400-submodule-basic.sh tests.\n\nThe 'm---------' symbolic mode is taken from cgit, C CGI web interface\nfor git; see:\n  http://hjemli.net/git/cgit/tree\n\nThe S_ISGITLINK subroutine and S_IFGITLINK, S_IFINVALID constants\nare taken from cache.h\n\n gitweb/gitweb.perl |   38 +++++++++++++++++++++++++++++++++++---\n 1 files changed, 35 insertions(+), 3 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex b381692..1aceede 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -890,11 +890,25 @@ sub age_string {\n \treturn $age_str;\n }\n \n+use constant {\n+\tS_IFINVALID => 0030000,\n+\tS_IFGITLINK => 0160000,\n+};\n+\n+# submodule/subproject, a commit object reference\n+sub S_ISGITLINK($) {\n+\tmy $mode = shift;\n+\n+\treturn (($mode & S_IFMT) == S_IFGITLINK)\n+}\n+\n # convert file mode in octal to symbolic file mode string\n sub mode_str {\n \tmy $mode = oct shift;\n \n-\tif (S_ISDIR($mode & S_IFMT)) {\n+\tif (S_ISGITLINK($mode)) {\n+\t\treturn 'm---------';\n+\t} elsif (S_ISDIR($mode & S_IFMT)) {\n \t\treturn 'drwxr-xr-x';\n \t} elsif (S_ISLNK($mode)) {\n \t\treturn 'lrwxrwxrwx';\n@@ -920,7 +934,9 @@ sub file_type {\n \t\t$mode = oct $mode;\n \t}\n \n-\tif (S_ISDIR($mode & S_IFMT)) {\n+\tif (S_ISGITLINK($mode)) {\n+\t\treturn \"submodule\";\n+\t} elsif (S_ISDIR($mode & S_IFMT)) {\n \t\treturn \"directory\";\n \t} elsif (S_ISLNK($mode)) {\n \t\treturn \"symlink\";\n@@ -941,7 +957,9 @@ sub file_type_long {\n \t\t$mode = oct $mode;\n \t}\n \n-\tif (S_ISDIR($mode & S_IFMT)) {\n+\tif (S_ISGITLINK($mode)) {\n+\t\treturn \"submodule\";\n+\t} elsif (S_ISDIR($mode & S_IFMT)) {\n \t\treturn \"directory\";\n \t} elsif (S_ISLNK($mode)) {\n \t\treturn \"symlink\";\n@@ -2707,6 +2725,20 @@ sub git_print_tree_entry {\n \t\t\t              \"history\");\n \t\t}\n \t\tprint \"</td>\\n\";\n+\t} else {\n+\t\t# unknown object: we can only present history for it\n+\t\t# (this includes 'commit' object, i.e. submodule support)\n+\t\tprint \"<td class=\\\"list\\\">\" .\n+\t\t      esc_path($t->{'name'}) .\n+\t\t      \"</td>\\n\";\n+\t\tprint \"<td class=\\\"link\\\">\";\n+\t\tif (defined $hash_base) {\n+\t\t\tprint $cgi->a({-href => href(action=>\"history\",\n+\t\t\t                             hash_base=>$hash_base,\n+\t\t\t                             file_name=>\"$basedir$t->{'name'}\")},\n+\t\t\t              \"history\");\n+\t\t}\n+\t\tprint \"</td>\\n\";\n \t}\n }\n \n-- \n1.5.2.4\n"}]}