@@ -2719,37 +2719,36 @@ static int open_or_create_logfile(const char *path, void *cb)
2719
2719
}
2720
2720
2721
2721
/*
2722
- * Create a reflog for a ref. Store its path to *logfile. If
2723
- * force_create = 0, only create the reflog for certain refs (those
2724
- * for which should_autocreate_reflog returns non-zero). Otherwise,
2725
- * create it regardless of the reference name. If the logfile already
2726
- * existed or was created, return 0 and set *logfd to the file
2727
- * descriptor opened for appending to the file. If no logfile exists
2728
- * and we decided not to create one, return 0 and set *logfd to -1. On
2729
- * failure, fill in *err, set *logfd to -1, and return -1.
2722
+ * Create a reflog for a ref. If force_create = 0, only create the
2723
+ * reflog for certain refs (those for which should_autocreate_reflog
2724
+ * returns non-zero). Otherwise, create it regardless of the reference
2725
+ * name. If the logfile already existed or was created, return 0 and
2726
+ * set *logfd to the file descriptor opened for appending to the file.
2727
+ * If no logfile exists and we decided not to create one, return 0 and
2728
+ * set *logfd to -1. On failure, fill in *err, set *logfd to -1, and
2729
+ * return -1.
2730
2730
*/
2731
- static int log_ref_setup (const char * refname ,
2732
- struct strbuf * logfile , int * logfd ,
2733
- struct strbuf * err , int force_create )
2731
+ static int log_ref_setup (const char * refname , int force_create ,
2732
+ int * logfd , struct strbuf * err )
2734
2733
{
2735
- strbuf_git_path ( logfile , "logs/%s" , refname );
2734
+ char * logfile = git_pathdup ( "logs/%s" , refname );
2736
2735
2737
2736
if (force_create || should_autocreate_reflog (refname )) {
2738
- if (raceproof_create_file (logfile -> buf , open_or_create_logfile , logfd )) {
2737
+ if (raceproof_create_file (logfile , open_or_create_logfile , logfd )) {
2739
2738
if (errno == ENOENT )
2740
2739
strbuf_addf (err , "unable to create directory for '%s': "
2741
- "%s" , logfile -> buf , strerror (errno ));
2740
+ "%s" , logfile , strerror (errno ));
2742
2741
else if (errno == EISDIR )
2743
2742
strbuf_addf (err , "there are still logs under '%s'" ,
2744
- logfile -> buf );
2743
+ logfile );
2745
2744
else
2746
2745
strbuf_addf (err , "unable to append to '%s': %s" ,
2747
- logfile -> buf , strerror (errno ));
2746
+ logfile , strerror (errno ));
2748
2747
2749
- return -1 ;
2748
+ goto error ;
2750
2749
}
2751
2750
} else {
2752
- * logfd = open (logfile -> buf , O_APPEND | O_WRONLY , 0666 );
2751
+ * logfd = open (logfile , O_APPEND | O_WRONLY , 0666 );
2753
2752
if (* logfd < 0 ) {
2754
2753
if (errno == ENOENT || errno == EISDIR ) {
2755
2754
/*
@@ -2761,34 +2760,39 @@ static int log_ref_setup(const char *refname,
2761
2760
;
2762
2761
} else {
2763
2762
strbuf_addf (err , "unable to append to '%s': %s" ,
2764
- logfile -> buf , strerror (errno ));
2765
- return -1 ;
2763
+ logfile , strerror (errno ));
2764
+ goto error ;
2766
2765
}
2767
2766
}
2768
2767
}
2769
2768
2770
2769
if (* logfd >= 0 )
2771
- adjust_shared_perm (logfile -> buf );
2770
+ adjust_shared_perm (logfile );
2772
2771
2772
+ free (logfile );
2773
2773
return 0 ;
2774
+
2775
+ error :
2776
+ free (logfile );
2777
+ return -1 ;
2774
2778
}
2775
2779
2776
2780
static int files_create_reflog (struct ref_store * ref_store ,
2777
2781
const char * refname , int force_create ,
2778
2782
struct strbuf * err )
2779
2783
{
2780
- int ret ;
2781
- struct strbuf sb = STRBUF_INIT ;
2782
2784
int fd ;
2783
2785
2784
2786
/* Check validity (but we don't need the result): */
2785
2787
files_downcast (ref_store , 0 , "create_reflog" );
2786
2788
2787
- ret = log_ref_setup (refname , & sb , & fd , err , force_create );
2789
+ if (log_ref_setup (refname , force_create , & fd , err ))
2790
+ return -1 ;
2791
+
2788
2792
if (fd >= 0 )
2789
2793
close (fd );
2790
- strbuf_release ( & sb );
2791
- return ret ;
2794
+
2795
+ return 0 ;
2792
2796
}
2793
2797
2794
2798
static int log_ref_write_fd (int fd , const unsigned char * old_sha1 ,
@@ -2819,16 +2823,15 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
2819
2823
2820
2824
static int log_ref_write_1 (const char * refname , const unsigned char * old_sha1 ,
2821
2825
const unsigned char * new_sha1 , const char * msg ,
2822
- struct strbuf * logfile , int flags ,
2823
- struct strbuf * err )
2826
+ int flags , struct strbuf * err )
2824
2827
{
2825
2828
int logfd , result ;
2826
2829
2827
2830
if (log_all_ref_updates < 0 )
2828
2831
log_all_ref_updates = !is_bare_repository ();
2829
2832
2830
- result = log_ref_setup (refname , logfile , & logfd , err ,
2831
- flags & REF_FORCE_CREATE_REFLOG );
2833
+ result = log_ref_setup (refname , flags & REF_FORCE_CREATE_REFLOG ,
2834
+ & logfd , err );
2832
2835
2833
2836
if (result )
2834
2837
return result ;
@@ -2859,11 +2862,7 @@ int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
2859
2862
const unsigned char * new_sha1 , const char * msg ,
2860
2863
int flags , struct strbuf * err )
2861
2864
{
2862
- struct strbuf sb = STRBUF_INIT ;
2863
- int ret = log_ref_write_1 (refname , old_sha1 , new_sha1 , msg , & sb , flags ,
2864
- err );
2865
- strbuf_release (& sb );
2866
- return ret ;
2865
+ return log_ref_write_1 (refname , old_sha1 , new_sha1 , msg , flags , err );
2867
2866
}
2868
2867
2869
2868
/*
0 commit comments