-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_create_patches_util.sh
More file actions
79 lines (67 loc) · 2.58 KB
/
_create_patches_util.sh
File metadata and controls
79 lines (67 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script should not be executed directly."
else
echo "Loading create patch util."
fi
reset_file_if_only_index_changes() {
local patch_fp=$1
# Switch to the repository with the patch files, and check
# if there are substantial changes in the patch file
cd $patch_dp
# shortstat_result=$(git diff --shortstat $patch_fp)
numstat_result=$(git diff --numstat $patch_fp)
performed_git_restore=0
# If numstat_result is empty, the file is up-to-date and there is nothing to restore.
if [ -n "$numstat_result" ]; then
read -r num_added_lines num_deleted_lines fn <<< "$numstat_result"
if [ $num_added_lines == 1 ] && [ $num_deleted_lines == 1 ]; then
local diff_output=$(git diff -- "$patch_fp")
# printf "%s\n" "$diff_output"
# Check for lines that start with "+index"" or "-index"
local added_index_lines=$(echo "$diff_output" | grep '^+index')
local removed_index_lines=$(echo "$diff_output" | grep '^-index')
local num_added_index_lines=$(echo "$added_index_lines" | wc -l)
local num_removed_index_lines=$(echo "$removed_index_lines" | wc -l)
if [ $num_added_index_lines == 1 ] && [ $num_removed_index_lines == 1 ]; then
# echo "Only index lines have changed in $patch_fp"
git restore $patch_fp
performed_git_restore=1
else
echo "ERROR: SINGLE CHANGE (BUT NOT INDEX LINE) in $patch_fp"
exit
fi
# else
# echo "Actual changes in $patch_fp"
fi
fi
# Switch back to the previous directory (i.e. the colmap git repository)
cd $modified_colmap_source_dp
return $performed_git_restore
}
create_patch() {
local source_fp=$1
local patch_fn=$2
local patch_fp="$patch_dp/$patch_fn"
if [ "$overwrite_patch_file" -eq 1 ] || [ ! -f "$patch_fp" ]; then
git diff "$source_fp" > "$patch_fp"
if [ $reset_index_changes == 1 ]; then
reset_file_if_only_index_changes $patch_fp
# Get return value of reset_file_if_only_index_changes
performed_git_restore=$?
else
performed_git_restore=0
fi
if [ $performed_git_restore == 0 ]; then
echo "Running: git diff \"$source_fp\" > \"$patch_fp\""
fi
fi
}
encode_path_as_filename() {
local filepath="$1"
echo "${filepath//\//__}"
}
decode_filename_as_path() {
local filename="$1"
echo "${filename//__/\/}"
}