summaryrefslogtreecommitdiffstats
path: root/git_part.c
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-09-27 00:07:03 +0300
committerGalin Simeonov <gts@volconst.com>2021-09-27 00:07:03 +0300
commit8c9ec9a22944e4d47b707d01f084e31ce4512f8a (patch)
treee31166165833880ac105c074a97e3566ee1b3416 /git_part.c
parentb24710fdd33599b83020d92b99961da36655cc4f (diff)
downloadvolgit-8c9ec9a22944e4d47b707d01f084e31ce4512f8a.tar.gz
Take html special chars into account when printing blobs. Not a perfect solution
Diffstat (limited to 'git_part.c')
-rw-r--r--git_part.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/git_part.c b/git_part.c
index fb6d18d..beaf5d0 100644
--- a/git_part.c
+++ b/git_part.c
@@ -95,7 +95,7 @@ void print_commits(int dir_fd,const git_reference *branch, git_repository *repo)
print_commit(current_commit,NULL,log_file,diff_directory_fd,repo);
git_revwalk_free(walker);
- fclose(log_file);
+ close_file(log_file);
}
void print_commit(git_commit *current_commit,git_commit *parent_commit,FILE *log_file,int diff_directory_fd,git_repository *repo)
{
@@ -200,10 +200,22 @@ int print_entry(FILE *index_file,const git_tree_entry *entry,int base_dir_fd,git
push_html_link_for_blob(index_file,entry_name,entry_oid);
{
FILE *blob_file;
- const void *blob_data;
+ const unsigned char *blob_data;
size_t blob_size;
+ size_t i;
git_blob *blob;
+ static const char *special_chars[256]
+ =
+ {
+ ['\"']="&quot;",
+ ['\'']="&apos;",
+ ['&']="&amp;",
+ ['<']="&lt;",
+ ['>']="&gt;",
+
+ };
+
blob=(git_blob*)obj;
blob_file=create_file(base_dir_fd,entry_oid);
@@ -211,9 +223,20 @@ int print_entry(FILE *index_file,const git_tree_entry *entry,int base_dir_fd,git
blob_size=git_blob_rawsize(blob);
blob_data=git_blob_rawcontent(blob);
- fwrite(blob_data,blob_size,1,blob_file);
-
- fclose(blob_file);
+ fprintf(blob_file,"<code><pre>\n");
+ for(i=0;i<blob_size;++i)
+ {
+ if(special_chars[blob_data[i]])
+ {
+ fwrite(special_chars[blob_data[i]],1,strlen(special_chars[blob_data[i]]),blob_file);
+ }else
+ {
+ fwrite(blob_data+i,1,1,blob_file);
+ }
+ }
+ fprintf(blob_file,"</pre></code>\n");
+
+ close_file(blob_file);
}
break;
}