Skip to content

Commit db4176a

Browse files
See discussion under #6902. Add genaiscript for commit messages for future use.
1 parent ef58376 commit db4176a

File tree

2 files changed

+94
-11
lines changed

2 files changed

+94
-11
lines changed

genaisrc/gcm.genai.mts

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { select, input, confirm } from "@inquirer/prompts"
2+
3+
// Check for staged changes and stage all changes if none are staged
4+
let diff = await host.exec("git", ["diff", "--cached"])
5+
if (!diff.stdout) {
6+
const stage = await confirm({
7+
message: "No staged changes. Stage all changes?",
8+
default: true,
9+
})
10+
if (stage) {
11+
await host.exec("git", ["add", "."])
12+
diff = await host.exec("git", [
13+
"diff",
14+
"--cached",
15+
"--",
16+
".",
17+
":!**/genaiscript.d.ts",
18+
])
19+
}
20+
if (!diff.stdout) cancel("no staged changes")
21+
}
22+
23+
console.log(diff.stdout)
24+
25+
let choice
26+
let message
27+
do {
28+
// Generate commit message
29+
message = (
30+
await runPrompt(
31+
(_) => {
32+
_.def("GIT_DIFF", diff, { maxTokens: 20000 })
33+
_.$`GIT_DIFF is a diff of all staged changes, coming from the command:
34+
\`\`\`
35+
git diff --cached
36+
\`\`\`
37+
Please generate a concise, one-line commit message for these changes.
38+
- do NOT add quotes`
39+
},
40+
{ cache: false, temperature: 0.8 }
41+
)
42+
).text
43+
44+
// Prompt user for commit message
45+
choice = await select({
46+
message,
47+
choices: [
48+
{
49+
name: "commit",
50+
value: "commit",
51+
description: "accept message and commit",
52+
},
53+
{
54+
name: "edit",
55+
value: "edit",
56+
description: "edit message and commit",
57+
},
58+
{
59+
name: "regenerate",
60+
value: "regenerate",
61+
description: "regenerate message",
62+
},
63+
],
64+
})
65+
66+
// Handle user choice
67+
if (choice === "edit") {
68+
message = await input({
69+
message: "Edit commit message",
70+
required: true,
71+
})
72+
choice = "commit"
73+
}
74+
// Regenerate message
75+
if (choice === "commit" && message) {
76+
console.log((await host.exec("git", ["commit", "-m", message])).stdout)
77+
if (await confirm({ message: "Push changes?", default: true }))
78+
console.log((await host.exec("git", ["push"])).stdout)
79+
break
80+
}
81+
} while (choice !== "commit")

src/util/memory_manager.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Copyright (c) 2015 Microsoft Corporation
2929
# define malloc_usable_size _msize
3030
#endif
3131

