git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/5] difftool: Eliminate global variables

From
Sebastian Schuberth <sschuberth@gmail.com>
Date
Jul 23, 2012, 06:13 UTC
Message-ID
<500CEB9F.4030406@gmail.com>
In-Reply-To
<1343014940-16439-2-git-send-email-davvid@gmail.com>
On 23.07.2012 05:42, David Aguilar wrote:
> Organize the script so that it has a single main() function which
> calls out to dir_diff() and file_diff() functions. This eliminates
> "dir-diff"-specific variables that do not need to be calculated when
> performing a regular file-diff.

Funny, I just have prepared a patch along the same lines so that one can call git-difftool -h and --tool-help also outside a repository, see below. Does you patch offer the same? If so, I'll drop mine.

---
  git-difftool.perl | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index ae1e052..e7b71c9 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -25,8 +25,9 @@ use Git;
  my @tools;
  my @working_tree;
  my $rc;
-my $repo = Git->repository();
-my $repo_path = $repo->repo_path();
+my $repo;
+my $repo_path;
+my $workdir;

  sub usage
  {
@@ -62,8 +63,6 @@ sub find_worktree
  	return $worktree;
  }

-my $workdir = find_worktree();
-
  sub filter_tool_scripts
  {
  	if (-d $_) {
@@ -293,6 +292,11 @@ if (defined($help)) {
  if (defined($tool_help)) {
  	print_tool_help();
  }
+
+$repo = Git->repository();
+$repo_path = $repo->repo_path();
+$workdir = find_worktree();
+
  if (defined($difftool_cmd)) {
  	if (length($difftool_cmd) > 0) {
  		$ENV{GIT_DIFF_TOOL} = $difftool_cmd;
-- 
1.7.11.msysgit.2
Previous: David AguilarNext: David Aguilar
Message 3 of 15 in “difftool: Simplify print_tool_help()”
  1. 1/5 difftool: Simplify print_tool_help()David Aguilar, Jul 23, 2012
  2. 2/5 difftool: Eliminate global variablesDavid Aguilar, Jul 23, 2012
  3. Sebastian SchuberthJul 23, 2012
  4. David AguilarJul 23, 2012
  5. Sebastian SchuberthJul 23, 2012
  6. David AguilarJul 23, 2012
  7. Sebastian SchuberthJul 23, 2012
  8. 3/5 difftool: Move option values into a hashDavid Aguilar, Jul 23, 2012
  9. David AguilarJul 23, 2012
  10. 5/5 difftool: Use symlinks when diffing against the worktreeDavid Aguilar, Jul 23, 2012
  11. Tim HeniganJul 24, 2012
  12. David AguilarJul 25, 2012
  13. David AguilarJul 25, 2012
  14. Junio C HamanoJul 25, 2012
  15. David AguilarJul 25, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.