From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, jnareb@gmail.com
Cc: dirson@bertin.fr, kevin@sb.org, gitster@pobox.com, peff@peff.net,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] get_sha1: support relative path "<obj>:<sth>" syntax
Date: Wed, 10 Nov 2010 23:37:01 +0700 [thread overview]
Message-ID: <1289407021-30287-1-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <m3eiatfbg2.fsf@localhost.localdomain>
Currently :path and ref:path can be used to refer to a specific object
in index or ref respectively. "path" component is absolute path. This
patch allows "path" to be written as "./path" or "../path", which is
relative to user's original cwd.
This does not work in commands that startup_info is NULL
(i.e. non-builtin ones).
---
On Wed, Nov 10, 2010 at 07:26:20AM -0800, Jakub Narebski wrote:
> The <obj>:<sth> is (with single exception of ':/<regexp>') about
> selecting subitem (path): <tree-ish>:<path>, [:<stage>]:<path>
I feel the urge of keeping ':./path' and ':../path' out of this
competition.
The idea is old although I don't remember if anybody has made any
attempt to realize it: use './' and '../' to specify the given path
is relative, not absolute.
I don't remember either if the idea was rejected or nobody bothered
to implement it. Anyway, here it is (for demostration only because it
needs two minor patches to work). Comments?
--
Duy
sha1_name.c | 30 +++++++++++++++++++++++++++---
1 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 484081d..791608d 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1060,25 +1060,35 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
if (!ret)
return ret;
/* sha1:path --> object name of path in ent sha1
- * :path -> object name of path in index
+ * :path -> object name of absolute path in index
+ * :./path -> object name of path relative to cwd in index
* :[0-3]:path -> object name of path in index at stage
* :/foo -> recent commit matching foo
*/
if (name[0] == ':') {
int stage = 0;
struct cache_entry *ce;
+ char *new_path = NULL;
int pos;
if (namelen > 2 && name[1] == '/')
return get_sha1_oneline(name + 2, sha1);
if (namelen < 3 ||
name[2] != ':' ||
- name[1] < '0' || '3' < name[1])
+ name[1] < '0' || '3' < name[1]) {
cp = name + 1;
+ if (startup_info && cp[0] == '.' &&
+ (cp[1] == '/' || (cp[1] == '.' && cp[2] == '/'))) {
+ new_path = prefix_path(startup_info->prefix,
+ strlen(startup_info->prefix),
+ cp);
+ cp = new_path;
+ }
+ }
else {
stage = name[1] - '0';
cp = name + 3;
}
- namelen = namelen - (cp - name);
+ namelen = strlen(cp);
strncpy(oc->path, cp,
sizeof(oc->path));
@@ -1096,12 +1106,14 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
break;
if (ce_stage(ce) == stage) {
hashcpy(sha1, ce->sha1);
+ free(new_path);
return 0;
}
pos++;
}
if (!gently)
diagnose_invalid_index_path(stage, prefix, cp);
+ free(new_path);
return -1;
}
for (cp = name, bracket_depth = 0; *cp; cp++) {
@@ -1122,6 +1134,17 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
}
if (!get_sha1_1(name, cp-name, tree_sha1)) {
const char *filename = cp+1;
+ char *new_filename = NULL;
+
+ if (startup_info &&
+ filename[0] == '.' &&
+ (filename[1] == '/' ||
+ (filename[1] == '.' && filename[2] == '/'))) {
+ new_filename = prefix_path(startup_info->prefix,
+ strlen(startup_info->prefix),
+ filename);
+ filename = new_filename;
+ }
ret = get_tree_entry(tree_sha1, filename, sha1, &oc->mode);
if (!gently) {
diagnose_invalid_sha1_path(prefix, filename,
@@ -1133,6 +1156,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
sizeof(oc->path));
oc->path[sizeof(oc->path)-1] = '\0';
+ free(new_filename);
return ret;
} else {
if (!gently)
--
1.7.3.2.210.g045198
next prev parent reply other threads:[~2010-11-10 16:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-09 7:30 [RFC] Using gitrevisions :/search style with other operators Yann Dirson
2010-11-09 8:06 ` Kevin Ballard
2010-11-09 9:24 ` Yann Dirson
2010-11-10 0:18 ` Junio C Hamano
2010-11-10 0:33 ` Kevin Ballard
2010-11-10 7:32 ` Yann Dirson
2010-11-10 7:46 ` Kevin Ballard
2010-11-10 7:46 ` Yann Dirson
2010-11-10 15:26 ` Jakub Narebski
2010-11-10 16:37 ` Nguyễn Thái Ngọc Duy [this message]
2010-11-10 17:17 ` [PATCH] get_sha1: support relative path "<obj>:<sth>" syntax Matthieu Moy
2010-11-10 17:47 ` Jonathan Nieder
2010-11-11 13:18 ` Nguyen Thai Ngoc Duy
2010-11-10 19:34 ` Junio C Hamano
2010-11-11 1:30 ` Nguyen Thai Ngoc Duy
2010-12-09 21:10 ` Junio C Hamano
2010-12-09 21:37 ` Junio C Hamano
2010-12-10 1:35 ` Nguyen Thai Ngoc Duy
2010-11-10 17:23 ` [RFC] Using gitrevisions :/search style with other operators Junio C Hamano
2010-11-10 18:19 ` Jakub Narebski
2010-11-09 16:10 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1289407021-30287-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=dirson@bertin.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
--cc=kevin@sb.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.