@@ -776,9 +776,14 @@ void wt_status_collect(struct wt_status *s)
776776
777777void wt_status_collect_free_buffers (struct wt_status * s )
778778{
779- free (s -> state .branch );
780- free (s -> state .onto );
781- free (s -> state .detached_from );
779+ wt_status_state_free_buffers (& s -> state );
780+ }
781+
782+ void wt_status_state_free_buffers (struct wt_status_state * state )
783+ {
784+ FREE_AND_NULL (state -> branch );
785+ FREE_AND_NULL (state -> onto );
786+ FREE_AND_NULL (state -> detached_from );
782787}
783788
784789static void wt_longstatus_print_unmerged (struct wt_status * s )
@@ -1225,7 +1230,7 @@ static int split_commit_in_progress(struct wt_status *s)
12251230 * The function assumes that the line does not contain useless spaces
12261231 * before or after the command.
12271232 */
1228- static void abbrev_sha1_in_line (struct strbuf * line )
1233+ static void abbrev_oid_in_line (struct strbuf * line )
12291234{
12301235 struct strbuf * * split ;
12311236 int i ;
@@ -1275,7 +1280,7 @@ static int read_rebase_todolist(const char *fname, struct string_list *lines)
12751280 strbuf_trim (& line );
12761281 if (!line .len )
12771282 continue ;
1278- abbrev_sha1_in_line (& line );
1283+ abbrev_oid_in_line (& line );
12791284 string_list_append (lines , line .buf );
12801285 }
12811286 fclose (f );
@@ -1568,9 +1573,9 @@ static void wt_status_get_detached_from(struct repository *r,
15681573 }
15691574
15701575 if (dwim_ref (cb .buf .buf , cb .buf .len , & oid , & ref , 1 ) == 1 &&
1571- /* sha1 is a commit? match without further lookup */
1576+ /* oid is a commit? match without further lookup */
15721577 (oideq (& cb .noid , & oid ) ||
1573- /* perhaps sha1 is a tag, try to dereference to a commit */
1578+ /* perhaps oid is a tag, try to dereference to a commit */
15741579 ((commit = lookup_commit_reference_gently (r , & oid , 1 )) != NULL &&
15751580 oideq (& cb .noid , & commit -> object .oid )))) {
15761581 const char * from = ref ;
@@ -1799,29 +1804,36 @@ static void wt_longstatus_print(struct wt_status *s)
17991804 ; /* nothing */
18001805 else if (s -> workdir_dirty ) {
18011806 if (s -> hints )
1802- printf (_ ("no changes added to commit "
1803- "(use \"git add\" and/or \"git commit -a\")\n" ));
1807+ fprintf (s -> fp , _ ("no changes added to commit "
1808+ "(use \"git add\" and/or "
1809+ "\"git commit -a\")\n" ));
18041810 else
1805- printf (_ ("no changes added to commit\n" ));
1811+ fprintf (s -> fp , _ ("no changes added to "
1812+ "commit\n" ));
18061813 } else if (s -> untracked .nr ) {
18071814 if (s -> hints )
1808- printf (_ ("nothing added to commit but untracked files "
1809- "present (use \"git add\" to track)\n" ));
1815+ fprintf (s -> fp , _ ("nothing added to commit but "
1816+ "untracked files present (use "
1817+ "\"git add\" to track)\n" ));
18101818 else
1811- printf (_ ("nothing added to commit but untracked files present\n" ));
1819+ fprintf (s -> fp , _ ("nothing added to commit but "
1820+ "untracked files present\n" ));
18121821 } else if (s -> is_initial ) {
18131822 if (s -> hints )
1814- printf (_ ("nothing to commit (create/copy files "
1815- "and use \"git add\" to track)\n" ));
1823+ fprintf (s -> fp , _ ("nothing to commit (create/"
1824+ "copy files and use \"git "
1825+ "add\" to track)\n" ));
18161826 else
1817- printf ( _ ("nothing to commit\n" ));
1827+ fprintf ( s -> fp , _ ("nothing to commit\n" ));
18181828 } else if (!s -> show_untracked_files ) {
18191829 if (s -> hints )
1820- printf (_ ("nothing to commit (use -u to show untracked files)\n" ));
1830+ fprintf (s -> fp , _ ("nothing to commit (use -u to "
1831+ "show untracked files)\n" ));
18211832 else
1822- printf ( _ ("nothing to commit\n" ));
1833+ fprintf ( s -> fp , _ ("nothing to commit\n" ));
18231834 } else
1824- printf (_ ("nothing to commit, working tree clean\n" ));
1835+ fprintf (s -> fp , _ ("nothing to commit, working tree "
1836+ "clean\n" ));
18251837 }
18261838 if (s -> show_stash )
18271839 wt_longstatus_print_stash_summary (s );
@@ -1844,12 +1856,12 @@ static void wt_shortstatus_unmerged(struct string_list_item *it,
18441856 }
18451857 color_fprintf (s -> fp , color (WT_STATUS_UNMERGED , s ), "%s" , how );
18461858 if (s -> null_termination ) {
1847- fprintf (stdout , " %s%c" , it -> string , 0 );
1859+ fprintf (s -> fp , " %s%c" , it -> string , 0 );
18481860 } else {
18491861 struct strbuf onebuf = STRBUF_INIT ;
18501862 const char * one ;
18511863 one = quote_path (it -> string , s -> prefix , & onebuf , QUOTE_PATH_QUOTE_SP );
1852- printf ( " %s\n" , one );
1864+ fprintf ( s -> fp , " %s\n" , one );
18531865 strbuf_release (& onebuf );
18541866 }
18551867}
@@ -1862,28 +1874,28 @@ static void wt_shortstatus_status(struct string_list_item *it,
18621874 if (d -> index_status )
18631875 color_fprintf (s -> fp , color (WT_STATUS_UPDATED , s ), "%c" , d -> index_status );
18641876 else
1865- putchar (' ' );
1877+ fputc (' ' , s -> fp );
18661878 if (d -> worktree_status )
18671879 color_fprintf (s -> fp , color (WT_STATUS_CHANGED , s ), "%c" , d -> worktree_status );
18681880 else
1869- putchar (' ' );
1870- putchar (' ' );
1881+ fputc (' ' , s -> fp );
1882+ fputc (' ' , s -> fp );
18711883 if (s -> null_termination ) {
1872- fprintf (stdout , "%s%c" , it -> string , 0 );
1884+ fprintf (s -> fp , "%s%c" , it -> string , 0 );
18731885 if (d -> rename_source )
1874- fprintf (stdout , "%s%c" , d -> rename_source , 0 );
1886+ fprintf (s -> fp , "%s%c" , d -> rename_source , 0 );
18751887 } else {
18761888 struct strbuf onebuf = STRBUF_INIT ;
18771889 const char * one ;
18781890
18791891 if (d -> rename_source ) {
18801892 one = quote_path (d -> rename_source , s -> prefix , & onebuf ,
18811893 QUOTE_PATH_QUOTE_SP );
1882- printf ( "%s -> " , one );
1894+ fprintf ( s -> fp , "%s -> " , one );
18831895 strbuf_release (& onebuf );
18841896 }
18851897 one = quote_path (it -> string , s -> prefix , & onebuf , QUOTE_PATH_QUOTE_SP );
1886- printf ( "%s\n" , one );
1898+ fprintf ( s -> fp , "%s\n" , one );
18871899 strbuf_release (& onebuf );
18881900 }
18891901}
@@ -1892,13 +1904,13 @@ static void wt_shortstatus_other(struct string_list_item *it,
18921904 struct wt_status * s , const char * sign )
18931905{
18941906 if (s -> null_termination ) {
1895- fprintf (stdout , "%s %s%c" , sign , it -> string , 0 );
1907+ fprintf (s -> fp , "%s %s%c" , sign , it -> string , 0 );
18961908 } else {
18971909 struct strbuf onebuf = STRBUF_INIT ;
18981910 const char * one ;
18991911 one = quote_path (it -> string , s -> prefix , & onebuf , QUOTE_PATH_QUOTE_SP );
19001912 color_fprintf (s -> fp , color (WT_STATUS_UNTRACKED , s ), "%s" , sign );
1901- printf ( " %s\n" , one );
1913+ fprintf ( s -> fp , " %s\n" , one );
19021914 strbuf_release (& onebuf );
19031915 }
19041916}
0 commit comments