git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Gitk Inotify support
@ 2016-06-09 21:12 Florian Schüller
  2016-06-09 21:24 ` Stefan Beller
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Schüller @ 2016-06-09 21:12 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

Hi
Is this correct to send possible gitk patches here? or should I send
them to Paul Mackerras somehow?

Anyway I just wanted that gitk automatically updates while I'm working
in my terminal

Are you interrested?

as described in "SubmittingPatches" this patch is based on
git://ozlabs.org/~paulus/gitk   22a713c72df8b6799c59287c50cee44c4a6db51e

The code should be robust to just don't autoupdate if
https://sourceforge.net/projects/tcl-inotify/ is not installed

Open points for now:
 - release watches for deleted directories seems to cause problems in
tcl-inotify (so I don't)
   I'm not sure how often that happens in ".git/"
 - I only call "updatecommits" and I don't know if there is a usecase
where I should be calling "reloadcommits"

Regards
Florian Schüller

[-- Attachment #2: 0001-first-support-for-inotify.patch --]
[-- Type: text/x-patch, Size: 2439 bytes --]

From 785ed6bc1b4a3b9019d3503b066afb2a025a2bc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Sch=C3=BCller?= <florian.schueller@gmail.com>
Date: Thu, 9 Jun 2016 22:54:43 +0200
Subject: [PATCH] first support for inotify

---
 gitk | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/gitk b/gitk
index 805a1c7..6e2ead2 100755
--- a/gitk
+++ b/gitk
@@ -8,6 +8,12 @@ exec wish "$0" -- "$@"
 # either version 2, or (at your option) any later version.
 
 package require Tk
+try {
+    package require inotify
+    set we_have_inotify true
+} on error {em} {
+    set we_have_inotify false
+}
 
 proc hasworktree {} {
     return [expr {[exec git rev-parse --is-bare-repository] == "false" &&
@@ -12363,6 +12369,59 @@ if {$i >= [llength $argv] && $revtreeargs ne {}} {
     }
 }
 
+proc inotify_handler { fd } {
+    set events [inotify_watch read]
+    set watch_info [inotify_watch info]
+    set update_view false
+
+    foreach {event} $events {
+        set current_watchid [dict get $event watchid]
+        set flags [dict get $event flags]
+        set event_filename [dict get $event filename]
+
+        foreach {path watchid watch_flags} $watch_info {
+            if {$watchid eq $current_watchid} {
+                set watch_path $path
+            }
+        }
+
+        set full_filename [file join $watch_path $event_filename]
+
+#        remove does not seem to work
+#        if {$flags eq "s"} {
+#            puts "Remove watch $full_filename"
+#            set wd [inotify_watch remove $full_filename]
+#        }
+
+        if {$flags eq "nD"} {
+            set wd [inotify_watch add $full_filename "nwds"]
+        }
+        if {![string match *.lock $event_filename]} {
+            set update_view true
+        }
+    }
+
+    #reloadcommits or updatecommits - depending on file and operation?
+    if {$update_view} {
+        updatecommits
+    }
+}
+
+proc watch_recursive { dir } {
+    inotify_watch add $dir "nwaCmMds"
+
+    foreach i [glob -nocomplain -dir $dir *] {
+        if {[file type $i] eq {directory}} {
+            watch_recursive $i
+        }
+    }
+}
+
+if { $we_have_inotify } {
+    set fd [inotify create "inotify_watch" "::inotify_handler"]
+    watch_recursive $gitdir
+}
+
 set nullid "0000000000000000000000000000000000000000"
 set nullid2 "0000000000000000000000000000000000000001"
 set nullfile "/dev/null"
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-01 20:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-09 21:12 [PATCH] Gitk Inotify support Florian Schüller
2016-06-09 21:24 ` Stefan Beller
2016-06-11 14:06   ` Florian Schüller
2016-12-12  1:58     ` Paul Mackerras
2017-01-01 20:30       ` Florian Schüller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).