sub-process: refactor handshake to common function
[gitweb.git] / builtin / worktree.c
index 1722a9bdc2a07ce3d98921299c6b57d03a50e870..c98e2ce5f57c1f41ccaf90041a1a22233ae75551 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "builtin.h"
 #include "dir.h"
 #include "parse-options.h"
@@ -31,7 +32,7 @@ struct add_opts {
 
 static int show_only;
 static int verbose;
-static unsigned long expire;
+static timestamp_t expire;
 
 static int prune_worktree(const char *id, struct strbuf *reason)
 {
@@ -131,7 +132,7 @@ static int prune(int ac, const char **av, const char *prefix)
                OPT_END()
        };
 
-       expire = ULONG_MAX;
+       expire = TIME_MAX;
        ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
        if (ac)
                usage_with_options(worktree_usage, options);
@@ -299,10 +300,8 @@ static int add_worktree(const char *path, const char *refname,
        }
 
        is_junk = 0;
-       free(junk_work_tree);
-       free(junk_git_dir);
-       junk_work_tree = NULL;
-       junk_git_dir = NULL;
+       FREE_AND_NULL(junk_work_tree);
+       FREE_AND_NULL(junk_git_dir);
 
 done:
        if (ret || !opts->keep_locked) {
@@ -414,9 +413,11 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
                                find_unique_abbrev(wt->head_sha1, DEFAULT_ABBREV));
                if (wt->is_detached)
                        strbuf_addstr(&sb, "(detached HEAD)");
-               else if (wt->head_ref)
-                       strbuf_addf(&sb, "[%s]", shorten_unambiguous_ref(wt->head_ref, 0));
-               else
+               else if (wt->head_ref) {
+                       char *ref = shorten_unambiguous_ref(wt->head_ref, 0);
+                       strbuf_addf(&sb, "[%s]", ref);
+                       free(ref);
+               } else
                        strbuf_addstr(&sb, "(error)");
        }
        printf("%s\n", sb.buf);