summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-09-27 11:15:01 +0300
committerGalin Simeonov <gts@volconst.com>2021-09-27 11:15:01 +0300
commit567d80acbd99a5b8cbaa6d1fccd36837631f9718 (patch)
tree18b0e96814d76e53db68df2f1898e25224298ded
parentace72972a821981acf4bb71ac430805a022a511b (diff)
downloadvolgit-567d80acbd99a5b8cbaa6d1fccd36837631f9718.tar.gz
handling special chars in diff files
-rw-r--r--git_part.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/git_part.c b/git_part.c
index 5d4ab8f..2102e85 100644
--- a/git_part.c
+++ b/git_part.c
@@ -2,6 +2,17 @@
#define VOLGIT_GIT_PART_C VOLGIT_GIT_PART_C
#include <git_part.h>
+static const char *special_chars[256]
+ =
+ {
+ ['\"']="&quot;",
+ ['\'']="&apos;",
+ ['&']="&amp;",
+ ['<']="&lt;",
+ ['>']="&gt;",
+
+ };
+
int print_diff_line(const git_diff_delta *delta,const git_diff_hunk *hunk,const git_diff_line *line,FILE *out)
{
size_t i;
@@ -14,8 +25,13 @@ int print_diff_line(const git_diff_delta *delta,const git_diff_hunk *hunk,const
fprintf(out,"%c ",line->origin);
for(i=0;i<line->content_len;++i)
- fprintf(out,"%c",line->content[i]);
-
+ if(special_chars[line->content[i]])
+ {
+ fwrite(special_chars[line->content[i]],1,strlen(special_chars[line->content[i]]),out);
+ }else
+ {
+ fwrite(line->content+i,1,1,out);
+ }
fprintf(out,"</div>");
return 0;
@@ -208,16 +224,6 @@ int print_entry(FILE *index_file,const git_tree_entry *entry,int base_dir_fd,git
size_t i;
git_blob *blob;
- static const char *special_chars[256]
- =
- {
- ['\"']="&quot;",
- ['\'']="&apos;",
- ['&']="&amp;",
- ['<']="&lt;",
- ['>']="&gt;",
-
- };
blob=(git_blob*)obj;