@@ -1702,10 +1702,11 @@ static char cb_option = 'b';
1702
1702
1703
1703
static int checkout_main (int argc , const char * * argv , const char * prefix ,
1704
1704
struct checkout_opts * opts , struct option * options ,
1705
- const char * const usagestr [],
1706
- struct branch_info * new_branch_info )
1705
+ const char * const usagestr [])
1707
1706
{
1708
1707
int parseopt_flags = 0 ;
1708
+ struct branch_info new_branch_info = { 0 };
1709
+ int ret ;
1709
1710
1710
1711
opts -> overwrite_ignore = 1 ;
1711
1712
opts -> prefix = prefix ;
@@ -1821,7 +1822,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1821
1822
opts -> track == BRANCH_TRACK_UNSPECIFIED &&
1822
1823
!opts -> new_branch ;
1823
1824
int n = parse_branchname_arg (argc , argv , dwim_ok ,
1824
- new_branch_info , opts , & rev );
1825
+ & new_branch_info , opts , & rev );
1825
1826
argv += n ;
1826
1827
argc -= n ;
1827
1828
} else if (!opts -> accept_ref && opts -> from_treeish ) {
@@ -1830,7 +1831,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1830
1831
if (repo_get_oid_mb (the_repository , opts -> from_treeish , & rev ))
1831
1832
die (_ ("could not resolve %s" ), opts -> from_treeish );
1832
1833
1833
- setup_new_branch_info_and_source_tree (new_branch_info ,
1834
+ setup_new_branch_info_and_source_tree (& new_branch_info ,
1834
1835
opts , & rev ,
1835
1836
opts -> from_treeish );
1836
1837
@@ -1850,7 +1851,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1850
1851
* Try to give more helpful suggestion.
1851
1852
* new_branch && argc > 1 will be caught later.
1852
1853
*/
1853
- if (opts -> new_branch && argc == 1 && !new_branch_info -> commit )
1854
+ if (opts -> new_branch && argc == 1 && !new_branch_info . commit )
1854
1855
die (_ ("'%s' is not a commit and a branch '%s' cannot be created from it" ),
1855
1856
argv [0 ], opts -> new_branch );
1856
1857
@@ -1900,9 +1901,16 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1900
1901
}
1901
1902
1902
1903
if (opts -> patch_mode || opts -> pathspec .nr )
1903
- return checkout_paths (opts , new_branch_info );
1904
+ ret = checkout_paths (opts , & new_branch_info );
1904
1905
else
1905
- return checkout_branch (opts , new_branch_info );
1906
+ ret = checkout_branch (opts , & new_branch_info );
1907
+
1908
+ branch_info_release (& new_branch_info );
1909
+ clear_pathspec (& opts -> pathspec );
1910
+ free (opts -> pathspec_from_file );
1911
+ free (options );
1912
+
1913
+ return ret ;
1906
1914
}
1907
1915
1908
1916
int cmd_checkout (int argc , const char * * argv , const char * prefix )
@@ -1920,8 +1928,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1920
1928
OPT_BOOL (0 , "overlay" , & opts .overlay_mode , N_ ("use overlay mode (default)" )),
1921
1929
OPT_END ()
1922
1930
};
1923
- int ret ;
1924
- struct branch_info new_branch_info = { 0 };
1925
1931
1926
1932
memset (& opts , 0 , sizeof (opts ));
1927
1933
opts .dwim_new_local_branch = 1 ;
@@ -1951,13 +1957,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1951
1957
options = add_common_switch_branch_options (& opts , options );
1952
1958
options = add_checkout_path_options (& opts , options );
1953
1959
1954
- ret = checkout_main (argc , argv , prefix , & opts ,
1955
- options , checkout_usage , & new_branch_info );
1956
- branch_info_release (& new_branch_info );
1957
- clear_pathspec (& opts .pathspec );
1958
- free (opts .pathspec_from_file );
1959
- FREE_AND_NULL (options );
1960
- return ret ;
1960
+ return checkout_main (argc , argv , prefix , & opts , options ,
1961
+ checkout_usage );
1961
1962
}
1962
1963
1963
1964
int cmd_switch (int argc , const char * * argv , const char * prefix )
@@ -1975,8 +1976,6 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
1975
1976
N_ ("throw away local modifications" )),
1976
1977
OPT_END ()
1977
1978
};
1978
- int ret ;
1979
- struct branch_info new_branch_info = { 0 };
1980
1979
1981
1980
memset (& opts , 0 , sizeof (opts ));
1982
1981
opts .dwim_new_local_branch = 1 ;
@@ -1995,11 +1994,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
1995
1994
1996
1995
cb_option = 'c' ;
1997
1996
1998
- ret = checkout_main (argc , argv , prefix , & opts ,
1999
- options , switch_branch_usage , & new_branch_info );
2000
- branch_info_release (& new_branch_info );
2001
- FREE_AND_NULL (options );
2002
- return ret ;
1997
+ return checkout_main (argc , argv , prefix , & opts , options ,
1998
+ switch_branch_usage );
2003
1999
}
2004
2000
2005
2001
int cmd_restore (int argc , const char * * argv , const char * prefix )
@@ -2018,8 +2014,6 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
2018
2014
OPT_BOOL (0 , "overlay" , & opts .overlay_mode , N_ ("use overlay mode" )),
2019
2015
OPT_END ()
2020
2016
};
2021
- int ret ;
2022
- struct branch_info new_branch_info = { 0 };
2023
2017
2024
2018
memset (& opts , 0 , sizeof (opts ));
2025
2019
opts .accept_ref = 0 ;
@@ -2034,9 +2028,6 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
2034
2028
options = add_common_options (& opts , options );
2035
2029
options = add_checkout_path_options (& opts , options );
2036
2030
2037
- ret = checkout_main (argc , argv , prefix , & opts ,
2038
- options , restore_usage , & new_branch_info );
2039
- branch_info_release (& new_branch_info );
2040
- FREE_AND_NULL (options );
2041
- return ret ;
2031
+ return checkout_main (argc , argv , prefix , & opts , options ,
2032
+ restore_usage );
2042
2033
}
0 commit comments