git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-archive: document CWD effect

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Apr 11, 2007, 20:36 UTC
Message-ID
<461D46C0.6080702@lsrfire.ath.cx>
In-Reply-To
<7v8xczvr13.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano schrieb:
> And I think most people find it natural if you give them the whole
> tree no matter where they start from.

Well, I can't argue against that, as I don't have any numbers. But I can understand this expectation a bit ("archive HEAD!" -- "here is an ear" might be confusing ;).

Show 20 quoted lines
> You could:
> 
> $ git archive HEAD -- t/howto
> 
> to have a narrowed tarball, and even if you make:
> 
> $ cd t/howto $ git archive HEAD
> 
> to produce the whole tree, the user can still do:
> 
> $ cd t/howto $ git archive HEAD -- .
> 
> to get the narrowed tree if the command understands the prefix it
> receives from git_setup_directory().
> 
> So while I understand when you say this is "another input method",
> letting people in a deep directory to abbreviate their cwd with "."
> would equally a good input method, and probably better than the
> current implementation, which leaves people without a single way to
> say "I want the whole tree" without cd'ing up.

Hmm, switching the feature's default mode around instead of cutting it off completely might be a good idea. Something like this? Unlike the current implementation, it always writes the full path from the repo root for each file.

René
diff --git a/builtin-archive.c b/builtin-archive.c
index 7f4e409..efa8679 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -128,18 +128,6 @@ void parse_treeish_arg(const char **argv, struct archiver_args *ar_args,
 	if (tree == NULL)
 		die("not a tree object");
 
-	if (prefix) {
-		unsigned char tree_sha1[20];
-		unsigned int mode;
-		int err;
-
-		err = get_tree_entry(tree->object.sha1, prefix,
-				     tree_sha1, &mode);
-		if (err || !S_ISDIR(mode))
-			die("current working directory is untracked");
-
-		tree = parse_tree_indirect(tree_sha1);
-	}
 	ar_args->tree = tree;
 	ar_args->commit_sha1 = commit_sha1;
 	ar_args->time = archive_time;
@@ -241,6 +229,7 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 	struct archiver ar;
 	int tree_idx;
 	const char *remote = NULL;
+	const char **pathspec;
 
 	remote = extract_remote_arg(&argc, argv);
 	if (remote)
@@ -255,7 +244,11 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
 
 	argv += tree_idx;
 	parse_treeish_arg(argv, &ar.args, prefix);
-	parse_pathspec_arg(argv + 1, &ar.args);
+
+	pathspec = argv + 1;
+	if (*pathspec && prefix)
+		pathspec = get_pathspec(prefix, pathspec);
+	parse_pathspec_arg(pathspec, &ar.args);
 
 	return ar.write_archive(&ar.args);
 }
Previous: Junio C Hamano
Message 10 of 10 in “bug in git-archive?”
  1. Nick WilliamsMar 3, 2007
  2. Johannes SchindelinMar 3, 2007
  3. git-archive: document CWD effectRené Scharfe, Apr 8, 2007
  4. Junio C HamanoApr 8, 2007
  5. René ScharfeApr 9, 2007
  6. Junio C HamanoApr 9, 2007
  7. Andy ParkinsApr 9, 2007
  8. René ScharfeApr 10, 2007
  9. Junio C HamanoApr 10, 2007
  10. René ScharfeApr 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.