32+
#define SIZE_T_ALIGN 2
33+
3234
// The following two function are automatically generated by the mk_make.py script.
3335
// The script collects ADD_INITIALIZER and ADD_FINALIZER commands in the .h files.
3436
// For example, rational.h contains
@@ -278,7 +280,7 @@ void memory::deallocate(void * p) {
278280
size_t sz = malloc_usable_size(p);
279281
void * real_p = p;
280282
#else
281-
size_t * sz_p = reinterpret_cast<size_t*>(p) - 1;
283+
size_t * sz_p = reinterpret_cast<size_t*>(p) - SIZE_T_ALIGN;
282284
size_t sz = *sz_p;
283285
void * real_p = reinterpret_cast<void*>(sz_p);
284286
#endif
@@ -291,7 +293,7 @@ void memory::deallocate(void * p) {
291293

292294
void * memory::allocate(size_t s) {
293295
#ifndef HAS_MALLOC_USABLE_SIZE
294-
s = s + sizeof(size_t); // we allocate an extra field!
296+
s = s + SIZE_T_ALIGN * sizeof(size_t); // we allocate an extra field!
295297
#endif
296298
g_memory_thread_alloc_size += s;
297299
g_memory_thread_alloc_count += 1;
@@ -308,7 +310,7 @@ void * memory::allocate(size_t s) {
308310
return r;
309311
#else
310312
*(static_cast<size_t*>(r)) = s;
311-
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
313+
return static_cast<size_t*>(r) + SIZE_T_ALIGN; // we return a pointer to the location after the extra field
312314
#endif
313315
}
314316

@@ -323,7 +325,7 @@ void* memory::reallocate(void *p, size_t s) {
323325
size_t *sz_p = reinterpret_cast<size_t*>(p)-1;
324326
size_t sz = *sz_p;
325327
void *real_p = reinterpret_cast<void*>(sz_p);
326-
s = s + sizeof(size_t); // we allocate an extra field!
328+
s = s + SIZE_T_ALIGN * sizeof(size_t); // we allocate an extra field!
327329
#endif
328330
g_memory_thread_alloc_size += s - sz;
329331
g_memory_thread_alloc_count += 1;
@@ -341,7 +343,7 @@ void* memory::reallocate(void *p, size_t s) {
341343
return r;
342344
#else
343345
*(static_cast<size_t*>(r)) = s;
344-
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
346+
return static_cast<size_t*>(r) + SIZE_T_ALIGN; // we return a pointer to the location after the extra field
345347
#endif
346348
}
347349

@@ -358,7 +360,7 @@ void memory::deallocate(void * p) {
358360
size_t sz = malloc_usable_size(p);
359361
void * real_p = p;
360362
#else
361-
size_t * sz_p = reinterpret_cast<size_t*>(p) - 1;
363+
size_t * sz_p = reinterpret_cast<size_t*>(p) - SIZE_T_ALIGN;
362364
size_t sz = *sz_p;
363365
void * real_p = reinterpret_cast<void*>(sz_p);
364366
#endif
@@ -368,7 +370,7 @@ void memory::deallocate(void * p) {
368370

369371
void * memory::allocate(size_t s) {
370372
#ifndef HAS_MALLOC_USABLE_SIZE
371-
s = s + sizeof(size_t); // we allocate an extra field!
373+
s = s + SIZE_T_ALIGN * sizeof(size_t); // we allocate an extra field!
372374
#endif
373375
g_memory_alloc_size += s;
374376
g_memory_alloc_count += 1;
@@ -389,7 +391,7 @@ void * memory::allocate(size_t s) {
389391
return r;
390392
#else
391393
*(static_cast<size_t*>(r)) = s;
392-
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
394+
return static_cast<size_t*>(r) + SIZE_T_ALIGN; // we return a pointer to the location after the extra field
393395
#endif
394396
}
395397

@@ -401,10 +403,10 @@ void* memory::reallocate(void *p, size_t s) {
401403
if (sz >= s)
402404
return p;
403405
#else
404-
size_t * sz_p = reinterpret_cast<size_t*>(p) - 1;
406+
size_t * sz_p = reinterpret_cast<size_t*>(p) - SIZE_T_ALIGN;
405407
size_t sz = *sz_p;
406408
void * real_p = reinterpret_cast<void*>(sz_p);
407-
s = s + sizeof(size_t); // we allocate an extra field!
409+
s = s + SIZE_T_ALIGN * sizeof(size_t); // we allocate an extra field!
408410
#endif
409411
g_memory_alloc_size += s - sz;
410412
g_memory_alloc_count += 1;
@@ -425,7 +427,7 @@ void* memory::reallocate(void *p, size_t s) {
425427
return r;
426428
#else
427429
*(static_cast<size_t*>(r)) = s;
428-
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
430+
return static_cast<size_t*>(r) + SIZE_T_ALIGN; // we return a pointer to the location after the extra field
429431
#endif
430432
}
431433

0 commit comments

Comments
 (0)