* Re: [BUG] git checkout <branch> allowed with uncommitted changes
From: PJ Weisberg @ 2011-10-13 19:44 UTC (permalink / raw)
To: git
In-Reply-To: <loom.20111013T171530-970@post.gmane.org>
On Thu, Oct 13, 2011 at 8:53 AM, arQon <arqon@gmx.com> wrote:
>>git co master
> error: Your local changes to the following files would be overwritten by
> checkout:
> file1.txt
> Please, commit your changes or stash them before you can switch branches.
> Aborting
>
> I'm sure if I thought about it enough (ie re-read Andreas's post a couple
> more times) I'd be able to understand why git gets it right sometimes but
> not other times, but I'm too tired right now. Even when I *am* awake and
Git gets it "right" (by your definition) when file1.txt on one branch
is different from file1.txt on the other branch. That means that
switching branches would require changing the file, so it refuses to
overwrite your changes by doing so. If it CAN switch branches without
losing your changes, it does.
The fundamental problem is that you're thinking of the changes to the
working tree (which aren't commited) as being "on" some branch. Until
they're committed, changes in the working tree are only in the working
tree. That's basically the difference between "committed" and "not
committed".
-PJ
^ permalink raw reply
* Re: [BUG] git checkout <branch> allowed with uncommitted changes
From: Carlos Martín Nieto @ 2011-10-13 20:07 UTC (permalink / raw)
To: arQon; +Cc: git
In-Reply-To: <loom.20111013T193054-868@post.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 3810 bytes --]
On Thu, 2011-10-13 at 18:19 +0000, arQon wrote:
> Carlos Martín Nieto <cmn <at> elego.de> writes:
> > If file1.txt in the foo branch is different from the one in the master
> > branch, git will refuse to switch branches. 'git diff foo master' should
> > show that those two files are different.
>
> Right, but only for a definition of "branch" that is actually "a fully
> committed branch", hence the confusion and the mention of "uncommitted
> changes" in the topic.
I'm not aware of any other definition of a branch, either for git or
subversion.
>
> An expectation that "co branch" should be analogous to "cd ../branch/" is by
> no means unreasonable. YOU may know better, but it's surprisingly non-obvious,
I don't see how. Switching branches is not the same as changing
directories. It doesn't work that way, neither with git nor subversion.
If you choose to have each branch in their own directory, that's fine,
but it has very little to do with the VCS tool.
> especially considering the -f option on checkout and the wording of -m, both
> of which strongly suggest that, in the absence of either of those flags, git
> WILL preserve the worktree by refusing to switch until that potentially-
> harmful situation is resolved by the user.
The general description could probably benefit from a more explicit
mention of what happens if there are local modifications. Currently it
looks like it's only mentioned in the text of -f and -m, which is not
particularly helpful.
>
> > Committing non-working code is fine, as long as you don't push it out.
>
> Right, but for the problem I was describing it's actually "committing
> non-working code is a requirement, in this situation, if you don't want your
> tree to get eaten". Going from "you absolutely must not do this" to "you must
> do this" takes some mental adjustment, but you also have to be *aware* that
> you now have to do something that was previously prohibited, which I wasn't.
You can also have a different directory for the other branch if you
really don't want to commit until it works. This is the same situation
that you find yourself right now with subversion; I don't see how it's
that hard to recognise that.
>
> > The bigger problem seems to be your reluctance to accept that git is
> > different from subversion
>
> Not at all. If I didn't WANT something different, I wouldn't have been trying
> to move to git in the first place. :)
>
> > but don't go around saying that git
> > corrupts branches when that's blatantly not true.
>
> See my first para in this post (or indeed, the original post). It's "not true"
> provided all branches are fully committed when you switch between them.
Right.
> It blatantly IS true if you switch from a dirty branch.
No. The branch has not been corrupted or changed at all. Your local
modifications to files in the working tree were kept. Again, this
happens both for git and svn.
> Redefining "branch" to mean "fully committed branch" makes it "not true" in
> that context, but so does redefining green to be red and saying that grass is
> red in that context: it may be correct from a certain POV, but it's
> incomprehensible to anyone who isn't aware of that semantic change.
This smells like FUD. A branch and a directory are two different things.
If you find it more comfortable to use different directories for
different branches that's fine, but that doesn't make it a branch.
Changing a file doesn't automatically mean that that version of the file
belongs to the currently active branch (or URL in the case for svn). A
branch is only ever changed when you commit. This is something that
holds true across VCSs. Play with subversion's 'switch' command, it
behaves the same way.
cmn
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply
* [PATCH 0/1] transport: Use is_bundle instead of !is_gitfile
From: Phil Hord @ 2011-10-13 20:26 UTC (permalink / raw)
To: Git List, Junio C Hamano; +Cc: Phil Hord
I'm not sure where this patch should go now since I see my
original patchset on both next and pu. Should I re-roll the
original series with this one merged in, or just submit this
one isolated, as I am doing here?
Pardon my newbieness.
Phil Hord (1):
transport: Add is_bundle() to detect bundle urls
bundle.c | 16 ++++++++++++++++
bundle.h | 1 +
transport.c | 10 +---------
3 files changed, 18 insertions(+), 9 deletions(-)
--
1.7.7.334.g311c9.dirty
^ permalink raw reply
* [PATCH 1/1] transport: Add is_bundle() to detect bundle urls
From: Phil Hord @ 2011-10-13 20:26 UTC (permalink / raw)
To: Git List, Junio C Hamano; +Cc: Phil Hord
In-Reply-To: <1318537562-18581-1-git-send-email-hordp@cisco.com>
Transport decides that any local url which is a file
must be a bundle. This is wrong if the local url is a
gitfile. Teach transport to verify the file is
really a bundle instead of just assuming it is so.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Phil Hord <hordp@cisco.com>
---
bundle.c | 16 ++++++++++++++++
bundle.h | 1 +
transport.c | 10 +---------
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/bundle.c b/bundle.c
index f82baae..cc0624d 100644
--- a/bundle.c
+++ b/bundle.c
@@ -23,6 +23,22 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,
list->nr++;
}
+int is_bundle(const char *path)
+{
+ char buffer[100];
+ FILE *ffd = fopen(path, "rb");
+ int ret=1;
+
+ if (!ffd)
+ return 0;
+
+ if (!fgets(buffer, sizeof(buffer), ffd) ||
+ strcmp(buffer, bundle_signature))
+ ret=0;
+ fclose(ffd);
+ return ret;
+}
+
/* returns an fd */
int read_bundle_header(const char *path, struct bundle_header *header)
{
diff --git a/bundle.h b/bundle.h
index c5a22c8..35aa0eb 100644
--- a/bundle.h
+++ b/bundle.h
@@ -14,6 +14,7 @@ struct bundle_header {
struct ref_list references;
};
+int is_bundle(const char *path);
int read_bundle_header(const char *path, struct bundle_header *header);
int create_bundle(struct bundle_header *header, const char *path,
int argc, const char **argv);
diff --git a/transport.c b/transport.c
index 57138d9..c76f5b7 100644
--- a/transport.c
+++ b/transport.c
@@ -881,14 +881,6 @@ static int is_gitfile(const char *url)
return !prefixcmp(buf, "gitdir: ");
}
-static int is_file(const char *url)
-{
- struct stat buf;
- if (stat(url, &buf))
- return 0;
- return S_ISREG(buf.st_mode);
-}
-
static int external_specification_len(const char *url)
{
return strchr(url, ':') - url;
@@ -929,7 +921,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
ret->fetch = fetch_objs_via_rsync;
ret->push = rsync_transport_push;
ret->smart_options = NULL;
- } else if (is_local(url) && is_file(url) && !is_gitfile(url)) {
+ } else if (is_local(url) && is_bundle(url)) {
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
ret->data = data;
ret->get_refs_list = get_refs_from_bundle;
--
1.7.7.334.g311c9.dirty
^ permalink raw reply related
* Re: [PATCH 10/14] is_dup_ref(): extract function from sort_ref_list()
From: Junio C Hamano @ 2011-10-13 20:43 UTC (permalink / raw)
To: mhagger
Cc: git, Jeff King, Drew Northup, Jakub Narebski, Heiko Voigt,
Johan Herland, Julian Phillips
In-Reply-To: <1318492715-5931-11-git-send-email-mhagger@alum.mit.edu>
mhagger@alum.mit.edu writes:
> ...
> @@ -94,15 +113,11 @@ static void sort_ref_array(struct ref_array *array)
>
> qsort(array->refs, array->nr, sizeof(*array->refs), ref_entry_cmp);
>
> - /* Remove any duplicates from the ref_array */
> + /* Remove any duplicates from the ref_list */
Eh... Also needs retitled.
> for (; j < array->nr; j++) {
> struct ref_entry *a = array->refs[i];
> struct ref_entry *b = array->refs[j];
> - if (!strcmp(a->name, b->name)) {
> - if (hashcmp(a->sha1, b->sha1))
> - die("Duplicated ref, and SHA1s don't match: %s",
> - a->name);
> - warning("Duplicated ref: %s", a->name);
> + if (is_dup_ref(a, b)) {
> free(b);
> continue;
> }
^ permalink raw reply
* Re: [Bug] git pull doesn't recognize --work-tree parameter
From: Junio C Hamano @ 2011-10-13 20:48 UTC (permalink / raw)
To: Jeff King; +Cc: Kirill Likhodedov, git
In-Reply-To: <20111013191457.GA18460@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> I didn't think that could happen now, because you would not be in the
> working tree, and therefore require_work_tree would fail.
Ok, then I was worried about a non-existing problem, which is good.
Then we can introduce cd_to_top that is more sensible than cd_to_toplevel
and perhaps add some warning to the latter about deprecation and
migration.
Thanks.
^ permalink raw reply
* [RFC/PATCH 1/2] bundle: allowing to read from an unseekable fd
From: Junio C Hamano @ 2011-10-13 22:32 UTC (permalink / raw)
To: Shawn O. Pearce; +Cc: git
The current code opens a given file with fopen(), reads it until the end
of the header and runs ftell(), and reopens the same file with open() and
seeks to skip the header. This structure makes it hard to retarget the
code to read from input that is not seekable, such as a network socket.
This patch by itself does not reach that goal yet, but I think it is a
right step in that direction.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* It would be nice if we can avoid byte-by-byte reading from the file
descriptor by over-reading into the strbuf and pass the remainder to
the caller of read_bundle_header(), but I suspect that it would require
us to carry the "here is the remainder from the previous read" buffer
around throughout the transport layer. Parsing of the header wouldn't
be performance critical compared to the computation cost of actually
reading the rest of the bundle, hopefully, so...
bundle.c | 99 ++++++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 64 insertions(+), 35 deletions(-)
diff --git a/bundle.c b/bundle.c
index f48fd7d..3aa715c 100644
--- a/bundle.c
+++ b/bundle.c
@@ -23,49 +23,78 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,
list->nr++;
}
-/* returns an fd */
+/* Eventually this should go to strbuf.[ch] */
+static int strbuf_readline_fd(struct strbuf *sb, int fd)
+{
+ strbuf_reset(sb);
+
+ while (1) {
+ char ch;
+ ssize_t len = xread(fd, &ch, 1);
+ if (len < 0)
+ return -1;
+ strbuf_addch(sb, ch);
+ if (ch == '\n')
+ break;
+ }
+ return 0;
+}
+
int read_bundle_header(const char *path, struct bundle_header *header)
{
- char buffer[1024];
- int fd;
- long fpos;
- FILE *ffd = fopen(path, "rb");
+ struct strbuf buf = STRBUF_INIT;
+ int fd = open(path, O_RDONLY);
+ int status = 0;
- if (!ffd)
+ if (fd < 0)
return error("could not open '%s'", path);
- if (!fgets(buffer, sizeof(buffer), ffd) ||
- strcmp(buffer, bundle_signature)) {
- fclose(ffd);
- return error("'%s' does not look like a v2 bundle file", path);
+
+ /* The bundle header begins with the signature */
+ if (strbuf_readline_fd(&buf, fd) ||
+ strcmp(buf.buf, bundle_signature)) {
+ error("'%s' does not look like a v2 bundle file", path);
+ status = -1;
+ goto abort;
}
- while (fgets(buffer, sizeof(buffer), ffd)
- && buffer[0] != '\n') {
- int is_prereq = buffer[0] == '-';
- int offset = is_prereq ? 1 : 0;
- int len = strlen(buffer);
+
+ /* The bundle header ends with an empty line */
+ while (!strbuf_readline_fd(&buf, fd) &&
+ buf.len && buf.buf[0] != '\n') {
unsigned char sha1[20];
- struct ref_list *list = is_prereq ? &header->prerequisites
- : &header->references;
- char delim;
-
- if (len && buffer[len - 1] == '\n')
- buffer[len - 1] = '\0';
- if (get_sha1_hex(buffer + offset, sha1)) {
- warning("unrecognized header: %s", buffer);
- continue;
+ int is_prereq = 0;
+
+ if (*buf.buf == '-') {
+ is_prereq = 1;
+ strbuf_remove(&buf, 0, 1);
+ }
+ strbuf_rtrim(&buf);
+
+ /*
+ * Tip lines have object name, SP, and refname.
+ * Prerequisites have object name that is optionally
+ * followed by SP and subject line.
+ */
+ if (get_sha1_hex(buf.buf, sha1) ||
+ (40 <= buf.len && !isspace(buf.buf[40])) ||
+ (!is_prereq && buf.len <= 40)) {
+ error("unrecognized header: %s%s (%d)",
+ (is_prereq ? "-" : ""), buf.buf, (int)buf.len);
+ status = -1;
+ break;
+ } else {
+ if (is_prereq)
+ add_to_ref_list(sha1, "", &header->prerequisites);
+ else
+ add_to_ref_list(sha1, buf.buf + 41, &header->references);
}
- delim = buffer[40 + offset];
- if (!isspace(delim) && (delim != '\0' || !is_prereq))
- die ("invalid header: %s", buffer);
- add_to_ref_list(sha1, isspace(delim) ?
- buffer + 41 + offset : "", list);
}
- fpos = ftell(ffd);
- fclose(ffd);
- fd = open(path, O_RDONLY);
- if (fd < 0)
- return error("could not open '%s'", path);
- lseek(fd, fpos, SEEK_SET);
+
+ abort:
+ if (status) {
+ close(fd);
+ fd = -1;
+ }
+ strbuf_release(&buf);
return fd;
}
--
1.7.7.289.gd0d4bb
^ permalink raw reply related
* [PATCH 2/2] bundle: add parse_bundle_header() helper function
From: Junio C Hamano @ 2011-10-13 22:35 UTC (permalink / raw)
To: git; +Cc: Shawn O. Pearce, Phil Hord
In-Reply-To: <7vpqi034l0.fsf@alter.siamese.dyndns.org>
Move most of the code from read_bundle_header() to parse_bundle_header()
that takes a file descriptor that is already opened for reading, and make
the former responsible only for opening the file and noticing errors.
As a logical consequence of this, is_bundle() helper function can be
implemented as a non-complaining variant of read_bundle_header() that
does not return an open file descriptor, and can be used to tighten
the check used to decide the use of bundle transport in transport.c
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* It generally is a bad practice to base a non-RFC patch on an RFC one,
but in any case here is how I would do the is_bundle() helper.
bundle.c | 39 +++++++++++++++++++++++++++++++--------
bundle.h | 1 +
transport.c | 2 +-
3 files changed, 33 insertions(+), 9 deletions(-)
diff --git a/bundle.c b/bundle.c
index 3aa715c..105b005 100644
--- a/bundle.c
+++ b/bundle.c
@@ -40,19 +40,18 @@ static int strbuf_readline_fd(struct strbuf *sb, int fd)
return 0;
}
-int read_bundle_header(const char *path, struct bundle_header *header)
+static int parse_bundle_header(int fd, struct bundle_header *header,
+ const char *report_path)
{
struct strbuf buf = STRBUF_INIT;
- int fd = open(path, O_RDONLY);
int status = 0;
- if (fd < 0)
- return error("could not open '%s'", path);
-
/* The bundle header begins with the signature */
if (strbuf_readline_fd(&buf, fd) ||
strcmp(buf.buf, bundle_signature)) {
- error("'%s' does not look like a v2 bundle file", path);
+ if (report_path)
+ error("'%s' does not look like a v2 bundle file",
+ report_path);
status = -1;
goto abort;
}
@@ -77,8 +76,9 @@ int read_bundle_header(const char *path, struct bundle_header *header)
if (get_sha1_hex(buf.buf, sha1) ||
(40 <= buf.len && !isspace(buf.buf[40])) ||
(!is_prereq && buf.len <= 40)) {
- error("unrecognized header: %s%s (%d)",
- (is_prereq ? "-" : ""), buf.buf, (int)buf.len);
+ if (report_path)
+ error("unrecognized header: %s%s (%d)",
+ (is_prereq ? "-" : ""), buf.buf, (int)buf.len);
status = -1;
break;
} else {
@@ -98,6 +98,29 @@ int read_bundle_header(const char *path, struct bundle_header *header)
return fd;
}
+int read_bundle_header(const char *path, struct bundle_header *header)
+{
+ int fd = open(path, O_RDONLY);
+
+ if (fd < 0)
+ return error("could not open '%s'", path);
+ return parse_bundle_header(fd, header, path);
+}
+
+int is_bundle(const char *path, int quiet)
+{
+ struct bundle_header header;
+ int fd = open(path, O_RDONLY);
+
+ if (fd < 0)
+ return 0;
+ memset(&header, 0, sizeof(header));
+ fd = parse_bundle_header(fd, &header, quiet ? NULL : path);
+ if (fd >= 0)
+ close(fd);
+ return (fd >= 0);
+}
+
static int list_refs(struct ref_list *r, int argc, const char **argv)
{
int i;
diff --git a/bundle.h b/bundle.h
index e2aedd6..c6228e2 100644
--- a/bundle.h
+++ b/bundle.h
@@ -14,6 +14,7 @@ struct bundle_header {
struct ref_list references;
};
+int is_bundle(const char *path, int quiet);
int read_bundle_header(const char *path, struct bundle_header *header);
int create_bundle(struct bundle_header *header, const char *path,
int argc, const char **argv);
diff --git a/transport.c b/transport.c
index c9c8056..84d6480 100644
--- a/transport.c
+++ b/transport.c
@@ -913,7 +913,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
ret->fetch = fetch_objs_via_rsync;
ret->push = rsync_transport_push;
ret->smart_options = NULL;
- } else if (is_local(url) && is_file(url)) {
+ } else if (is_local(url) && is_file(url) && is_bundle(url, 1)) {
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
ret->data = data;
ret->get_refs_list = get_refs_from_bundle;
--
1.7.7.289.gd0d4bb
^ permalink raw reply related
* Re: [PATCH] t1402-check-ref-format: skip tests of refs beginning with slash on Windows
From: Junio C Hamano @ 2011-10-13 23:00 UTC (permalink / raw)
To: Johannes Sixt
Cc: mhagger, git, Jeff King, Drew Northup, Jakub Narebski,
Heiko Voigt, Johan Herland, Julian Phillips
In-Reply-To: <4E969BFC.50706@viscovery.net>
Johannes Sixt <j.sixt@viscovery.net> writes:
> This patch is needed on top of mh/check-ref-format-3, or it could be
> inserted in front of this batch (which probably amounts to the same
> thing :-)
How about applying directly on 'master' then?
> +invalid_ref NOT_MINGW '/'
> ...
> @@ -155,21 +155,21 @@ test_expect_success 'check-ref-format --branch from subdir' '
> '
>
> valid_ref_normalized() {
> - test_expect_success "ref name '$1' simplifies to '$2'" "
> + test_expect_success $3 "ref name '$1' simplifies to '$2'" "
> refname=\$(git check-ref-format --normalize '$1') &&
> test \"\$refname\" = '$2'"
> }
> invalid_ref_normalized() {
> - test_expect_success "check-ref-format --normalize rejects '$1'" "
> + test_expect_success $2 "check-ref-format --normalize rejects '$1'" "
> test_must_fail git check-ref-format --normalize '$1'"
> }
> ...
> +valid_ref_normalized '/heads/foo' 'heads/foo' NOT_MINGW
The inconsistencies strikes me a bit.
Perhaps update to something like this?
valid_ref_normalized () {
if test $# = 3
then
prereq=$1
shift
fi
test_expect_success $prereq "ref name '$1' simplifies to '$2'"
...
}
^ permalink raw reply
* Re: [PATCH] t1402-check-ref-format: skip tests of refs beginning with slash on Windows
From: Junio C Hamano @ 2011-10-13 23:07 UTC (permalink / raw)
To: Johannes Sixt
Cc: mhagger, git, Jeff King, Drew Northup, Jakub Narebski,
Heiko Voigt, Johan Herland, Julian Phillips
In-Reply-To: <7vfwiw33bf.fsf@alter.siamese.dyndns.org>
Bash on Windows converts program arguments that look like absolute POSIX
paths to their Windows form, i.e., drive-letter-colon format. For this
reason, those tests in t1402 that check refs that begin with a slash do not
work as expected on Windows: valid_ref tests are doomed to fail, and
invalid_ref tests fail for the wrong reason (that there is a colon rather
than that they begin with a slash).
Skip these tests.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Junio C Hamano <gitster@pobox.com> writes:
>> +invalid_ref NOT_MINGW '/'
>> ...
>> +valid_ref_normalized '/heads/foo' 'heads/foo' NOT_MINGW
>
> The inconsistencies strikes me a bit.
Here is what I tentatively will queue.
The interdiff from yours looks like this:
diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh
index dba5e97..1ae4d87 100755
--- a/t/t1402-check-ref-format.sh
+++ b/t/t1402-check-ref-format.sh
@@ -11,8 +11,9 @@ valid_ref() {
prereq=$1
shift
esac
- test_expect_success $prereq "ref name '$1' is valid${2:+ with options $2}" \
- "git check-ref-format $2 '$1'"
+ test_expect_success $prereq "ref name '$1' is valid${2:+ with options $2}" "
+ git check-ref-format $2 '$1'
+ "
}
invalid_ref() {
prereq=
@@ -21,8 +22,9 @@ invalid_ref() {
prereq=$1
shift
esac
- test_expect_success $prereq "ref name '$1' is invalid${2:+ with options $2}" \
- "test_must_fail git check-ref-format $2 '$1'"
+ test_expect_success $prereq "ref name '$1' is invalid${2:+ with options $2}" "
+ test_must_fail git check-ref-format $2 '$1'
+ "
}
invalid_ref ''
@@ -155,21 +157,35 @@ test_expect_success 'check-ref-format --branch from subdir' '
'
valid_ref_normalized() {
- test_expect_success $3 "ref name '$1' simplifies to '$2'" "
+ prereq=
+ case $1 in
+ [A-Z]*)
+ prereq=$1
+ shift
+ esac
+ test_expect_success $prereq "ref name '$1' simplifies to '$2'" "
refname=\$(git check-ref-format --normalize '$1') &&
- test \"\$refname\" = '$2'"
+ test \"\$refname\" = '$2'
+ "
}
invalid_ref_normalized() {
- test_expect_success $2 "check-ref-format --normalize rejects '$1'" "
- test_must_fail git check-ref-format --normalize '$1'"
+ prereq=
+ case $1 in
+ [A-Z]*)
+ prereq=$1
+ shift
+ esac
+ test_expect_success $prereq "check-ref-format --normalize rejects '$1'" "
+ test_must_fail git check-ref-format --normalize '$1'
+ "
}
valid_ref_normalized 'heads/foo' 'heads/foo'
valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
-valid_ref_normalized '/heads/foo' 'heads/foo' NOT_MINGW
+valid_ref_normalized NOT_MINGW '/heads/foo' 'heads/foo'
valid_ref_normalized '///heads/foo' 'heads/foo'
invalid_ref_normalized 'foo'
-invalid_ref_normalized '/foo' NOT_MINGW
+invalid_ref_normalized NOT_MINGW '/foo'
invalid_ref_normalized 'heads/foo/../bar'
invalid_ref_normalized 'heads/./foo'
invalid_ref_normalized 'heads\foo'
Thanks.
t/t1402-check-ref-format.sh | 88 +++++++++++++++++++++++++-----------------
1 files changed, 52 insertions(+), 36 deletions(-)
diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh
index 710fcca..1ae4d87 100755
--- a/t/t1402-check-ref-format.sh
+++ b/t/t1402-check-ref-format.sh
@@ -5,38 +5,40 @@ test_description='Test git check-ref-format'
. ./test-lib.sh
valid_ref() {
- if test "$#" = 1
- then
- test_expect_success "ref name '$1' is valid" \
- "git check-ref-format '$1'"
- else
- test_expect_success "ref name '$1' is valid with options $2" \
- "git check-ref-format $2 '$1'"
- fi
+ prereq=
+ case $1 in
+ [A-Z]*)
+ prereq=$1
+ shift
+ esac
+ test_expect_success $prereq "ref name '$1' is valid${2:+ with options $2}" "
+ git check-ref-format $2 '$1'
+ "
}
invalid_ref() {
- if test "$#" = 1
- then
- test_expect_success "ref name '$1' is invalid" \
- "test_must_fail git check-ref-format '$1'"
- else
- test_expect_success "ref name '$1' is invalid with options $2" \
- "test_must_fail git check-ref-format $2 '$1'"
- fi
+ prereq=
+ case $1 in
+ [A-Z]*)
+ prereq=$1
+ shift
+ esac
+ test_expect_success $prereq "ref name '$1' is invalid${2:+ with options $2}" "
+ test_must_fail git check-ref-format $2 '$1'
+ "
}
invalid_ref ''
-invalid_ref '/'
-invalid_ref '/' --allow-onelevel
-invalid_ref '/' --normalize
-invalid_ref '/' '--allow-onelevel --normalize'
+invalid_ref NOT_MINGW '/'
+invalid_ref NOT_MINGW '/' --allow-onelevel
+invalid_ref NOT_MINGW '/' --normalize
+invalid_ref NOT_MINGW '/' '--allow-onelevel --normalize'
valid_ref 'foo/bar/baz'
valid_ref 'foo/bar/baz' --normalize
invalid_ref 'refs///heads/foo'
valid_ref 'refs///heads/foo' --normalize
invalid_ref 'heads/foo/'
-invalid_ref '/heads/foo'
-valid_ref '/heads/foo' --normalize
+invalid_ref NOT_MINGW '/heads/foo'
+valid_ref NOT_MINGW '/heads/foo' --normalize
invalid_ref '///heads/foo'
valid_ref '///heads/foo' --normalize
invalid_ref './foo'
@@ -115,14 +117,14 @@ invalid_ref "$ref" --refspec-pattern
invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
ref='/foo'
-invalid_ref "$ref"
-invalid_ref "$ref" --allow-onelevel
-invalid_ref "$ref" --refspec-pattern
-invalid_ref "$ref" '--refspec-pattern --allow-onelevel'
-invalid_ref "$ref" --normalize
-valid_ref "$ref" '--allow-onelevel --normalize'
-invalid_ref "$ref" '--refspec-pattern --normalize'
-valid_ref "$ref" '--refspec-pattern --allow-onelevel --normalize'
+invalid_ref NOT_MINGW "$ref"
+invalid_ref NOT_MINGW "$ref" --allow-onelevel
+invalid_ref NOT_MINGW "$ref" --refspec-pattern
+invalid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel'
+invalid_ref NOT_MINGW "$ref" --normalize
+valid_ref NOT_MINGW "$ref" '--allow-onelevel --normalize'
+invalid_ref NOT_MINGW "$ref" '--refspec-pattern --normalize'
+valid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize'
test_expect_success "check-ref-format --branch @{-1}" '
T=$(git write-tree) &&
@@ -155,21 +157,35 @@ test_expect_success 'check-ref-format --branch from subdir' '
'
valid_ref_normalized() {
- test_expect_success "ref name '$1' simplifies to '$2'" "
+ prereq=
+ case $1 in
+ [A-Z]*)
+ prereq=$1
+ shift
+ esac
+ test_expect_success $prereq "ref name '$1' simplifies to '$2'" "
refname=\$(git check-ref-format --normalize '$1') &&
- test \"\$refname\" = '$2'"
+ test \"\$refname\" = '$2'
+ "
}
invalid_ref_normalized() {
- test_expect_success "check-ref-format --normalize rejects '$1'" "
- test_must_fail git check-ref-format --normalize '$1'"
+ prereq=
+ case $1 in
+ [A-Z]*)
+ prereq=$1
+ shift
+ esac
+ test_expect_success $prereq "check-ref-format --normalize rejects '$1'" "
+ test_must_fail git check-ref-format --normalize '$1'
+ "
}
valid_ref_normalized 'heads/foo' 'heads/foo'
valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo'
-valid_ref_normalized '/heads/foo' 'heads/foo'
+valid_ref_normalized NOT_MINGW '/heads/foo' 'heads/foo'
valid_ref_normalized '///heads/foo' 'heads/foo'
invalid_ref_normalized 'foo'
-invalid_ref_normalized '/foo'
+invalid_ref_normalized NOT_MINGW '/foo'
invalid_ref_normalized 'heads/foo/../bar'
invalid_ref_normalized 'heads/./foo'
invalid_ref_normalized 'heads\foo'
--
1.7.7.289.gd0d4bb
^ permalink raw reply related
* [PATCH] pack-objects: protect against disappearing packs
From: Jeff King @ 2011-10-14 1:23 UTC (permalink / raw)
To: git; +Cc: git-dev, Shawn O. Pearce, Nicolas Pitre
It's possible that while pack-objects is running, a
simultaneously running prune process might delete a pack
that we are interested in. Because we load the pack indices
early on, we know that the pack contains our item, but by
the time we try to open and map it, it is gone.
Since c715f78, we already protect against this in the normal
object access code path, but pack-objects accesses the packs
at a lower level. In the normal access path, we call
find_pack_entry, which will call find_pack_entry_one on each
pack index, which does the actual lookup. If it gets a hit,
we will actually open and verify the validity of the
matching packfile (using c715f78's is_pack_valid). If we
can't open it, we'll issue a warning and pretend that we
didn't find it, causing us to go on to the next pack (or on
to loose objects).
Furthermore, we will cache the descriptor to the opened
packfile. Which means that later, when we actually try to
access the object, we are likely to still have that packfile
opened, and won't care if it has been unlinked from the
filesystem.
Notice the "likely" above. If there is another pack access
in the interim, and we run out of descriptors, we could
close the pack. And then a later attempt to access the
closed pack could fail (we'll try to re-open it, of course,
but it may have been deleted). In practice, this doesn't
happen because we tend to look up items and then access them
immediately.
Pack-objects does not follow this code path. Instead, it
accesses the packs at a much lower level, using
find_pack_entry_one directly. This means we skip the
is_pack_valid check, and may end up with the name of a
packfile, but no open descriptor.
We can add the same is_pack_valid check here. Unfortunately,
the access patterns of pack-objects are not quite as nice
for keeping lookup and object access together. We look up
each object as we find out about it, and the only later when
writing the packfile do we necessarily access it. Which
means that the opened packfile may be closed in the interim.
In practice, however, adding this check still has value, for
three reasons.
1. If you have a reasonable number of packs and/or a
reasonable file descriptor limit, you can keep all of
your packs open simultaneously. If this is the case,
then the race is impossible to trigger.
2. Even if you can't keep all packs open at once, you
may end up keeping the deleted one open (i.e., you may
get lucky).
3. The race window is shortened. You may notice early that
the pack is gone, and not try to access it. Triggering
the problem without this check means deleting the pack
any time after we read the list of index files, but
before we access the looked-up objects. Triggering it
with this check means deleting the pack means deleting
the pack after we do a lookup (and successfully access
the packfile), but before we access the object. Which
is a smaller window.
---
We're seeing this at GitHub because we prune pretty
aggressively. We let pushes go into individual repositories,
but then we kick off a job to move the resulting objects
into the repository's "network" repo, which is basically a
big alternates repository for related repos.
You can reproduce locally with:
push() {
(cd child &&
echo content >>file &&
git add file &&
git commit -q -m "change `wc -l <file`" &&
git push -q origin HEAD
) &&
(cd network.git &&
git fetch -q ../parent refs/*:refs/* &&
git gc --auto
) &&
(cd parent.git &&
git repack -qadl
)
}
fetch() {
rm -rf clone$1
git.compile clone -q file://$PWD/parent.git clone$1 2>>output$1 ||
{
echo >&2 FAIL FAIL FAIL
exit 1
}
}
git init --bare network.git &&
git --git-dir=network.git config transfer.unpacklimit 1 &&
git init --bare parent.git &&
git --git-dir=parent.git config transfer.unpacklimit 1 &&
echo "$PWD/network.git/objects" >parent.git/objects/info/alternates
git clone parent.git child &&
(for i in `seq 1 1000`; do push; done) &
(for i in `seq 1 1000`; do fetch 1; done) &
(for i in `seq 1 1000`; do fetch 2; done) &
wait
One process repeatedly pushes new packs, then migrates the
objects over to the network repo. Simultaneously, two
processes are constantly cloning. After 10-20 seconds, I'll
usually get unlucky and a clone will fail (because the
remote pack-objects complains about the inaccessible
packfile).
Another option would be to open the pack at point of use, and if that
fails, try to find the object elsewhere. This throws off the rest of the
code a bit, though, as we were expecting to get it from a pack, which
went into our decision about what we should delta.
Signed-off-by: Jeff King <peff@peff.net>
---
builtin/pack-objects.c | 4 ++++
cache.h | 1 +
sha1_file.c | 2 +-
3 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 2b18de5..8681ccd 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -804,6 +804,10 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
off_t offset = find_pack_entry_one(sha1, p);
if (offset) {
if (!found_pack) {
+ if (!is_pack_valid(p)) {
+ error("packfile %s cannot be accessed", p->pack_name);
+ continue;
+ }
found_offset = offset;
found_pack = p;
}
diff --git a/cache.h b/cache.h
index e39e160..495b468 100644
--- a/cache.h
+++ b/cache.h
@@ -1055,6 +1055,7 @@ struct extra_have_objects {
extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t);
extern off_t nth_packed_object_offset(const struct packed_git *, uint32_t);
extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
+extern int is_pack_valid(struct packed_git *);
extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
diff --git a/sha1_file.c b/sha1_file.c
index 3401301..a22c5b4 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1987,7 +1987,7 @@ off_t find_pack_entry_one(const unsigned char *sha1,
return 0;
}
-static int is_pack_valid(struct packed_git *p)
+int is_pack_valid(struct packed_git *p)
{
/* An already open pack is known to be valid. */
if (p->pack_fd != -1)
--
1.7.6.4.37.g43b58b
^ permalink raw reply related
* Re: [PATCH] pack-objects: protect against disappearing packs
From: Jeff King @ 2011-10-14 1:31 UTC (permalink / raw)
To: git; +Cc: git-dev, Shawn O. Pearce, Nicolas Pitre
In-Reply-To: <20111014012320.GA4395@sigill.intra.peff.net>
On Thu, Oct 13, 2011 at 09:23:20PM -0400, Jeff King wrote:
> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index 2b18de5..8681ccd 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -804,6 +804,10 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
> off_t offset = find_pack_entry_one(sha1, p);
> if (offset) {
> if (!found_pack) {
> + if (!is_pack_valid(p)) {
> + error("packfile %s cannot be accessed", p->pack_name);
> + continue;
> + }
This message is modeled after the one in find_pack_entry. However,
they're not really errors, since we will try to find the object
elsewhere (and generally succeed). So the messages could just go away.
Though they can also alert you to something fishy going on (like a
packfile with bad permissions). But perhaps we should downgrade them
like this:
-- >8 --
Subject: [PATCH] downgrade "packfile cannot be accessed" errors to warnings
These can happen if another process simultaneously prunes a
pack. But that is not usually an error condition, because a
properly-running prune should have repacked the object into
a new pack. So we will notice that the pack has disappeared
unexpectedly, print a message, try other packs (possibly
after re-scanning the list of packs), and find it in the new
pack.
Signed-off-by: Jeff King <peff@peff.net>
---
builtin/pack-objects.c | 2 +-
sha1_file.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 8681ccd..ba3705d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -805,7 +805,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
if (offset) {
if (!found_pack) {
if (!is_pack_valid(p)) {
- error("packfile %s cannot be accessed", p->pack_name);
+ warning("packfile %s cannot be accessed", p->pack_name);
continue;
}
found_offset = offset;
diff --git a/sha1_file.c b/sha1_file.c
index a22c5b4..27f3b9b 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2038,7 +2038,7 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
* was loaded!
*/
if (!is_pack_valid(p)) {
- error("packfile %s cannot be accessed", p->pack_name);
+ warning("packfile %s cannot be accessed", p->pack_name);
goto next;
}
e->offset = offset;
--
1.7.6.4.37.g43b58b
^ permalink raw reply related
* Re: [BUG] git checkout <branch> allowed with uncommitted changes
From: Jeff King @ 2011-10-14 1:38 UTC (permalink / raw)
To: arQon; +Cc: git
In-Reply-To: <loom.20111013T203610-130@post.gmane.org>
On Thu, Oct 13, 2011 at 06:56:14PM +0000, arQon wrote:
> I'll give a shot, though I don't know how good it'll be. Off the top of my
> head, I don't see any good way to explain the inconsistency with LOCAL CHANGES
> sometimes preventing switches and sometimes not, based on what is to the user
> an arbitrary set of rules that has nothing to do with the *current state* of
> the worktree, but rather the state of those files in prior commits.
The rules are fairly straightforward. You are moving from branch A to
branch B. If path X is not changed going from A to B, git will not touch
it, whether or not you have local changes. If path X is changed going
from A to B, then git will refuse the checkout, and you have the option
of:
1. checkout -f: overwrite your local changes with what's in B
2. checkout -m: merge your changes with what's in B (using A as a
common ancestor)
> But sure, I'll see if I can come up with something. If nothing else,
> having the manpage at least explain what "M" means; that it can be
> potentially disastrous; and what you need to do to avoid it, would be
> a definite plus.
You keep saying things like "disastrous". Git's rules are specifically
designed to be as flexible as possible without allowing the checkout
command to cause data loss.
Do you actually have a case that causes irrecoverable data loss?
Note that I don't count "these changes were based on A, now they are
based on B" as data loss. Your file content is still completely intact,
and if you want to make them based on "A" again, you just need to
"git checkout A" again.
-Peff
^ permalink raw reply
* fatal: Not a git repository
From: T @ 2011-10-14 1:57 UTC (permalink / raw)
To: git@vger.kernel.org
I am on RedHat Linux Server 5.7, installed git and all worked great.
Performed a "git add ." and sat back and watched it chew up GB fo data and create the .git repository, which I was going to study. But then I decided to delete the .git repository before the commit, and redo the work after I added additional files to the filesystem.
The git application no longer works. I have done a complete deletion of all files that I know of and a complete reinstallation and yet every time that I attempt to get git to reread the directory and recreate the repository or ANY repository on the system even while root the error message is:
[root@localhost wizdom]# git add .
fatal: Not a git repository (or any of the parent directories): .git
Any idea on how to fix this problem so that I can get on with using git?
Wizdom is a dir of management information systems related files, 29.4GB in size, containing 264380 files, for systems administration and when git had complete the add command it had create a dir /home/Object/wizdon/.git that was 26.1GB in size and with 212774 files in 256 sub-folders.
============================================
[root@localhost ~]# mkdir /tmp/git_source
[root@localhost ~]# cp /home/Object/Desktop/100511/git/git-1.7.7.tar.gz /tmp/git_source/.
[root@localhost ~]# openssl dgst -sha1 /tmp/git_source/git-1.7.7.tar.gz
SHA1(/tmp/git_source/git-1.7.7.tar.gz)= bbf85bd767ca6b7e9caa1489bb4ba7ec64e0ab35
[root@localhost ~]# cd /tmp/git_source/
[root@localhost git_source]# tar -xzf git-1.7.7.tar.gz
[root@localhost git_source]# ls
git-1.7.7 git-1.7.7.tar.gz
[root@localhost git_source]# ./configure
[root@localhost git-1.7.7]# make
[root@localhost git-1.7.7]# make install
[root@localhost git-1.7.7]# updatedb
[root@localhost git-1.7.7]# which git
/usr/local/bin/git
[root@localhost ~]# ls -al /usr/local/bin/gi*
-rwxr-xr-x 109 root root 5113079 Oct 13 13:14 /usr/local/bin/git
-rwxr-xr-x 2 root root 120939 Oct 13 13:14 /usr/local/bin/git-cvsserver
-rwxr-xr-x 1 root root 324172 Oct 13 13:14 /usr/local/bin/gitk
-rwxr-xr-x 109 root root 5113079 Oct 13 13:14 /usr/local/bin/git-receive-pack
-rwxr-xr-x 2 root root 2144914 Oct 13 13:14 /usr/local/bin/git-shell
-rwxr-xr-x 109 root root 5113079 Oct 13 13:14 /usr/local/bin/git-upload-archive
-rwxr-xr-x 2 root root 2195752 Oct 13 13:14 /usr/local/bin/git-upload-pack
Just to see what it would do, or what it does, I ran git against my systems administration collection called wizdom on a Dell T-410 with one socket in use.
[root@localhost git-1.7.7]# git --version
git version 1.7.7
[root@localhost wizdom]# git init
Initialized empty Git repository in /home/Object/Desktop/wizdom/.git/
[root@localhost wizdom]# git add .
[root@localhost wizdom]#
And in another window while "git add ." ran, I execute the top command to see what the processor had to say:
[root@localhost ~]# top
top - 16:12:43 up 1 day, 21:19, 4 users, load average: 1.35, 0.73, 0.32
Tasks: 232 total, 2 running, 230 sleeping, 0 stopped, 0 zombie
Cpu0 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu1 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu2 : 0.7%us, 0.0%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu3 : 0.0%us, 2.0%sy, 0.0%ni, 46.7%id, 50.7%wa, 0.3%hi, 0.3%si, 0.0%st
Cpu4 : 0.0%us, 1.0%sy, 0.0%ni, 99.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu5 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu6 : 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu7 : 93.7%us, 2.7%sy, 0.0%ni, 3.3%id, 0.3%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 5968036k total, 5932372k used, 35664k free, 191688k buffers
Swap: 8159224k total, 0k used, 8159224k free, 4938104k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16250 root 25 0 17344 1428 792 D 96.2 0.0 1:09.41 git-fast-import
16233 root 18 0 44348 29m 1036 S 1.3 0.5 0:53.89 git
...
Thanks!
^ permalink raw reply
* Re: fatal: Not a git repository
From: BlackSwan @ 2011-10-14 2:14 UTC (permalink / raw)
To: git
In-Reply-To: <1318557443.92591.YahooMailNeo@web114209.mail.gq1.yahoo.com>
Sorry.... I figured it out, and it was right in front of me.
[root@localhost wizdom]# git init
Thanks all!
--
View this message in context: http://git.661346.n2.nabble.com/fatal-Not-a-git-repository-tp6891065p6891093.html
Sent from the git mailing list archive at Nabble.com.
^ permalink raw reply
* Re: [PATCH] pack-objects: protect against disappearing packs
From: Nicolas Pitre @ 2011-10-14 2:42 UTC (permalink / raw)
To: Jeff King; +Cc: git, git-dev, Shawn O. Pearce
In-Reply-To: <20111014012320.GA4395@sigill.intra.peff.net>
On Thu, 13 Oct 2011, Jeff King wrote:
> It's possible that while pack-objects is running, a
> simultaneously running prune process might delete a pack
> that we are interested in. Because we load the pack indices
> early on, we know that the pack contains our item, but by
> the time we try to open and map it, it is gone.
>
> Since c715f78, we already protect against this in the normal
> object access code path, but pack-objects accesses the packs
> at a lower level. In the normal access path, we call
> find_pack_entry, which will call find_pack_entry_one on each
> pack index, which does the actual lookup. If it gets a hit,
> we will actually open and verify the validity of the
> matching packfile (using c715f78's is_pack_valid). If we
> can't open it, we'll issue a warning and pretend that we
> didn't find it, causing us to go on to the next pack (or on
> to loose objects).
>
> Furthermore, we will cache the descriptor to the opened
> packfile. Which means that later, when we actually try to
> access the object, we are likely to still have that packfile
> opened, and won't care if it has been unlinked from the
> filesystem.
>
> Notice the "likely" above. If there is another pack access
> in the interim, and we run out of descriptors, we could
> close the pack. And then a later attempt to access the
> closed pack could fail (we'll try to re-open it, of course,
> but it may have been deleted). In practice, this doesn't
> happen because we tend to look up items and then access them
> immediately.
>
> Pack-objects does not follow this code path. Instead, it
> accesses the packs at a much lower level, using
> find_pack_entry_one directly. This means we skip the
> is_pack_valid check, and may end up with the name of a
> packfile, but no open descriptor.
>
> We can add the same is_pack_valid check here. Unfortunately,
> the access patterns of pack-objects are not quite as nice
> for keeping lookup and object access together. We look up
> each object as we find out about it, and the only later when
> writing the packfile do we necessarily access it. Which
> means that the opened packfile may be closed in the interim.
>
> In practice, however, adding this check still has value, for
> three reasons.
>
> 1. If you have a reasonable number of packs and/or a
> reasonable file descriptor limit, you can keep all of
> your packs open simultaneously. If this is the case,
> then the race is impossible to trigger.
>
> 2. Even if you can't keep all packs open at once, you
> may end up keeping the deleted one open (i.e., you may
> get lucky).
>
> 3. The race window is shortened. You may notice early that
> the pack is gone, and not try to access it. Triggering
> the problem without this check means deleting the pack
> any time after we read the list of index files, but
> before we access the looked-up objects. Triggering it
> with this check means deleting the pack means deleting
> the pack after we do a lookup (and successfully access
> the packfile), but before we access the object. Which
> is a smaller window.
> ---
you should put your SOB above that line I would think.
Acked-by: Nicolas Pitre <nico@fluxnic.net>
> We're seeing this at GitHub because we prune pretty
> aggressively. We let pushes go into individual repositories,
> but then we kick off a job to move the resulting objects
> into the repository's "network" repo, which is basically a
> big alternates repository for related repos.
While this patch certainly has value, it doesn't provide 100%
reliability for that use case. Maybe the github infrastructure should
simply skip any auto-repack on push if some other object maintenance
operation is ongoing, possibly via the pre-auto-gc hook.
Nicolas
^ permalink raw reply
* Re: [PATCH] pack-objects: protect against disappearing packs
From: Nicolas Pitre @ 2011-10-14 2:43 UTC (permalink / raw)
To: Jeff King; +Cc: git, git-dev, Shawn O. Pearce
In-Reply-To: <20111014013130.GA7163@sigill.intra.peff.net>
On Thu, 13 Oct 2011, Jeff King wrote:
> On Thu, Oct 13, 2011 at 09:23:20PM -0400, Jeff King wrote:
>
> > diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> > index 2b18de5..8681ccd 100644
> > --- a/builtin/pack-objects.c
> > +++ b/builtin/pack-objects.c
> > @@ -804,6 +804,10 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
> > off_t offset = find_pack_entry_one(sha1, p);
> > if (offset) {
> > if (!found_pack) {
> > + if (!is_pack_valid(p)) {
> > + error("packfile %s cannot be accessed", p->pack_name);
> > + continue;
> > + }
>
> This message is modeled after the one in find_pack_entry. However,
> they're not really errors, since we will try to find the object
> elsewhere (and generally succeed). So the messages could just go away.
> Though they can also alert you to something fishy going on (like a
> packfile with bad permissions). But perhaps we should downgrade them
> like this:
>
> -- >8 --
> Subject: [PATCH] downgrade "packfile cannot be accessed" errors to warnings
>
> These can happen if another process simultaneously prunes a
> pack. But that is not usually an error condition, because a
> properly-running prune should have repacked the object into
> a new pack. So we will notice that the pack has disappeared
> unexpectedly, print a message, try other packs (possibly
> after re-scanning the list of packs), and find it in the new
> pack.
>
> Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Nicolas Pitre <nico@fluxnic.net>
> ---
> builtin/pack-objects.c | 2 +-
> sha1_file.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index 8681ccd..ba3705d 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -805,7 +805,7 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
> if (offset) {
> if (!found_pack) {
> if (!is_pack_valid(p)) {
> - error("packfile %s cannot be accessed", p->pack_name);
> + warning("packfile %s cannot be accessed", p->pack_name);
> continue;
> }
> found_offset = offset;
> diff --git a/sha1_file.c b/sha1_file.c
> index a22c5b4..27f3b9b 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -2038,7 +2038,7 @@ static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
> * was loaded!
> */
> if (!is_pack_valid(p)) {
> - error("packfile %s cannot be accessed", p->pack_name);
> + warning("packfile %s cannot be accessed", p->pack_name);
> goto next;
> }
> e->offset = offset;
> --
> 1.7.6.4.37.g43b58b
>
^ permalink raw reply
* Re: [PATCH] daemon: return "access denied" if a service is not allowed
From: Junio C Hamano @ 2011-10-14 5:01 UTC (permalink / raw)
To: Jeff King
Cc: Nguyen Thai Ngoc Duy, git, Ilari Liusvaara, Johannes Sixt,
Jonathan Nieder
In-Reply-To: <20111013182816.GA17573@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> So if we want to do anything, I would think it would be a hook. Except
> that we may or may not have a repo, so it would not be a hook in
> $GIT_DIR/hooks, but rather some script to be run passed on the command
> line, like:
>
> git daemon --informative-errors=/path/to/hook
I don't think it is necessarily good to have such a variation across
hosting sites. Your "something like this" patch looked like it was giving
a reasonable level of detail, IMO.
^ permalink raw reply
* interrupting "git rebase" (Re: git rebase +)
From: Jonathan Nieder @ 2011-10-14 5:26 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Adam Piatyszek, git, Martin von Zweigbergk
In-Reply-To: <4E96E5E1.7010103@viscovery.net>
Johannes Sixt wrote:
> Hitting Ctrl-C during git-rebase results undefined behavior. git-rebase is
> a shell script and was never designed to operate in any form of atomicity.
>
> You should have let it run until it stopped.
Wait, really? That's bad, and unlike most git commands.
> Then you could have said 'git
> rebase --abort' (if it didn't complete) or 'git reset --hard ORIG_HEAD'
> (if it completed).
If interrupting the rebase leaves the repository in a state that
rm -fr .git/rebase-apply
git reset --hard <appropriate commit name>
cannot recover from, I'd consider it a serious problem.
By the way, what happened to the "git rebase --abort-softly" synonym
for "rm -fr .git/rebase-apply" discussed a while ago?
^ permalink raw reply
* Re: interrupting "git rebase" (Re: git rebase +)
From: Jonathan Nieder @ 2011-10-14 5:29 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Adam Piatyszek, git, Martin von Zweigbergk
In-Reply-To: <20111014052653.GA5052@elie.hsd1.il.comcast.net>
Jonathan Nieder wrote:
> By the way, what happened to the "git rebase --abort-softly" synonym
> for "rm -fr .git/rebase-apply" discussed a while ago?
(Here's a pointer I should have included[1]. Sorry for the noise.)
[1] http://thread.gmane.org/gmane.comp.version-control.git/174655
^ permalink raw reply
* Re: [PATCH 07/14] is_refname_available(): remove the "quiet" argument
From: Michael Haggerty @ 2011-10-14 5:35 UTC (permalink / raw)
To: Drew Northup
Cc: Junio C Hamano, git, Jeff King, Jakub Narebski, Heiko Voigt,
Johan Herland, Julian Phillips
In-Reply-To: <1318509685.7231.6.camel@drew-northup.unet.maine.edu>
On 10/13/2011 02:41 PM, Drew Northup wrote:
>
> On Thu, 2011-10-13 at 09:58 +0200, mhagger@alum.mit.edu wrote:
>> From: Michael Haggerty <mhagger@alum.mit.edu>
>>
>> quiet was always set to 0, so get rid of it. Add a function docstring
>> for good measure.
>
> I would like to know if perhaps it was an unfinished project somewhere
> to propagate the "quiet" option down to this level before removing the
> function argument. Comments?
The is_refname_available() function, including the quiet option, was
added in c976d415e53 (coincidentally the same commit that added
RENAME-REF). I am unable to find any use of the function with quiet=1
anywhere in history.
>> +/*
>> + * Return true iff a reference named refname could be created without
>
> Did you really mean "iff" (as in "if and only if") or just plain "if"
> here?
I did indeed mean "if and only if". Are you asking because you think
that abbreviation is too obscure, or because you think that "if and only
if" is logically incorrect here and I should have used "if"?
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
^ permalink raw reply
* Re: [PATCH] t1402-check-ref-format: skip tests of refs beginning with slash on Windows
From: Johannes Sixt @ 2011-10-14 6:40 UTC (permalink / raw)
To: Junio C Hamano
Cc: mhagger, git, Jeff King, Drew Northup, Jakub Narebski,
Heiko Voigt, Johan Herland, Julian Phillips
In-Reply-To: <7vbotk32zm.fsf@alter.siamese.dyndns.org>
Am 10/14/2011 1:07, schrieb Junio C Hamano:
> Junio C Hamano <gitster@pobox.com> writes:
>
>>> +invalid_ref NOT_MINGW '/'
>>> ...
>>> +valid_ref_normalized '/heads/foo' 'heads/foo' NOT_MINGW
>>
>> The inconsistencies strikes me a bit.
>
> Here is what I tentatively will queue.
The patch looks good, and the test cases pass as expected.
Thank you very much,
-- Hannes
^ permalink raw reply
* Re: [BUG] git checkout <branch> allowed with uncommitted changes
From: Alexey Shumkin @ 2011-10-14 6:51 UTC (permalink / raw)
To: arQon; +Cc: git
In-Reply-To: <20111013201711.3d55c693@ashu.dyn.rarus.ru>
> > Lucky you. :P The most likely reason for me is, I'm working on
> > something and I get interrupted and have to switch. Since the code
> > may well not even compile at this point, the last thing I want to do
> > is commit it.
> "git stash" helps here
> With Git you can/have_to/must change your SVN-based habits.
> DO NOT BE AFRAID OF FREQUENT COMMITS!
> There are local until you push them.
>
> >git's ability for that commit to be local is half the
> > reason I'm trying to switch to it.
> You always have a chance to modify/reedit you commits
> see "git commit --amend" and "git rebase [-i]"
>
> I'm telling you it as an ex-SVN user.
> >(I'm not particularly keen on
> > having to commit broken code to even a local repo, but that's still
> > a hell of a lot better than having it pushed upstream as well).
>
> Again, do not be afraid to commit your changes. Be afraid of losing
> your changes. Git makes everything (as other discussion participants
> already described) to keep your changes within workflow when you
> switch between branches often.
>
> Read some books which are describe Git's usual (and effective)
> workflow, ProGit - http://progit.org/book/
> Version Contol by Example (there is a chapter about Git) -
> http://git-scm.com/course/svn.html
oops,
wrong url
fixed link
Version Contol by Example (there is a chapter about Git) -
http://www.ericsink.com/vcbe/
^ permalink raw reply
* Re: [PATCH] pack-objects: protect against disappearing packs
From: Johannes Sixt @ 2011-10-14 7:06 UTC (permalink / raw)
To: Jeff King; +Cc: git, git-dev, Shawn O. Pearce, Nicolas Pitre
In-Reply-To: <20111014012320.GA4395@sigill.intra.peff.net>
Am 10/14/2011 3:23, schrieb Jeff King:
> In practice, however, adding this check still has value, for
> three reasons.
>
> 1. If you have a reasonable number of packs and/or a
> reasonable file descriptor limit, you can keep all of
> your packs open simultaneously. If this is the case,
> then the race is impossible to trigger.
On Windows, we cannot remove files that are open. If I understand
correctly, this patch keeps more files open for a longer time. Is there
any chance that packfiles remain now open until an unlink() call?
I am not worried about parallel processes (we already have a problem
there), but that this can now happen within a single process, i.e., that a
single git-repack -a -d -f would now try to unlink a pack file that it
opened itself and did not close timely.
I'll test your patch later this weekend to see whether the test suite
finds something. But perhaps you know the answer already?
-- Hannes
^ permalink raw reply
* defined behaviour for multiple urls for a remote
From: Sitaram Chamarty @ 2011-10-14 7:07 UTC (permalink / raw)
To: Git Mailing List
Hi,
What's the defined behaviour if I do this:
[remote "both"]
url = https://code.google.com/p/gitolite/
url = git@github.com:sitaramc/gitolite.git
I know what I'm seeing (a fetch only goes to the first URL, and does a
HEAD->FETCH_HEAD because I didn't provide a refspec line, while a push
seems to push all to both), but I was curious what the official
position is, because I couldn't find it in the docs.
--
Sitaram
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox