33# existence of certain subdirectories under SOURCE_DIR (if provided as an
44# extra argument, otherwise uses CMAKE_CURRENT_SOURCE_DIR).
55
6- function (get_source_info_svn path revision repository)
7- # If svn is a bat file, find_program(Subversion) doesn't find it.
8- # Explicitly search for that here; Subversion_SVN_EXECUTABLE will override
9- # the find_program call in FindSubversion.cmake.
10- find_program (Subversion_SVN_EXECUTABLE NAMES svn svn.bat)
11- find_package (Subversion)
12-
13- # Subversion module does not work with symlinks, see PR8437.
14- get_filename_component (realpath ${path} REALPATH)
15- if (Subversion_FOUND)
16- subversion_wc_info(${realpath} Project)
17- if (Project_WC_REVISION)
18- set (${revision} ${Project_WC_REVISION} PARENT_SCOPE)
19- endif ()
20- if (Project_WC_URL)
21- set (${repository} ${Project_WC_URL} PARENT_SCOPE)
22- endif ()
23- endif ()
24- endfunction ()
25-
26- function (get_source_info_git path revision repository)
6+ function (get_source_info path revision repository)
277 find_package (Git)
288 if (GIT_FOUND)
299 execute_process (COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
@@ -34,61 +14,36 @@ function(get_source_info_git path revision repository)
3414 if (git_result EQUAL 0)
3515 string (STRIP "${git_output} " git_output)
3616 get_filename_component (git_dir ${git_output} ABSOLUTE BASE_DIR ${path} )
37- if (EXISTS "${git_dir} /svn/refs" )
38- execute_process (COMMAND ${GIT_EXECUTABLE} svn info
39- WORKING_DIRECTORY ${path}
40- RESULT_VARIABLE git_result
41- OUTPUT_VARIABLE git_output)
42- if (git_result EQUAL 0)
43- string (REGEX REPLACE "^(.*\n )?Revision: ([^\n ]+).*"
44- "\\ 2" git_svn_rev "${git_output} " )
45- set (${revision} ${git_svn_rev} PARENT_SCOPE)
46- string (REGEX REPLACE "^(.*\n )?URL: ([^\n ]+).*"
47- "\\ 2" git_url "${git_output} " )
48- set (${repository} ${git_url} PARENT_SCOPE)
49- endif ()
17+ execute_process (COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
18+ WORKING_DIRECTORY ${path}
19+ RESULT_VARIABLE git_result
20+ OUTPUT_VARIABLE git_output)
21+ if (git_result EQUAL 0)
22+ string (STRIP "${git_output} " git_output)
23+ set (${revision} ${git_output} PARENT_SCOPE)
24+ endif ()
25+ execute_process (COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref --symbolic -full-name @{upstream}
26+ WORKING_DIRECTORY ${path}
27+ RESULT_VARIABLE git_result
28+ OUTPUT_VARIABLE git_output
29+ ERROR_QUIET)
30+ if (git_result EQUAL 0)
31+ string (REPLACE "/" ";" branch ${git_output} )
32+ list (GET branch 0 remote)
33+ else ()
34+ set (remote "origin" )
35+ endif ()
36+ execute_process (COMMAND ${GIT_EXECUTABLE} remote get -url ${remote}
37+ WORKING_DIRECTORY ${path}
38+ RESULT_VARIABLE git_result
39+ OUTPUT_VARIABLE git_output
40+ ERROR_QUIET)
41+ if (git_result EQUAL 0)
42+ string (STRIP "${git_output} " git_output)
43+ set (${repository} ${git_output} PARENT_SCOPE)
5044 else ()
51- execute_process (COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
52- WORKING_DIRECTORY ${path}
53- RESULT_VARIABLE git_result
54- OUTPUT_VARIABLE git_output)
55- if (git_result EQUAL 0)
56- string (STRIP "${git_output} " git_output)
57- set (${revision} ${git_output} PARENT_SCOPE)
58- endif ()
59- execute_process (COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref --symbolic -full-name @{upstream}
60- WORKING_DIRECTORY ${path}
61- RESULT_VARIABLE git_result
62- OUTPUT_VARIABLE git_output
63- ERROR_QUIET)
64- if (git_result EQUAL 0)
65- string (REPLACE "/" ";" branch ${git_output} )
66- list (GET branch 0 remote)
67- else ()
68- set (remote "origin" )
69- endif ()
70- execute_process (COMMAND ${GIT_EXECUTABLE} remote get -url ${remote}
71- WORKING_DIRECTORY ${path}
72- RESULT_VARIABLE git_result
73- OUTPUT_VARIABLE git_output
74- ERROR_QUIET)
75- if (git_result EQUAL 0)
76- string (STRIP "${git_output} " git_output)
77- set (${repository} ${git_output} PARENT_SCOPE)
78- else ()
79- set (${repository} ${path} PARENT_SCOPE)
80- endif ()
45+ set (${repository} ${path} PARENT_SCOPE)
8146 endif ()
8247 endif ()
8348 endif ()
8449endfunction ()
85-
86- function (get_source_info path revision repository)
87- if (EXISTS "${path} /.svn" )
88- get_source_info_svn("${path} " revision_info repository_info)
89- else ()
90- get_source_info_git("${path} " revision_info repository_info)
91- endif ()
92- set (${repository} "${repository_info} " PARENT_SCOPE)
93- set (${revision} "${revision_info} " PARENT_SCOPE)
94- endfunction ()
0 commit comments