5
5
#include "string-list.h"
6
6
#include "run-command.h"
7
7
#include "commit.h"
8
- #include "tempfile.h"
9
8
#include "trailer.h"
10
9
#include "list.h"
11
10
/*
@@ -163,8 +162,8 @@ static void print_tok_val(FILE *outfile, const char *tok, const char *val)
163
162
fprintf (outfile , "%s%c %s\n" , tok , separators [0 ], val );
164
163
}
165
164
166
- static void format_trailers (const struct process_trailer_options * opts ,
167
- struct list_head * trailers , FILE * outfile )
165
+ void format_trailers (const struct process_trailer_options * opts ,
166
+ struct list_head * trailers , FILE * outfile )
168
167
{
169
168
struct list_head * pos ;
170
169
struct trailer_item * item ;
@@ -366,8 +365,8 @@ static int find_same_and_apply_arg(struct list_head *head,
366
365
return 0 ;
367
366
}
368
367
369
- static void process_trailers_lists (struct list_head * head ,
370
- struct list_head * arg_head )
368
+ void process_trailers_lists (struct list_head * head ,
369
+ struct list_head * arg_head )
371
370
{
372
371
struct list_head * pos , * p ;
373
372
struct arg_item * arg_tok ;
@@ -589,7 +588,7 @@ static int git_trailer_config(const char *conf_key, const char *value,
589
588
return 0 ;
590
589
}
591
590
592
- static void trailer_config_init (void )
591
+ void trailer_config_init (void )
593
592
{
594
593
if (configured )
595
594
return ;
@@ -719,7 +718,7 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val,
719
718
list_add_tail (& new_item -> list , arg_head );
720
719
}
721
720
722
- static void parse_trailers_from_config (struct list_head * config_head )
721
+ void parse_trailers_from_config (struct list_head * config_head )
723
722
{
724
723
struct arg_item * item ;
725
724
struct list_head * pos ;
@@ -735,8 +734,8 @@ static void parse_trailers_from_config(struct list_head *config_head)
735
734
}
736
735
}
737
736
738
- static void parse_trailers_from_command_line_args (struct list_head * arg_head ,
739
- struct list_head * new_trailer_head )
737
+ void parse_trailers_from_command_line_args (struct list_head * arg_head ,
738
+ struct list_head * new_trailer_head )
740
739
{
741
740
struct strbuf tok = STRBUF_INIT ;
742
741
struct strbuf val = STRBUF_INIT ;
@@ -775,17 +774,6 @@ static void parse_trailers_from_command_line_args(struct list_head *arg_head,
775
774
free (cl_separators );
776
775
}
777
776
778
- static void read_input_file (struct strbuf * sb , const char * file )
779
- {
780
- if (file ) {
781
- if (strbuf_read_file (sb , file , 0 ) < 0 )
782
- die_errno (_ ("could not read input file '%s'" ), file );
783
- } else {
784
- if (strbuf_read (sb , fileno (stdin ), 0 ) < 0 )
785
- die_errno (_ ("could not read from stdin" ));
786
- }
787
- }
788
-
789
777
static const char * next_line (const char * str )
790
778
{
791
779
const char * nl = strchrnul (str , '\n' );
@@ -1000,10 +988,10 @@ static void unfold_value(struct strbuf *val)
1000
988
* Parse trailers in "str", populating the trailer info and "head"
1001
989
* linked list structure.
1002
990
*/
1003
- static void parse_trailers (struct trailer_info * info ,
1004
- const char * str ,
1005
- struct list_head * head ,
1006
- const struct process_trailer_options * opts )
991
+ void parse_trailers (const struct process_trailer_options * opts ,
992
+ struct trailer_info * info ,
993
+ const char * str ,
994
+ struct list_head * head )
1007
995
{
1008
996
struct strbuf tok = STRBUF_INIT ;
1009
997
struct strbuf val = STRBUF_INIT ;
@@ -1035,7 +1023,7 @@ static void parse_trailers(struct trailer_info *info,
1035
1023
}
1036
1024
}
1037
1025
1038
- static void free_trailers (struct list_head * trailers )
1026
+ void free_trailers (struct list_head * trailers )
1039
1027
{
1040
1028
struct list_head * pos , * p ;
1041
1029
list_for_each_safe (pos , p , trailers ) {
@@ -1044,87 +1032,6 @@ static void free_trailers(struct list_head *trailers)
1044
1032
}
1045
1033
}
1046
1034
1047
- static struct tempfile * trailers_tempfile ;
1048
-
1049
- static FILE * create_in_place_tempfile (const char * file )
1050
- {
1051
- struct stat st ;
1052
- struct strbuf filename_template = STRBUF_INIT ;
1053
- const char * tail ;
1054
- FILE * outfile ;
1055
-
1056
- if (stat (file , & st ))
1057
- die_errno (_ ("could not stat %s" ), file );
1058
- if (!S_ISREG (st .st_mode ))
1059
- die (_ ("file %s is not a regular file" ), file );
1060
- if (!(st .st_mode & S_IWUSR ))
1061
- die (_ ("file %s is not writable by user" ), file );
1062
-
1063
- /* Create temporary file in the same directory as the original */
1064
- tail = strrchr (file , '/' );
1065
- if (tail )
1066
- strbuf_add (& filename_template , file , tail - file + 1 );
1067
- strbuf_addstr (& filename_template , "git-interpret-trailers-XXXXXX" );
1068
-
1069
- trailers_tempfile = xmks_tempfile_m (filename_template .buf , st .st_mode );
1070
- strbuf_release (& filename_template );
1071
- outfile = fdopen_tempfile (trailers_tempfile , "w" );
1072
- if (!outfile )
1073
- die_errno (_ ("could not open temporary file" ));
1074
-
1075
- return outfile ;
1076
- }
1077
-
1078
- void interpret_trailers (const struct process_trailer_options * opts ,
1079
- struct list_head * new_trailer_head ,
1080
- const char * file )
1081
- {
1082
- LIST_HEAD (head );
1083
- struct strbuf sb = STRBUF_INIT ;
1084
- struct trailer_info info ;
1085
- FILE * outfile = stdout ;
1086
-
1087
- trailer_config_init ();
1088
-
1089
- read_input_file (& sb , file );
1090
-
1091
- if (opts -> in_place )
1092
- outfile = create_in_place_tempfile (file );
1093
-
1094
- parse_trailers (& info , sb .buf , & head , opts );
1095
-
1096
- /* Print the lines before the trailers */
1097
- if (!opts -> only_trailers )
1098
- fwrite (sb .buf , 1 , info .trailer_block_start , outfile );
1099
-
1100
- if (!opts -> only_trailers && !info .blank_line_before_trailer )
1101
- fprintf (outfile , "\n" );
1102
-
1103
-
1104
- if (!opts -> only_input ) {
1105
- LIST_HEAD (config_head );
1106
- LIST_HEAD (arg_head );
1107
- parse_trailers_from_config (& config_head );
1108
- parse_trailers_from_command_line_args (& arg_head , new_trailer_head );
1109
- list_splice (& config_head , & arg_head );
1110
- process_trailers_lists (& head , & arg_head );
1111
- }
1112
-
1113
- format_trailers (opts , & head , outfile );
1114
- free_trailers (& head );
1115
-
1116
- /* Print the lines after the trailers as is */
1117
- if (!opts -> only_trailers )
1118
- fwrite (sb .buf + info .trailer_block_end , 1 , sb .len - info .trailer_block_end , outfile );
1119
- trailer_info_release (& info );
1120
-
1121
- if (opts -> in_place )
1122
- if (rename_tempfile (& trailers_tempfile , file ))
1123
- die_errno (_ ("could not rename temporary file to %s" ), file );
1124
-
1125
- strbuf_release (& sb );
1126
- }
1127
-
1128
1035
void trailer_info_get (struct trailer_info * info , const char * str ,
1129
1036
const struct process_trailer_options * opts )
1130
1037
{
0 commit comments