##// END OF EJS Templates
chg: make is possible to call by default an hg binary located next to chg...
Valentin Gatien-Baron -
r46128:4c8d9b53 default
parent child Browse files
Show More
@@ -8,6 +8,9 b' override CFLAGS += -std=gnu99'
8 8 ifdef HGPATH
9 9 override CPPFLAGS += -DHGPATH=\"$(HGPATH)\"
10 10 endif
11 ifdef HGPATHREL
12 override CPPFLAGS += -DHGPATHREL=\"$(HGPATHREL)\"
13 endif
11 14
12 15 DESTDIR =
13 16 PREFIX = /usr/local
@@ -30,3 +30,11 b' The following variables are available fo'
30 30 * CHGSOCKNAME specifies the socket path of the background cmdserver.
31 31 * CHGTIMEOUT specifies how many seconds chg will wait before giving up
32 32 connecting to a cmdserver. If it is 0, chg will wait forever. Default: 60
33
34 Build environment variables:
35
36 * HGPATH: the path to the hg executable to call when CHGHG and HG are not set,
37 instead of "hg"
38 * HGPATHREL=1: when CHGHG and HG are not set, the hg executable will be ./hg
39 relative to the chg executable. Only works on linux, falls back to "hg"
40 otherwise.
@@ -184,13 +184,46 b' static void setcmdserveropts(struct cmds'
184 184 abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
185 185 }
186 186
187 /* If the current program is, say, /a/b/c/chg, returns /a/b/c/hg. */
188 static char *getrelhgcmd(void)
189 {
190 ssize_t n;
191 char *res, *slash;
192 int maxsize = 4096;
193 res = malloc(maxsize);
194 if (res == NULL)
195 goto cleanup;
196 n = readlink("/proc/self/exe", res, maxsize);
197 if (n < 0 || n >= maxsize)
198 goto cleanup;
199 res[n] = '\0';
200 slash = strrchr(res, '/');
201 if (slash == NULL)
202 goto cleanup;
203 /* 4 is strlen("/hg") + nul byte */
204 if (slash + 4 >= res + maxsize)
205 goto cleanup;
206 memcpy(slash, "/hg", 4);
207 return res;
208 cleanup:
209 free(res);
210 return NULL;
211 }
212
187 213 static const char *gethgcmd(void)
188 214 {
189 215 static const char *hgcmd = NULL;
216 #ifdef HGPATHREL
217 int tryrelhgcmd = 1;
218 #else
219 int tryrelhgcmd = 0;
220 #endif
190 221 if (!hgcmd) {
191 222 hgcmd = getenv("CHGHG");
192 223 if (!hgcmd || hgcmd[0] == '\0')
193 224 hgcmd = getenv("HG");
225 if (tryrelhgcmd && (!hgcmd || hgcmd[0] == '\0'))
226 hgcmd = getrelhgcmd();
194 227 if (!hgcmd || hgcmd[0] == '\0')
195 228 #ifdef HGPATH
196 229 hgcmd = (HGPATH);
General Comments 0
You need to be logged in to leave comments. Login now