Skip to content

Commit 4ea3397

Browse files
committed
GitSigns: Implement "One Fat Diff" option
Depending on the original file it was possible for the diff to fail. This happened specifically when a chunk's anchor line was over 80 characters long. In this case git's unified diff output shortens the chunk's anchor line. Since the script was searching for a subtitle line identical to the chunk's anchor line, this would fail. This introduces an option to bypass looking for the anchor line by having the diff just be one huge chunk instead of invididual chunks per change (±2 lines). Note we're intentionally not saving the one_fat_diff variable because it's supposed to be an intentional choice, not a default when it was used once.
1 parent 4f5ba08 commit 4ea3397

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

macros/arch.GitSigns.moon

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export script_name = "Git Signs"
22
export script_description = "Displays git diffs in Aegisub"
3-
export script_version = "0.2.4"
3+
export script_version = "0.3.0"
44
export script_namespace = "arch.GitSigns"
55
export script_author = "arch1t3cht"
66

@@ -45,13 +45,18 @@ check_has_git = () ->
4545
return has_git
4646

4747

48-
get_git_diff = (ref) ->
48+
get_git_diff = (ref, subs, one_fat_diff) ->
4949
dir = aegisub.decode_path("?script")
5050
if dir == "?script"
5151
aegisub.log("File isn't saved! Aborting.")
5252
aegisub.cancel()
5353

54-
handle = io.popen("#{get_git()} -C \"#{dir}\" diff --raw -p \"#{ref}\" \"#{aegisub.file_name()}\"")
54+
local git_u_arg
55+
if one_fat_diff == true
56+
git_u_arg = "--unified=#{#subs}"
57+
else
58+
git_u_arg = ""
59+
handle = io.popen("#{get_git()} -C \"#{dir}\" diff --raw #{git_u_arg} -p \"#{ref}\" \"#{aegisub.file_name()}\"")
5560
return handle\read("*a")
5661

5762

@@ -138,7 +143,7 @@ show_diff_lines = (subs, diff, show_before) ->
138143
break
139144

140145
if offset == nil
141-
aegisub.log("Diff didn't match the subtitles! Make sure to save your file.\n")
146+
aegisub.log("Diff didn't match the subtitles! Make sure to save your file.\nYou can try again with the \"One Fat Diff\" option enabled.\n")
142147
aegisub.cancel()
143148

144149
break unless offset == nil
@@ -199,8 +204,14 @@ show_diff_diag = (subs, sel) ->
199204
label: "Show before and after",
200205
hint: "Add commented lines marked [Git -] showing how the line looked before the change.",
201206
name: "show_before",
202-
value: config.c.show_before
203-
x: 2, y: 1, width: 2, height: 2,
207+
value: config.c.show_before,
208+
x: 2, y: 1, width: 2, height: 1,
209+
},{
210+
class: "checkbox",
211+
label: "One Fat Diff (potentially very slow!)",
212+
hint: "Have git output one fat diff from beginning to end of the file with no chunks. Use only when diff fails without this.",
213+
name: "one_fat_diff",
214+
x: 2, y: 2, width: 2, height: 1,
204215
}})
205216

206217
return if not btn
@@ -209,7 +220,7 @@ show_diff_diag = (subs, sel) ->
209220
config\write()
210221

211222
ref = "#{result.ref}~#{result.before}"
212-
diff = get_git_diff(ref)
223+
diff = get_git_diff(ref, subs, result.one_fat_diff)
213224

214225
current_diff = diff
215226
show_diff_lines(subs, diff, result.show_before)

0 commit comments

Comments
 (0)