Skip to content

Commit 19265b0

Browse files
committed
Merge branch 'jh/builtin-fsmonitor-part-2plus' into seen
Various small fixes and cleanups on part-2 of the same topic. * jh/builtin-fsmonitor-part-2plus: fsmonitor-settings: simplify initialization of settings data fsmonitor--daemon: add _() to calls to error() fsmonitor--daemon: add _() to calls to die() compat/fsmonitor/fsm-listen-win32: add _() to calls to error() compat/fsmonitor/fsm-listen-darwin: add _() to calls to error() fsmonitor-ipc: add _() to calls to die() t7527: delete unused verify_status() function t7527: fix && chaining in matrix_try() t7527: add parameters to start_daemon to handle args and subshell t/perf/p7519: cleanup coding style t/perf/p7519: use grep rather than egrep in test fsmonitor--daemon: refactor cookie handling for readability t/helper/fsmonitor-client: cleanup call to parse_options() compat/fsmonitor/fsm-listen-darwin: split out GCC-specific declarations update-index: convert advise() messages back to warning() t/test-lib: avoid using git on LHS of pipe
2 parents e0fc338 + 7e19fac commit 19265b0

File tree

11 files changed

+276
-275
lines changed

11 files changed

+276
-275
lines changed

builtin/fsmonitor--daemon.c

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ static int do_as_client__status(void)
109109

110110
enum fsmonitor_cookie_item_result {
111111
FCIR_ERROR = -1, /* could not create cookie file ? */
112-
FCIR_INIT = 0,
112+
FCIR_INIT,
113113
FCIR_SEEN,
114114
FCIR_ABORT,
115115
};
116116

117117
struct fsmonitor_cookie_item {
118118
struct hashmap_entry entry;
119-
const char *name;
119+
char *name;
120120
enum fsmonitor_cookie_item_result result;
121121
};
122122

