@@ -282,14 +282,17 @@ template dropPrivilegesAndChdir(path: Option[string], body: untyped): int =
282282 printError (config.color, tr " failed to drop privileges" )
283283 quit (1 )
284284
285- proc editLoop (config: Config , base: string , repoPath: string , gitSubdir: Option [string ],
286- defaultYes: bool , noconfirm: bool ): char =
287- proc editFileLoop (file: string ): char =
288- let default = if defaultYes: 'y' else : 'n'
285+ template createViewTag (repo: string , base: string ): string =
286+ " view-" & repo & " /" & base
287+
288+ proc editLoop (config: Config , repo: string , base: string , repoPath: string ,
289+ gitSubdir: Option [string ], defaultYes: bool , noconfirm: bool ): char =
290+ let default = if defaultYes: 'y' else : 'n'
289291
292+ proc editFileLoop (file: string ): char =
290293 let res = printColonUserChoiceWithHelp (config.color,
291294 tr " View and edit $#?" % [base & " /" & file],
292- choices ('y' , 'n' , ('s' , tr " skip all files " ), ('a' , tr " abort operation" )),
295+ choices ('y' , 'n' , ('s' , tr " skip all" ), ('a' , tr " abort operation" )),
293296 default, noconfirm, 'n' )
294297
295298 if res == 'y' :
@@ -324,7 +327,51 @@ proc editLoop(config: Config, base: string, repoPath: string, gitSubdir: Option[
324327 else :
325328 'n'
326329
327- editFileLoopAll (0 )
330+ let tag = createViewTag (repo, base)
331+
332+ proc viewDiffLoop (hasChanges: bool ): char =
333+ let res = if hasChanges:
334+ printColonUserChoiceWithHelp (config.color,
335+ tr " View changes in $#?" % [base],
336+ choices ('y' , 'n' , ('e' , tr " edit files" ), ('s' , tr " skip all" ), ('a' , tr " abort operation" )),
337+ default, noconfirm, 'n' )
338+ else :
339+ printColonUserChoiceWithHelp (config.color,
340+ tr " No changes in $#. Edit files?" % [base],
341+ choices ('y' , 'n' , ('s' , tr " skip all" ), ('a' , tr " abort operation" )),
342+ 'n' , noconfirm, 'n' )
343+
344+ if hasChanges and res == 'y' :
345+ discard forkWait (() => (block :
346+ dropPrivilegesAndChdir (none (string )):
347+ execResult (gitCmd, " -C" , repoPath, " diff" , tag & " ..@" , gitSubdir.get (" ." ))))
348+ viewDiffLoop (hasChanges)
349+ elif (hasChanges and res == 'e' ) or (not hasChanges and res == 'y' ):
350+ editFileLoopAll (0 )
351+ else :
352+ res
353+
354+ let (hasChanges, noTag) = if repo == " aur" : (block :
355+ let revisions = forkWaitRedirect (() => (block :
356+ dropPrivilegesAndChdir (none (string )):
357+ execResult (gitCmd, " -C" , repoPath, " rev-list" , tag & " ..@" )))
358+
359+ if revisions.code != 0 :
360+ (false , true )
361+ elif revisions.output.len == 0 :
362+ (false , false )
363+ else : (block :
364+ let diff = forkWaitRedirect (() => (block :
365+ dropPrivilegesAndChdir (none (string )):
366+ execResult (gitCmd, " -C" , repoPath, " diff" , tag & " ..@" , gitSubdir.get (" ." ))))
367+ (diff.output.len > 0 , false )))
368+ else :
369+ (false , true )
370+
371+ if noTag:
372+ editFileLoopAll (0 )
373+ else :
374+ viewDiffLoop (hasChanges)
328375
329376proc buildLoop (config: Config , pkgInfos: seq [PackageInfo ], skipDeps: bool ,
330377 noconfirm: bool , noextract: bool ): (Option [BuildResult ], int , bool ) =
@@ -438,7 +485,7 @@ proc buildFromSources(config: Config, commonArgs: seq[Argument],
438485
439486 proc loop (noextract: bool , showEditLoop: bool ): (Option [BuildResult ], int ) =
440487 let res = if showEditLoop and not noconfirm:
441- editLoop (config, base, repoPath, gitSubdir, false , noconfirm)
488+ editLoop (config, pkgInfos[ 0 ].repo, base, repoPath, gitSubdir, false , noconfirm)
442489 else :
443490 'n'
444491
@@ -546,6 +593,28 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
546593 handleTmpRoot (false )
547594 (newSeq [(string , string )](), code)
548595 else :
596+ let cachePath = config.userCacheInitial.cache (CacheKind .repositories)
597+ for pkgInfos in basePackages:
598+ let repo = pkgInfos[0 ].repo
599+ if repo == " aur" :
600+ let base = pkgInfos[0 ].base
601+ let fullName = bareFullName (BareKind .pkg, base)
602+ let bareRepoPath = repoPath (cachePath, fullName)
603+ let tag = createViewTag (repo, base)
604+
605+ template run (args: varargs [string ]) =
606+ discard forkWait (() => (block :
607+ dropPrivilegesAndChdir (none (string )):
608+ if not config.debug:
609+ discard close (1 )
610+ discard open (" /dev/null" )
611+ discard close (2 )
612+ discard open (" /dev/null" )
613+ execResult (args)))
614+
615+ run (gitCmd, " -C" , bareRepoPath, " tag" , " -d" , tag)
616+ run (gitCmd, " -C" , bareRepoPath, " tag" , tag)
617+
549618 handleTmpRoot (true )
550619 let installedAs = lc[(r.name.unsafeGet, r.pkgInfo.name) | (br < - buildResults,
551620 r < - br.replacePkgInfos, r.name.isSome), (string , string )]
@@ -611,10 +680,11 @@ proc confirmViewAndImportKeys(config: Config, basePackages: seq[seq[seq[PackageI
611680 proc checkNext (index: int , skipEdit: bool , skipKeys: bool ): int =
612681 if index < flatBasePackages.len:
613682 let pkgInfos = flatBasePackages[index]
683+ let repo = pkgInfos[0 ].repo
614684 let base = pkgInfos[0 ].base
615685 let repoPath = repoPath (config.tmpRootInitial, base)
616686
617- let aur = pkgInfos[ 0 ]. repo == " aur"
687+ let aur = repo == " aur"
618688
619689 if not skipEdit and aur and not noconfirm and config.aurComments:
620690 echo (tr " downloading comments from AUR..." )
@@ -628,7 +698,7 @@ proc confirmViewAndImportKeys(config: Config, basePackages: seq[seq[seq[PackageI
628698 'n'
629699 else : (block :
630700 let defaultYes = aur and not config.viewNoDefault
631- editLoop (config, base, repoPath, pkgInfos[0 ].gitSubdir, defaultYes, noconfirm))
701+ editLoop (config, repo, base, repoPath, pkgInfos[0 ].gitSubdir, defaultYes, noconfirm))
632702
633703 if editRes == 'a' :
634704 1
0 commit comments