Skip to content

Commit 32d2cfa

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 32d2cfa

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

macros/arch.GitSigns.moon

Lines changed: 16 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,16 @@ 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+
handle = io.popen("#{get_git()} -C \"#{dir}\" diff --raw #{git_u_arg} -p \"#{ref}\" \"#{aegisub.file_name()}\"")
5558
return handle\read("*a")
5659

5760

@@ -138,7 +141,7 @@ show_diff_lines = (subs, diff, show_before) ->
138141
break
139142

140143
if offset == nil
141-
aegisub.log("Diff didn't match the subtitles! Make sure to save your file.\n")
144+
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")
142145
aegisub.cancel()
143146

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

206215
return if not btn
@@ -209,7 +218,7 @@ show_diff_diag = (subs, sel) ->
209218
config\write()
210219

211220
ref = "#{result.ref}~#{result.before}"
212-
diff = get_git_diff(ref)
221+
diff = get_git_diff(ref, subs, result.one_fat_diff)
213222

214223
current_diff = diff
215224
show_diff_lines(subs, diff, result.show_before)

0 commit comments

Comments
 (0)