@@ -166,37 +166,44 @@ static enum fsmonitor_cookie_item_result with_lock__wait_for_cookie(
166166
* that the listener thread has seen it.
167167
*/
168168
fd = open(cookie_pathname.buf, O_WRONLY | O_CREAT | O_EXCL, 0600);
169-
if (fd >= 0) {
170-
close(fd);
171-
unlink(cookie_pathname.buf);
172-
173-
/*
174-
* Technically, this is an infinite wait (well, unless another
175-
* thread sends us an abort). I'd like to change this to
176-
* use `pthread_cond_timedwait()` and return an error/timeout
177-
* and let the caller do the trivial response thing, but we
178-
* don't have that routine in our thread-utils.
179-
*
180-
* After extensive beta testing I'm not really worried about
181-
* this. Also note that the above open() and unlink() calls
182-
* will cause at least two FS events on that path, so the odds
183-
* of getting stuck are pretty slim.
184-
*/
185-
while (cookie->result == FCIR_INIT)
186-
pthread_cond_wait(&state->cookies_cond,
187-
&state->main_lock);
188-
} else {
169+
if (fd < 0) {
189170
error_errno(_("could not create fsmonitor cookie '%s'"),
190171
cookie->name);
191172

192173
cookie->result = FCIR_ERROR;
174+
goto done;
193175
}
194176

177+
/*
178+
* Technically, close() and unlink() can fail, but we don't
179+
* care here. We only created the file to trigger a watch
180+
* event from the FS to know that when we're up to date.
181+
*/
182+
close(fd);
183+
unlink(cookie_pathname.buf);
184+
185+
/*
186+
* Technically, this is an infinite wait (well, unless another
187+
* thread sends us an abort). I'd like to change this to
188+
* use `pthread_cond_timedwait()` and return an error/timeout
189+
* and let the caller do the trivial response thing, but we
190+
* don't have that routine in our thread-utils.
191+
*
192+
* After extensive beta testing I'm not really worried about
193+
* this. Also note that the above open() and unlink() calls
194+
* will cause at least two FS events on that path, so the odds
195+
* of getting stuck are pretty slim.
196+
*/
197+
while (cookie->result == FCIR_INIT)
198+
pthread_cond_wait(&state->cookies_cond,
199+
&state->main_lock);
200+
201+
done:
195202
hashmap_remove(&state->cookies, &cookie->entry, NULL);
196203

197204
result = cookie->result;
198205

199-
free((char*)cookie->name);
206+
free(cookie->name);
200207
free(cookie);
201208
strbuf_release(&cookie_pathname);
202209

@@ -1319,7 +1326,7 @@ static int try_to_run_foreground_daemon(int detach_console)
13191326
* common error case.
13201327
*/
13211328
if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING)
1322-
die("fsmonitor--daemon is already running '%s'",
1329+
die(_("fsmonitor--daemon is already running '%s'"),
13231330
the_repository->worktree);
13241331

13251332
if (fsmonitor__announce_startup) {
@@ -1374,7 +1381,7 @@ static int try_to_start_background_daemon(void)
13741381
* immediately exited).
13751382
*/
13761383
if (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING)
1377-
die("fsmonitor--daemon is already running '%s'",
1384+
die(_("fsmonitor--daemon is already running '%s'"),
13781385
the_repository->worktree);
13791386

13801387
if (fsmonitor__announce_startup) {
@@ -1404,13 +1411,13 @@ static int try_to_start_background_daemon(void)
14041411
default:
14051412
case SBGR_ERROR:
14061413
case SBGR_CB_ERROR:
1407-
return error("daemon failed to start");
1414+
return error(_("daemon failed to start"));
14081415

14091416
case SBGR_TIMEOUT:
1410-
return error("daemon not online yet");
1417+
return error(_("daemon not online yet"));
14111418

14121419
case SBGR_DIED:
1413-
return error("daemon terminated");
1420+
return error(_("daemon terminated"));
14141421
}
14151422
}
14161423

builtin/update-index.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,18 +1238,18 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
12381238
if (fsmonitor > 0) {
12391239
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
12401240
if (fsm_mode == FSMONITOR_MODE_DISABLED) {
1241-
advise(_("core.fsmonitor is unset; "
1242-
"set it if you really want to "
1243-
"enable fsmonitor"));
1241+
warning(_("core.fsmonitor is unset; "
1242+
"set it if you really want to "
1243+
"enable fsmonitor"));
12441244
}
12451245
add_fsmonitor(&the_index);
12461246
report(_("fsmonitor enabled"));
12471247
} else if (!fsmonitor) {
12481248
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
12491249
if (fsm_mode > FSMONITOR_MODE_DISABLED)
1250-
advise(_("core.fsmonitor is set; "
1251-
"remove it if you really want to "
1252-
"disable fsmonitor"));
1250+
warning(_("core.fsmonitor is set; "
1251+
"remove it if you really want to "
1252+
"disable fsmonitor"));
12531253
remove_fsmonitor(&the_index);
12541254
report(_("fsmonitor disabled"));
12551255
}

compat/fsmonitor/fsm-darwin-gcc.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#ifndef FSM_DARWIN_GCC_H
2+
#define FSM_DARWIN_GCC_H
3+
4+
#ifndef __clang__
5+
/*
6+
* It is possible to #include CoreFoundation/CoreFoundation.h when compiling
7+
* with clang, but not with GCC as of time of writing.
8+
*
9+
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93082 for details.
10+
*/
11+
typedef unsigned int FSEventStreamCreateFlags;
12+
#define kFSEventStreamEventFlagNone 0x00000000
13+
#define kFSEventStreamEventFlagMustScanSubDirs 0x00000001
14+
#define kFSEventStreamEventFlagUserDropped 0x00000002
15+
#define kFSEventStreamEventFlagKernelDropped 0x00000004
16+
#define kFSEventStreamEventFlagEventIdsWrapped 0x00000008
17+
#define kFSEventStreamEventFlagHistoryDone 0x00000010
18+
#define kFSEventStreamEventFlagRootChanged 0x00000020
19+
#define kFSEventStreamEventFlagMount 0x00000040
20+
#define kFSEventStreamEventFlagUnmount 0x00000080
21+
#define kFSEventStreamEventFlagItemCreated 0x00000100
22+
#define kFSEventStreamEventFlagItemRemoved 0x00000200
23+
#define kFSEventStreamEventFlagItemInodeMetaMod 0x00000400
24+
#define kFSEventStreamEventFlagItemRenamed 0x00000800
25+
#define kFSEventStreamEventFlagItemModified 0x00001000
26+
#define kFSEventStreamEventFlagItemFinderInfoMod 0x00002000
27+
#define kFSEventStreamEventFlagItemChangeOwner 0x00004000
28+
#define kFSEventStreamEventFlagItemXattrMod 0x00008000
29+
#define kFSEventStreamEventFlagItemIsFile 0x00010000
30+
#define kFSEventStreamEventFlagItemIsDir 0x00020000
31+
#define kFSEventStreamEventFlagItemIsSymlink 0x00040000
32+
#define kFSEventStreamEventFlagOwnEvent 0x00080000
33+
#define kFSEventStreamEventFlagItemIsHardlink 0x00100000
34+
#define kFSEventStreamEventFlagItemIsLastHardlink 0x00200000
35+
#define kFSEventStreamEventFlagItemCloned 0x00400000
36+
37+
typedef struct __FSEventStream *FSEventStreamRef;
38+
typedef const FSEventStreamRef ConstFSEventStreamRef;
39+
40+
typedef unsigned int CFStringEncoding;
41+
#define kCFStringEncodingUTF8 0x08000100
42+
43+
typedef const struct __CFString *CFStringRef;
44+
typedef const struct __CFArray *CFArrayRef;
45+
typedef const struct __CFRunLoop *CFRunLoopRef;
46+
47+
struct FSEventStreamContext {
48+
long long version;
49+
void *cb_data, *retain, *release, *copy_description;
50+
};
51+
52+
typedef struct FSEventStreamContext FSEventStreamContext;
53+
typedef unsigned int FSEventStreamEventFlags;
54+
#define kFSEventStreamCreateFlagNoDefer 0x02
55+
#define kFSEventStreamCreateFlagWatchRoot 0x04
56+
#define kFSEventStreamCreateFlagFileEvents 0x10
57+
58+
typedef unsigned long long FSEventStreamEventId;
59+
#define kFSEventStreamEventIdSinceNow 0xFFFFFFFFFFFFFFFFULL
60+
61+
typedef void (*FSEventStreamCallback)(ConstFSEventStreamRef streamRef,
62+
void *context,
63+
__SIZE_TYPE__ num_of_events,
64+
void *event_paths,
65+
const FSEventStreamEventFlags event_flags[],
66+
const FSEventStreamEventId event_ids[]);
67+
typedef double CFTimeInterval;
68+
FSEventStreamRef FSEventStreamCreate(void *allocator,
69+
FSEventStreamCallback callback,
70+
FSEventStreamContext *context,
71+
CFArrayRef paths_to_watch,
72+
FSEventStreamEventId since_when,
73+
CFTimeInterval latency,
74+
FSEventStreamCreateFlags flags);
75+
CFStringRef CFStringCreateWithCString(void *allocator, const char *string,
76+
CFStringEncoding encoding);
77+
CFArrayRef CFArrayCreate(void *allocator, const void **items, long long count,
78+
void *callbacks);
79+
void CFRunLoopRun(void);
80+
void CFRunLoopStop(CFRunLoopRef run_loop);
81+
CFRunLoopRef CFRunLoopGetCurrent(void);
82+
extern CFStringRef kCFRunLoopDefaultMode;
83+
void FSEventStreamScheduleWithRunLoop(FSEventStreamRef stream,
84+
CFRunLoopRef run_loop,
85+
CFStringRef run_loop_mode);
86+
unsigned char FSEventStreamStart(FSEventStreamRef stream);
87+
void FSEventStreamStop(FSEventStreamRef stream);
88+
void FSEventStreamInvalidate(FSEventStreamRef stream);
89+
void FSEventStreamRelease(FSEventStreamRef stream);
90+
91+
#endif /* !clang */
92+
#endif /* FSM_DARWIN_GCC_H */

compat/fsmonitor/fsm-listen-darwin.c

Lines changed: 3 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,6 @@
11
#ifndef __clang__
2-
/*
3-
* It is possible to #include CoreFoundation/CoreFoundation.h when compiling
4-
* with clang, but not with GCC as of time of writing.
5-
*
6-
* See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93082 for details.
7-
*/
8-
typedef unsigned int FSEventStreamCreateFlags;
9-
#define kFSEventStreamEventFlagNone 0x00000000
10-
#define kFSEventStreamEventFlagMustScanSubDirs 0x00000001
11-
#define kFSEventStreamEventFlagUserDropped 0x00000002
12-
#define kFSEventStreamEventFlagKernelDropped 0x00000004
13-
#define kFSEventStreamEventFlagEventIdsWrapped 0x00000008
14-
#define kFSEventStreamEventFlagHistoryDone 0x00000010
15-
#define kFSEventStreamEventFlagRootChanged 0x00000020
16-
#define kFSEventStreamEventFlagMount 0x00000040
17-
#define kFSEventStreamEventFlagUnmount 0x00000080
18-
#define kFSEventStreamEventFlagItemCreated 0x00000100
19-
#define kFSEventStreamEventFlagItemRemoved 0x00000200
20-
#define kFSEventStreamEventFlagItemInodeMetaMod 0x00000400
21-
#define kFSEventStreamEventFlagItemRenamed 0x00000800
22-
#define kFSEventStreamEventFlagItemModified 0x00001000
23-
#define kFSEventStreamEventFlagItemFinderInfoMod 0x00002000
24-
#define kFSEventStreamEventFlagItemChangeOwner 0x00004000
25-
#define kFSEventStreamEventFlagItemXattrMod 0x00008000
26-
#define kFSEventStreamEventFlagItemIsFile 0x00010000
27-
#define kFSEventStreamEventFlagItemIsDir 0x00020000
28-
#define kFSEventStreamEventFlagItemIsSymlink 0x00040000
29-
#define kFSEventStreamEventFlagOwnEvent 0x00080000
30-
#define kFSEventStreamEventFlagItemIsHardlink 0x00100000
31-
#define kFSEventStreamEventFlagItemIsLastHardlink 0x00200000
32-
#define kFSEventStreamEventFlagItemCloned 0x00400000
33-
34-
typedef struct __FSEventStream *FSEventStreamRef;
35-
typedef const FSEventStreamRef ConstFSEventStreamRef;
36-
37-
typedef unsigned int CFStringEncoding;
38-
#define kCFStringEncodingUTF8 0x08000100
39-
40-
typedef const struct __CFString *CFStringRef;
41-
typedef const struct __CFArray *CFArrayRef;
42-
typedef const struct __CFRunLoop *CFRunLoopRef;
43-
44-
struct FSEventStreamContext {
45-
long long version;
46-
void *cb_data, *retain, *release, *copy_description;
47-
};
48-
49-
typedef struct FSEventStreamContext FSEventStreamContext;
50-
typedef unsigned int FSEventStreamEventFlags;
51-
#define kFSEventStreamCreateFlagNoDefer 0x02
52-
#define kFSEventStreamCreateFlagWatchRoot 0x04
53-
#define kFSEventStreamCreateFlagFileEvents 0x10
54-
55-
typedef unsigned long long FSEventStreamEventId;
56-
#define kFSEventStreamEventIdSinceNow 0xFFFFFFFFFFFFFFFFULL
57-
58-
typedef void (*FSEventStreamCallback)(ConstFSEventStreamRef streamRef,
59-
void *context,
60-
__SIZE_TYPE__ num_of_events,
61-
void *event_paths,
62-
const FSEventStreamEventFlags event_flags[],
63-
const FSEventStreamEventId event_ids[]);
64-
typedef double CFTimeInterval;
65-
FSEventStreamRef FSEventStreamCreate(void *allocator,
66-
FSEventStreamCallback callback,
67-
FSEventStreamContext *context,
68-
CFArrayRef paths_to_watch,
69-
FSEventStreamEventId since_when,
70-
CFTimeInterval latency,
71-
FSEventStreamCreateFlags flags);
72-
CFStringRef CFStringCreateWithCString(void *allocator, const char *string,
73-
CFStringEncoding encoding);
74-
CFArrayRef CFArrayCreate(void *allocator, const void **items, long long count,
75-
void *callbacks);
76-
void CFRunLoopRun(void);
77-
void CFRunLoopStop(CFRunLoopRef run_loop);
78-
CFRunLoopRef CFRunLoopGetCurrent(void);
79-
extern CFStringRef kCFRunLoopDefaultMode;
80-
void FSEventStreamScheduleWithRunLoop(FSEventStreamRef stream,
81-
CFRunLoopRef run_loop,
82-
CFStringRef run_loop_mode);
83-
unsigned char FSEventStreamStart(FSEventStreamRef stream);
84-
void FSEventStreamStop(FSEventStreamRef stream);
85-
void FSEventStreamInvalidate(FSEventStreamRef stream);
86-
void FSEventStreamRelease(FSEventStreamRef stream);
2+
#include "fsm-darwin-gcc.h"
873
#else
88-
/*
89-
* Let Apple's headers declare `isalnum()` first, before
90-
* Git's headers override it via a constant
91-
*/
92-
#include <string.h>
934
#include <CoreFoundation/CoreFoundation.h>
945
#include <CoreServices/CoreServices.h>
956
#endif
@@ -424,7 +335,7 @@ int fsm_listen__ctor(struct fsmonitor_daemon_state *state)
424335
return 0;
425336

426337
failed:
427-
error("Unable to create FSEventStream.");
338+
error(_("Unable to create FSEventStream."));
428339

429340
FREE_AND_NULL(state->backend_data);
430341
return -1;
@@ -472,7 +383,7 @@ void fsm_listen__loop(struct fsmonitor_daemon_state *state)
472383
data->stream_scheduled = 1;
473384

474385
if (!FSEventStreamStart(data->stream)) {
475-
error("Failed to start the FSEventStream");
386+
error(_("Failed to start the FSEventStream"));
476387
goto force_error_stop_without_loop;
477388
}
478389
data->stream_started = 1;

compat/fsmonitor/fsm-listen-win32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int normalize_path_in_utf8(FILE_NOTIFY_INFORMATION *info,
8282
if (len > 0)
8383
goto normalize;
8484
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
85-
error("[GLE %ld] could not convert path to UTF-8: '%.*ls'",
85+
error(_("[GLE %ld] could not convert path to UTF-8: '%.*ls'"),
8686
GetLastError(),
8787
(int)(info->FileNameLength / sizeof(WCHAR)),
8888
info->FileName);
@@ -185,7 +185,7 @@ static int start_rdcw_watch(struct fsmonitor_daemon_backend_data *data,
185185
if (watch->is_active)
186186
return 0;
187187

188-
error("ReadDirectoryChangedW failed on '%s' [GLE %ld]",
188+
error(_("ReadDirectoryChangedW failed on '%s' [GLE %ld]"),
189189
watch->path.buf, GetLastError());
190190
return -1;
191191
}
@@ -228,7 +228,7 @@ static int recv_rdcw_watch(struct one_watch *watch)
228228
* sure it is worth it.
229229
*/
230230

231-
error("GetOverlappedResult failed on '%s' [GLE %ld]",
231+
error(_("GetOverlappedResult failed on '%s' [GLE %ld]"),
232232
watch->path.buf, gle);
233233
return -1;
234234
}

fsmonitor-ipc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int fsmonitor_ipc__send_command(const char *command,
152152
state = ipc_client_try_connect(fsmonitor_ipc__get_path(), &options,
153153
&connection);
154154
if (state != IPC_STATE__LISTENING) {
155-
die("fsmonitor--daemon is not running");
155+
die(_("fsmonitor--daemon is not running"));
156156
return -1;
157157
}
158158

@@ -161,7 +161,7 @@ int fsmonitor_ipc__send_command(const char *command,
161161
ipc_client_close_connection(connection);
162162

163163
if (ret == -1) {
164-
die("could not send '%s' command to fsmonitor--daemon", c);
164+
die(_("could not send '%s' command to fsmonitor--daemon"), c);
165165
return -1;
166166
}
167167

0 commit comments

Comments
 (0)